home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / applications / xlispstat / src / src1.lzh / Amiga / amireq2.c < prev    next >
C/C++ Source or Header  |  1990-10-11  |  16KB  |  406 lines

  1. /* AmiReq2.c - Low Level Requester Objects for Amiga                   */
  2. /* Copyright (c) 1990 by J.K. Lindsey                                  */
  3. /* Additions to XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney     */
  4. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  5. /* You may give out copies of this software; for conditions see the    */
  6. /* file COPYING included with this distribution.                       */
  7.  
  8. #include <proto/exec.h>
  9. #include <proto/intuition.h>
  10. #include <proto/graphics.h>
  11. #include <graphics/gfxmacros.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "autil2.h"
  15. #include "xlisp.h"
  16. #include "osdef.h"
  17. #include "xlproto.h"
  18. #include "xlsproto.h"
  19. #include "iviewproto.h"
  20. #include "Stproto.h"
  21. #include "osproto.h"
  22. #include "xlvar.h"
  23. #include "xlsvar.h"
  24. #include "amivar.h"
  25.  
  26. static int jump_to_top;
  27.  
  28. /* layout definitions */
  29. #define FONT_HEIGHT 16
  30. #define FONT_WIDTH_GUESS 9
  31. #define FONT_POINTS 12
  32.  
  33. #define BUTTON_HEIGHT 20
  34. #define BUTTON_WIDTH 90
  35. #define BUTTON_PAD 15
  36.  
  37. #define TOGGLE_PAD 20
  38. #define TOGGLE_HEIGHT FONT_HEIGHT - 2
  39.  
  40. #define EDIT_TEXT_PAD 20
  41. #define EDIT_TEXT_HEIGHT 20
  42. #define STATIC_TEXT_PAD 20
  43. #define STATIC_TEXT_HEIGHT FONT_HEIGHT
  44.  
  45. #define CHOICE_HEIGHT 20
  46. #define CHOICE_PAD 20
  47.  
  48. #define SCROLL_WIDTH 180
  49. #define SCROLL_HEIGHT 16
  50. /*
  51. #define LIST_ITEM_HEIGHT 16
  52. #define MAX_LIST_ROWS 12
  53. */
  54. int max_line_size(char *);
  55. LVAL DialogTextItemText(LVAL,int,char *);
  56.  
  57. /***********************************************************************/
  58. /***********************************************************************/
  59. /**                                                                   **/
  60. /**                       Internal Dialog Functions                   **/
  61. /**                                                                   **/
  62. /***********************************************************************/
  63. /***********************************************************************/
  64.  
  65. /***********************************************************************/
  66. /**                                                                   **/
  67. /**                          Utility Functions                        **/
  68. /**                                                                   **/
  69. /***********************************************************************/
  70.  
  71. static Point StringSize(char *s){
  72.    Point pt;
  73.    pt.v=window->RPort->TxHeight;
  74.    pt.h=window->RPort->TxWidth*strlen(s);
  75.    return(pt);}
  76.  
  77. /***********************************************************************/
  78. /**                                                                   **/
  79. /**                         Callback Functions                        **/
  80. /**                                                                   **/
  81. /***********************************************************************/
  82.  
  83. static void clear_dialog(DialogPtr theDialog){
  84.    struct RastPort *rp;
  85.    rp=theDialog->RPort;
  86.    SetAPen(rp,WHITE);
  87.    SetOPen(rp,BLACK);
  88.    RectFill(rp,2,10,theDialog->Width-3,theDialog->Height-3);
  89.    BNDRYOFF(rp);}
  90.  
  91. static void SetClusterValue(DialogPtr theDialog,int item){
  92.    int i,n,ns,leader;
  93.    DialogItemData *data;
  94.    struct Gadget *lgad;
  95.    data=GetDialogItemData(theDialog);
  96.    leader=data[item].clusterLeader;
  97.    ns=data[item].clusterSize;
  98.    n=ns+leader;
  99.    lgad=data[leader].itemPtr;
  100.    RemoveGList(theDialog,lgad,ns);
  101.    for(i=leader;i<n;i++){
  102.       if(i!=item)data[i].itemPtr->Flags=GADGHIMAGE;
  103.       else data[i].itemPtr->Flags=GADGHIMAGE|SELECTED;}
  104.    AddGList(theDialog,lgad,leader,ns,0);
  105.    clear_dialog(theDialog);
  106.    RefreshGList(data->itemPtr,theDialog,0,-1);}
  107.  
  108. /* Action proc for scroll bars. */
  109.  
  110. void doDialog(int theItem,DialogPtr theDialog){
  111.    LVAL item, args;
  112.    DialogItemData *data;
  113.    int type;
  114.    struct Gadget *itemPtr;
  115.    data=GetDialogItemData(theDialog);
  116.    item=data[theItem].object;
  117.    type=data[theItem].type;
  118.    itemPtr=data[theItem].itemPtr;
  119.    if(type==TOGGLE_ITEM)set_slot_value(item,s_value,itemPtr->Flags&SELECTED?s_true:NIL);
  120.    else if(type==CHOICE_ITEM)SetClusterValue(theDialog,theItem);
  121.    if(objectp(item)&&theItem){
  122.       xlsave1(args);
  123.       args=list2(item,sk_do_action);
  124.       xsapplysubr(xmsend,args);
  125.       xlpop();}}
  126.  
  127. /***********************************************************************/
  128. /***********************************************************************/
  129. /**                                                                   **/
  130. /**                        Public Dialog Functions                    **/
  131. /**                                                                   **/
  132. /***********************************************************************/
  133. /***********************************************************************/
  134.  
  135. /***********************************************************************/
  136. /**                                                                   **/
  137. /**                           Dialog Functions                        **/
  138. /**                                                                   **/
  139. /***********************************************************************/
  140.  
  141. LVAL DialogGetModalItem(LVAL dialog){
  142.    DialogPtr theDialog;
  143.    LVAL item;
  144.    short itemNumber;
  145.    int type;
  146.    DialogItemData *data;
  147.    struct IntuiMessage *message;
  148.    struct Gadget *address;
  149.    int class;
  150.    if(!(theDialog=GETDIALOGADDRESS(dialog)))xlfail("the dialog is not visible");
  151.    for(;;){
  152.       Wait(1<<theDialog->UserPort->mp_SigBit);
  153.       if(message=(struct IntuiMessage *)GetMsg(theDialog->UserPort)){
  154.          class=message->Class;
  155.          address=(struct Gadget *)message->IAddress;
  156.          ReplyMsg((struct Message *)message);
  157.          if(class==GADGETUP||class==GADGETDOWN)break;}}
  158.    itemNumber=address->GadgetID;
  159.    if(itemNumber<0||itemNumber>DialogItemCount(theDialog))xlfail("invalid item number");
  160.    data=GetDialogItemData(theDialog);
  161.    type=data[itemNumber].type;
  162.    item=data[itemNumber].object;
  163.    if(type==TOGGLE_ITEM)set_slot_value(item,s_value,address->Flags&SELECTED?s_true:NIL);
  164.    else if(type==CHOICE_ITEM)SetClusterValue(theDialog,itemNumber);
  165.    return(item);}
  166.  
  167. /***********************************************************************/
  168. /**                                                                   **/
  169. /**                         Button Item Functions                     **/
  170. /**                                                                   **/
  171. /***********************************************************************/
  172.  
  173. void DialogButtonGetDefaultSize(LVAL item,int *width,int *height){
  174.    LVAL text=slot_value(item, s_text);
  175.    Point sz;
  176.    if(!stringp(text))xlerror("not a string",text);
  177.    sz=StringSize(getstring(text));
  178.    if(width)*width=max(sz.h+BUTTON_PAD,BUTTON_WIDTH);
  179.    if(height)*height=BUTTON_HEIGHT;}
  180.  
  181. /***********************************************************************/
  182. /**                                                                   **/
  183. /**                         Toggle Item Functions                     **/
  184. /**                                                                   **/
  185. /***********************************************************************/
  186.  
  187. void DialogToggleGetDefaultSize(LVAL item,int *width,int *height){
  188.    Point sz;
  189.    sz=StringSize(getstring(slot_value(item,s_text)));
  190.    if(width)*width=sz.h+TOGGLE_PAD;
  191.    if(height)*height=TOGGLE_HEIGHT;}
  192.  
  193. LVAL DialogToggleItemValue(LVAL item,int set,LVAL value){
  194.    LVAL dialog;
  195.    struct Gadget *gad;
  196.    DialogPtr theDialog;
  197.    dialog=slot_value(item,s_dialog);
  198.    if(theDialog=GETDIALOGADDRESS(dialog)){
  199.       gad=FindItemData(theDialog,item)->itemPtr;
  200.       if(set){
  201.          set_slot_value(item,s_value,value?s_true:NIL);
  202.          if(value)gad->Flags|=SELECTED;
  203.          else gad->Flags&=~SELECTED;
  204.          RefreshGList(gad,theDialog,0,1);}}
  205.    return(slot_value(item,s_value));}
  206.  
  207. /***********************************************************************/
  208. /**                                                                   **/
  209. /**                         Text Item Functions                       **/
  210. /**                                                                   **/
  211. /***********************************************************************/
  212.  
  213. void DialogTextGetDefaultSize(LVAL item,int *width,int *height){
  214.    Point sz;
  215.    LVAL text=slot_value(item,s_text);
  216.    LVAL text_length=slot_value(item,xlenter("TEXT-LENGTH"));
  217.    int w=0;
  218.    char *s;
  219.    if(stringp(text)){
  220.       w=max_line_size(getstring(text));
  221.       s=(char *)getstring(text);
  222.       for(sz.v=STATIC_TEXT_HEIGHT;*s!='\0';s++)if(*s=='\n'||*s=='\r')sz.v+=STATIC_TEXT_HEIGHT;}
  223.    if(fixp(text_length)){
  224.       sz=StringSize("M");
  225.       w=max((int)(getfixnum(text_length)*sz.h),w);}
  226.    if(slot_value(item,s_editable)){
  227.       if(width)*width=w+EDIT_TEXT_PAD;
  228.       if(height)*height=EDIT_TEXT_HEIGHT;}
  229.    else {
  230.       if(width)*width=w+STATIC_TEXT_PAD;
  231.       if(height)*height=sz.v;}}           /* STATIC_TEXT_HEIGHT */
  232.  
  233. LVAL DialogTextItemText(LVAL item,int set,char *text){
  234.    DialogItemData *itemData;
  235.    DialogPtr theDialog;
  236.    struct Gadget *gad;
  237.    theDialog=(DialogPtr)GETDIALOGADDRESS(slot_value(item,s_dialog));
  238.    if(theDialog){
  239.       itemData=FindItemData(theDialog,item);
  240.       gad=itemData->itemPtr;
  241.       if(set){
  242.          if(slot_value(item,s_editable)){
  243.             strcpy(((struct StringInfo *)gad->SpecialInfo)->Buffer,text);}
  244.          else {
  245.             clear_dialog(theDialog);
  246.             gad->GadgetText->IText=text;}
  247.          RefreshGList(GetDialogData(theDialog)->gadl,theDialog,0,-1);}
  248.       else set_slot_value(item,s_text,make_string(((struct StringInfo *)itemData->itemPtr->SpecialInfo)->Buffer));}
  249.    return(slot_value(item,s_text));}
  250.  
  251. /***********************************************************************/
  252. /**                                                                   **/
  253. /**                         Choice Item Functions                     **/
  254. /**                                                                   **/
  255. /***********************************************************************/
  256.  
  257. void DialogChoiceGetDefaultSize(LVAL item,int *width,int *height){
  258.    Point sz,pt;
  259.    LVAL text=slot_value(item,s_text);
  260.    for(sz.h=0,sz.v=0;consp(text);text=cdr(text)){
  261.       pt=StringSize(getstring(car(text)));
  262.       sz.h=max(sz.h,pt.h);
  263.       sz.v+=CHOICE_HEIGHT;}
  264.    if(width)*width=sz.h+CHOICE_PAD;
  265.    if(height)*height=sz.v;}
  266.  
  267. LVAL DialogChoiceItemValue(LVAL item,int set,int value){
  268.    LVAL result;
  269.    DialogItemData *itemData,*data;
  270.    DialogPtr theDialog;
  271.    int leader,i,n;
  272.    if(theDialog=(DialogPtr)GETDIALOGADDRESS(slot_value(item,s_dialog))){
  273.       data=GetDialogItemData(theDialog);
  274.       itemData=FindItemData(theDialog,item);
  275.       leader=itemData->clusterLeader;
  276.       n=itemData->clusterSize;
  277.       if(set){
  278.          if(value<0||value>=n)xlfail("value out of range");
  279.          for(i=0;i<n;i++)data[leader+i].itemPtr->Flags&=~SELECTED;
  280.          data[leader+value].itemPtr->Flags|=SELECTED;
  281.          RefreshGList(data[leader].itemPtr,theDialog,0,n);
  282.          result=cvfixnum((FIXTYPE)value);}
  283.       else {
  284.          result=NIL;
  285.          for(i=0;i<n&&!result;i++) {  
  286.             result=(data[leader+i].itemPtr->Flags&SELECTED)?cvfixnum((FIXTYPE)i):NIL;}}
  287.       set_slot_value(item, s_value, result);}
  288.    return(slot_value(item, s_value));}
  289.  
  290. /***********************************************************************/
  291. /**                                                                   **/
  292. /**                         Scroll Item Functions                     **/
  293. /**                                                                   **/
  294. /***********************************************************************/
  295.  
  296. void DialogScrollGetDefaultSize(LVAL item,int *width,int *height){
  297.    if(width)*width=SCROLL_WIDTH;
  298.    if(height)*height=SCROLL_HEIGHT;}
  299.  
  300. static LVAL scroll_item_value(LVAL item,int set,int value,int which){
  301.    LVAL result;
  302.    DialogItemData *itemData;
  303.    DialogPtr theDialog;
  304.    struct Gadget *gad;
  305.    struct PropInfo *pi;
  306.    int max,min;
  307.    if(theDialog=GETDIALOGADDRESS(slot_value(item,s_dialog))){
  308.       itemData=FindItemData(theDialog,item);
  309.       gad=itemData->itemPtr;
  310.       max=getfixnum(slot_value(item,s_max_value));
  311.       min=getfixnum(slot_value(item,s_min_value));
  312.       pi=(struct PropInfo *)gad->SpecialInfo;
  313.       switch (which) {
  314.          case 'H': {
  315.             if(!set)value=max;
  316.             result=cvfixnum((FIXTYPE)value);
  317.             set_slot_value(item,s_max_value,result);
  318.             break;}
  319.          case 'L': {
  320.             if(!set)value=min;
  321.             result=cvfixnum((FIXTYPE)value);
  322.             set_slot_value(item,s_min_value,result);
  323.             break;}
  324.          case 'V': {
  325.             if(set){
  326.                if(gad->Height>gad->Width){
  327.                   NewModifyProp(gad,theDialog,0,AUTOKNOB|FREEVERT,MAXPOT,
  328.                   ((value-min)*MAXPOT)/(max-min),MAXBODY,MAXBODY/(max-min),1);}
  329.                else {
  330.                   NewModifyProp(gad,theDialog,0,AUTOKNOB|FREEHORIZ,
  331.                   ((value-min)*MAXPOT)/(max-min),MAXPOT,MAXBODY/(max-min),
  332.                   MAXBODY,1);}}
  333.             else {
  334.                value=(gad->Height>gad->Width)?pi->VertPot:pi->HorizPot;
  335.                value=(value*(max-min))/MAXPOT+min;}
  336.             result=cvfixnum((FIXTYPE)value);
  337.             set_slot_value(item,s_value,result);
  338.             break;}}}
  339.    return(result);}
  340.  
  341. LVAL DialogScrollItemValue(LVAL item,int set,int value){
  342.   return(scroll_item_value(item,set,value,'V'));}
  343.  
  344. LVAL DialogScrollItemMax(LVAL item,int set,int value){
  345.   return(scroll_item_value(item,set,value,'H'));}
  346.  
  347. LVAL DialogScrollItemMin(LVAL item,int set,int value){
  348.   return(scroll_item_value(item,set,value,'L'));}
  349.  
  350. /***********************************************************************/
  351. /**                                                                   **/
  352. /**                          List Item Functions                      **/
  353. /**                                                                   **/
  354. /***********************************************************************/
  355.  
  356. void DialogListGetDefaultSize(LVAL item,int *width,int *height){
  357.    /*LVAL columns=slot_value(item,s_columns);
  358.    LVAL data=slot_value(item,s_list_data);
  359.    Point sz;
  360.    if(listp(data))sz.v=LIST_ITEM_HEIGHT*llength(data);
  361.    else if(simplevectorp(data))sz.v=LIST_ITEM_HEIGHT*getsize(data);
  362.    else if(matrixp(data))sz.v=16*getfixnum(getelement(displacedarraydim(data),0));
  363.    sz.v=min(sz.v,MAX_LIST_ROWS*LIST_ITEM_HEIGHT);
  364.    if(matrixp(data)&&getfixnum(getelement(displacedarraydim(data),1))>getfixnum(columns))sz.v+=15;
  365.    sz.h=150*getfixnum(columns);
  366.    if (width)*width=sz.h;
  367.    if(height)*height=sz.v;}*/
  368.    xlfail("not supported 48"); }
  369.  
  370. void DialogListItemSetText(LVAL item,LVAL index,char *text){
  371.    /*LVAL listData;
  372.    DialogItemData *itemData;
  373.    DialogPtr theDialog;
  374.    Point cell;
  375.    int temp;
  376.    listData=slot_value(item,s_list_data);
  377.    if(matrixp(listData)){
  378.       cell=ListToPoint(index);
  379.          temp=cell.h;
  380.       cell.h=cell.v;
  381.       cell.v=temp;}
  382.    else {
  383.       if(!fixp(index))xlerror("not an integer",index);
  384.       cell.h=0;
  385.       cell.v=getfixnum(index);}
  386.    theDialog=(DialogPtr)GETDIALOGADDRESS(slot_value(item,s_dialog));
  387.    if(theDialog) {
  388.       itemData=FindItemData(theDialog,item);
  389.       itemData->itemPtr->GadgetText->IText=text;}}*/
  390.     xlfail("not supported 49"); }
  391.  
  392. LVAL DialogListItemSelection(LVAL item,int set,LVAL index){
  393.    xlfail("not supported 50");
  394.    return(0);}
  395.  
  396. static max_line_size(char *s){
  397.    char *bp;
  398.    int w;
  399.    Point sz;
  400.    for(w=0;*s!='\0';*s++){
  401.       for(bp=buf;*s!='\0'&&*s!='\r'&&*s!='\n';s++,bp++)*bp=*s;
  402.       *bp='\0';
  403.       sz=StringSize(buf);
  404.       w=max(w, sz.h);}
  405.    return(w);}
  406.