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

  1. /* AmiIviewWindow.c - Low Level Window 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/intuition.h>
  9. #include <proto/exec.h>
  10. #include <exec/memory.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "autil2.h"
  14. #include "xlisp.h"
  15. #include "osdef.h"
  16. #include "xlproto.h"
  17. #include "xlsproto.h"
  18. #include "iviewproto.h"
  19. #include "Stproto.h"
  20. #include "osproto.h"
  21. #include "amivar.h"
  22. #include "xlsvar.h"
  23.  
  24. /* forward declarations */
  25. void init_ami_cursors(void);
  26.  
  27. StGWWinInfo *IViewWindowWinInfo(struct Window *w){
  28.    return(w?(StGWWinInfo *)w->UserData:0);}
  29.  
  30. /**************************************************************************/
  31. /**                                                                      **/
  32. /**                       Initialization Functions                       **/
  33. /**                                                                      **/
  34. /**************************************************************************/
  35.  
  36. void StInitGraphics(void){
  37.    initialize_static_globals();
  38.    init_ami_colors();
  39.    init_ami_cursors();}
  40.  
  41. /**************************************************************************/
  42. /**                                                                      **/
  43. /**                       Window Creation Functions                      **/
  44. /**                                                                      **/
  45. /**************************************************************************/
  46.  
  47. void scroll_action(StGWWinInfo *gwinfo,int id){
  48.    int left,top,width,height,value;
  49.    if(id){
  50.       value=((struct PropInfo *)gwinfo->vscroll->SpecialInfo)->VertPot;
  51.       StGWSetScroll(gwinfo,gwinfo->view_h,value,0);}
  52.    else {
  53.       value=((struct PropInfo *)gwinfo->hscroll->SpecialInfo)->HorizPot;
  54.       StGWSetScroll(gwinfo,value,gwinfo->view_v,0);}
  55.    StGWGetViewRect(gwinfo,&left,&top,&width,&height);
  56.    StGWStartBuffering(gwinfo);
  57.    StGWObRedraw(gwinfo->Object);
  58.    StGWBufferToScreen(gwinfo,left,top,width,height);}
  59.  
  60. void mouse_action(StGWWinInfo *gwinfo,unsigned short qualifier){
  61.    struct Window *w;
  62.    int x,y,width,height;
  63.    MouseClickModifier mods;
  64.    w=gwinfo->window;
  65.    StGWGetViewRect(gwinfo,0,0,&width,&height);
  66.    x=w->MouseX-w->BorderLeft;
  67.    y=w->MouseY-w->BorderTop;
  68.    if(x<0||y<0||x>width||y>height)return;
  69.    scroll_clip(gwinfo,&x,&y);
  70.    mods=(qualifier&SHIFTED)?ExtendModifier:NoModifiers;
  71.    if(qualifier&ALT)mods+=2;
  72.    StGWObDoMouse(gwinfo->Object,x,y,MouseClick,mods);}
  73.  
  74. void key_action(StGWWinInfo *gwinfo,char key,int mods){
  75.    if(key=='\r')key='\n';
  76.    StGWObDoKey(gwinfo->Object,key,mods&SHIFTED,mods&ALT);}
  77.  
  78. void graph_update_action(StGWWinInfo *gwinfo,int resized){
  79.    LVAL object;
  80.    struct Window *w;
  81.    int width,height;
  82.    unsigned short s;
  83.    if(!gwinfo||!(w=gwinfo->window))return;
  84.    object=gwinfo->Object;
  85.    SetHardwareState(gwinfo);
  86.    if(!gwinfo->initialized){
  87.       resized=1;
  88.       gwinfo->initialized=1;}
  89.    StGWGetViewRect(gwinfo,0,0,&width,&height);
  90.    if(resized){
  91.       if(gwinfo->hasHscroll){
  92.          gwinfo->view_h=s=(gwinfo->canvasWidth-width>0)?(MAXBODY*width)/gwinfo->canvasWidth:MAXBODY;
  93.          NewModifyProp(gwinfo->hscroll,w,0,AUTOKNOB|FREEHORIZ,
  94.          (short)gwinfo->view_h,MAXPOT,s,MAXBODY,1);}
  95.       else gwinfo->canvasWidth=width;
  96.       if(gwinfo->hasVscroll){
  97.          gwinfo->view_v=s=(gwinfo->canvasHeight-height>0)?(MAXBODY*height)/gwinfo->canvasHeight:MAXBODY;
  98.          NewModifyProp(gwinfo->vscroll,w,0,AUTOKNOB|FREEVERT,
  99.          MAXPOT,(short)gwinfo->view_v,MAXBODY,s,1);}
  100.       else gwinfo->canvasHeight=height;
  101.       StGWObResize(object);}
  102.    StGWObRedraw(object);}
  103. /*
  104. void graph_activate_action(StGWWinInfo *gwinfo,int active){
  105.    if(active)ami_do_cursor(gwinfo);}
  106.  
  107. void clobber_action(StGWWinInfo *gwinfo){
  108.    struct Window *w;
  109.    w=gwinfo->window;
  110.    if(IViewInternalIsLinked(w))IViewUnlinkWindow(w);
  111.    StGWObDoClobber(gwinfo->Object);
  112.    StGWRemove(gwinfo);}
  113. */
  114. void idle_action(StGWWinInfo *gwinfo){
  115.    struct Window *w;
  116.    int old_x,old_y;
  117.    w=gwinfo->window;
  118.    old_x=gwinfo->mouse_x;
  119.    old_y=gwinfo->mouse_y;
  120.    gwinfo->mouse_x=w->MouseX;
  121.    gwinfo->mouse_y=w->MouseY;
  122.    if(old_x!=w->MouseX||old_y!=w->MouseY)
  123.    StGWObDoMouse(gwinfo->Object,w->MouseX-w->BorderLeft,w->MouseY-w->BorderTop,MouseMove,0);
  124.    if(gwinfo->idleOn)StGWObDoIdle(gwinfo->Object);}
  125.  
  126. StGWWinInfoSize(void){
  127.    return(sizeof(StGWWinInfo));}
  128.  
  129. void StGWInitWinInfo(LVAL object){
  130.    StGWWinInfo *gwinfo=(StGWWinInfo *)StGWObWinInfo(object);
  131.    gwinfo->Object=object;
  132.    gwinfo->initialized=0;
  133.    gwinfo->symbolMode=JAM2;
  134.    gwinfo->canvasWidth=0;
  135.    gwinfo->canvasHeight=0;
  136.    gwinfo->hasHscroll=0;
  137.    gwinfo->hasVscroll=0;
  138.    gwinfo->hscroll=0;
  139.    gwinfo->vscroll=0;
  140.    gwinfo->view_h=0;
  141.    gwinfo->view_v=0;
  142.    gwinfo->h_scroll_inc[0]=1;
  143.    gwinfo->h_scroll_inc[1]=50;
  144.    gwinfo->v_scroll_inc[0]=1;
  145.    gwinfo->v_scroll_inc[1]=50;
  146.    gwinfo->lineType=0;
  147.    gwinfo->drawMode=JAM1;
  148.    gwinfo->backColor=WHITE;
  149.    gwinfo->drawColor=BLACK;
  150.    gwinfo->lineWidth=1;
  151.    gwinfo->window=0;
  152.    gwinfo->idleOn=0;
  153.    gwinfo->use_color=1;
  154.    gwinfo->cursor=0;
  155.    gwinfo->clipped=0;
  156.    gwinfo->RefCon=nil;}
  157.  
  158. IVIEW_WINDOW IViewWindowNew(LVAL object,int is_GW){
  159.    char *title;
  160.    static char deftitle[]="Graph Window";
  161.    unsigned long flags,iflags;
  162.    int left,top,width,height,goAway;
  163.    StGWWinInfo *gwinfo;
  164.    struct Window *w;
  165.    struct NewWindow nw;
  166.    StGWGetAllocInfo(object,&title,&left,&top,&width,&height,&goAway);
  167.    width+=2*screen->WBorLeft;
  168.    height+=2*screen->BarHeight+1;
  169.    if((left-=screen->WBorLeft)<0)left=0;
  170.    if((top-=screen->BarHeight+1)<0)top=0;
  171.    if(left+width>screenw)width=screenw-left;
  172.    if(top+height>screenh)height=screenh-top;
  173.    iflags=GADGETUP|MENUPICK|NEWSIZE|MOUSEBUTTONS|VANILLAKEY|ACTIVEWINDOW|
  174.    INACTIVEWINDOW|SIZEVERIFY;
  175.    flags=WINDOWDRAG|WINDOWSIZING|ACTIVATE|WINDOWDEPTH|SIZEBBOTTOM
  176.    |SMART_REFRESH|NOCAREREFRESH;
  177. #ifdef RMOUSE
  178.    iflags|=MOUSEMOVE;
  179.    flags|=REPORTMOUSE;
  180. #endif RMOUSE
  181.    if(goAway){
  182.       flags|=WINDOWCLOSE;
  183.       iflags|=CLOSEWINDOW;}
  184.    if(!title||strlen(title)<=0)title=deftitle;
  185.    nw.LeftEdge=left;
  186.    nw.TopEdge=top;
  187.    nw.Width=width;
  188.    nw.Height=height;
  189.    nw.DetailPen=WHITE;
  190.    nw.BlockPen=BLACK;
  191.    nw.IDCMPFlags=iflags;
  192.    nw.Flags=flags;
  193.    nw.FirstGadget=0;
  194.    nw.CheckMark=0;
  195.    nw.Title=title;
  196.    nw.Screen=screen;
  197.    nw.BitMap=0;
  198.    nw.MinWidth=100;
  199.    nw.MinHeight=50;
  200.    nw.MaxWidth=screenw;
  201.    nw.MaxHeight=screenh;
  202.    nw.Type=screentype;
  203.    if(!(w=OpenWindow(&nw)))StPerror("window creation failed");
  204.    gwinfo=(StGWWinInfo *)StGWObWinInfo(object);
  205.    gwinfo->window=w;
  206.    if(!gwinfo->hasHscroll)gwinfo->canvasWidth=width;
  207.    if(!gwinfo->hasVscroll)gwinfo->canvasHeight=height;
  208.    w->UserData=(char *)gwinfo;
  209.    if(Menu_Ptr)StMObInstall(0);
  210.    SetHardwareState(gwinfo);
  211.    if(is_GW)set_iview_window_address(w,object);
  212.    else set_iview_address(w,object);
  213.    return(w);}
  214.  
  215. /**************************************************************************/
  216. /**                                                                      **/
  217. /**                          Clipping  Functions                         **/
  218. /**                                                                      **/
  219. /**************************************************************************/
  220.  
  221. void StGWSetClipRect(StGWWinInfo *gwinfo,int clipped,int left,int top,int width,int height){
  222.    if(!gwinfo)return;
  223.    gwinfo->clipped=clipped;
  224.    if(clipped){
  225.       gwinfo->clip_rect.left=left;
  226.       gwinfo->clip_rect.top=top;
  227.       gwinfo->clip_rect.width=width;
  228.       gwinfo->clip_rect.height=height;}}
  229.  
  230. int StGWGetClipRect(StGWWinInfo *gwinfo,int *left,int *top,int *width,int *height){
  231.    if(gwinfo){
  232.       if(left)*left=gwinfo->clip_rect.left;
  233.       if(top)*top=gwinfo->clip_rect.top;
  234.       if(width)*width=gwinfo->clip_rect.width;
  235.       if(height)*height=gwinfo->clip_rect.height;
  236.       return(gwinfo->clipped);}
  237.    else return(0);}
  238.  
  239. /**************************************************************************/
  240. /**                                                                      **/
  241. /**                         Miscellaneous Functions                      **/
  242. /**                                                                      **/
  243. /**************************************************************************/
  244.  
  245. #define NumBasicCursors 9
  246.  
  247. static int NumCursors;
  248.  
  249. typedef struct {
  250.    unsigned short *curs;
  251.    int h,v;
  252.    LVAL refcon;}
  253. cursor_entry;
  254.  
  255. static cursor_entry *curstab;
  256.  
  257. static void init_ami_cursors(void){
  258.   NumCursors=NumBasicCursors;
  259.   curstab=(cursor_entry *)StCalloc(NumCursors,sizeof(cursor_entry));}
  260.  
  261. void StGWSetCursRefCon(int index,LVAL rc){
  262.   if(index<NumCursors)curstab[index].refcon=rc;}
  263.  
  264. LVAL StGWGetCursRefCon(int index){
  265.   if(index<NumCursors)return(curstab[index].refcon);
  266.   else return(0);}
  267.  
  268. static void set_image_bits(short *bits,char *image,char *mask){
  269.    int i,j;
  270.    for(i=0;i<16;i++)for(j=0;j<16;j++){
  271.       if(image[i*16+j])bits[2*i+2]|=(1<<j);
  272.       if(mask&&mask[i*16+j])bits[2*i+3]|=(1<<j);}}
  273.  
  274. StGWMakeCursor(int n,char *image,char *mask,int h,int v,LVAL refcon){
  275.    int index;
  276.    char *temp;
  277.    cursor_entry *c;
  278.    if(n!=16||!image)return(-1);
  279.    for(index=0;index<NumCursors&&StGWGetCursRefCon(index);index++);
  280.    if(index>=NumCursors){
  281.       temp=realloc(curstab,(NumCursors+1)*sizeof(cursor_entry));
  282.       if(!temp)return(-1);
  283.       curstab=(cursor_entry *)temp;
  284.       NumCursors++;
  285.       c=&curstab[index];
  286.       c->curs=0;
  287.       c->refcon=0;}
  288.    else c=&curstab[index];
  289.    if(!c->curs&&!(c->curs=AllocMem(72,MEMF_CHIP|MEMF_CLEAR)))return(-1);
  290.    set_image_bits(c->curs,image,mask);
  291.    curstab[index].h=-h;
  292.    curstab[index].v=-v;
  293.    curstab[index].refcon=refcon;
  294.    return(index);}
  295.    
  296. int StGWMakeResCursor(char *name,int num,LVAL refcon){
  297.    return(0);}
  298.  
  299. void StGWFreeCursor(int index){
  300.    cursor_entry *c=&curstab[index];
  301.    if(index<NumCursors&&index>=NumBasicCursors){
  302.       if(c->curs)FreeMem(c->curs,72);
  303.       c->curs=0;
  304.       c->refcon=0;}}
  305.  
  306. #include "pointer.h"
  307. static unsigned short *get_cursor(int index,int *x,int *y){
  308.    unsigned short *curs=0;
  309.    if(index<NumBasicCursors){
  310.       switch (index) {
  311.          case ARROW_CURSOR: {
  312.             curs=nil;
  313.             break;}
  314.          case WATCH_CURSOR: {
  315.             curs=snooze;
  316.             *x=snoozex;
  317.             *y=snoozey;
  318.             break;}
  319.          case CROSS_CURSOR: {
  320.             curs=cross;
  321.             *x=crossx;
  322.             *y=crossy;
  323.             break;}
  324.          case BRUSH_CURSOR: {
  325.             curs=brush;
  326.             *x=brushx;
  327.             *y=brushy;
  328.             break;}
  329.          case HAND_CURSOR: {
  330.             curs=hand;
  331.             *x=handx;
  332.             *y=handy;
  333.             break;}
  334.          case FINGER_CURSOR: {
  335.             curs=finger;
  336.             *x=fingerx;
  337.             *y=fingery;
  338.             break;}
  339.          case HOUR_GLASS_CURSOR: {
  340.             curs=glass;
  341.             *x=glassx;
  342.             *y=glassy;
  343.             break;}
  344.          case TRASH_BAG_CURSOR: {
  345.             curs=bag;
  346.             *x=bagx;
  347.             *y=bagy;
  348.             break;}
  349.          case TRASH_CAN_CURSOR: {
  350.             curs=can;
  351.             *x=canx;
  352.             *y=cany;
  353.             break;}}}
  354.    else if(index<NumCursors){
  355.       curs=curstab[index].curs;
  356.       *x=curstab[index].h;
  357.       *y=curstab[index].v;}
  358.    return(curs);}
  359.   
  360. void ami_do_cursor(StGWWinInfo *gwinfo){
  361.    unsigned short *curs;
  362.    struct Window *w;
  363.    int x,y,l;
  364.    w=gwinfo->window;
  365.    l=(gwinfo->cursor==WATCH_CURSOR)?22:16;
  366.    if(curs=get_cursor(gwinfo->cursor,&x,&y))SetPointer(w,curs,l,16,x,y);
  367.    else ClearPointer(w);}
  368.  
  369. void StGWSetCursor(StGWWinInfo *gwinfo,int cursor){
  370.    if(gwinfo)gwinfo->cursor=cursor;}
  371.  
  372. StGWCursor(StGWWinInfo *gwinfo){
  373.    return(gwinfo?gwinfo->cursor:0);}
  374.  
  375.