home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / win_stack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-17  |  10.9 KB  |  370 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: win_stack.c,v 1.2 89/04/11 12:20:52 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/win_stack.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/win_stack.c,v $$Revision: 1.2 $";
  12.  
  13. /* push - pop window environment */
  14.  
  15. #include "bitmap.h"
  16. #include "font.h"
  17. #include "defs.h"
  18. #include "window.h"
  19. #include "menu.h"
  20. #include "event.h"
  21. #include <stdio.h>
  22.  
  23. #define S(x)    (stack->x)
  24.  
  25. /* push a window on the environment stack */
  26.  
  27. int
  28. win_push(win,level)
  29. register WINDOW *win;        /* window to push */
  30. int level;            /* what things to push */
  31.    {
  32.    register WINDOW *stack;    /* pushed window goes here */
  33.    register int i,j;
  34.    char *malloc(), *save_line(), *print_stack();
  35.    struct menu_state *menu_copy();
  36.  
  37.    if ((stack = (WINDOW *) malloc(sizeof(WINDOW))) == (WINDOW *) 0)
  38.       return(-1);
  39.     
  40.    if (level == 0)
  41.       level = P_DEFAULT;
  42.  
  43. #ifdef DEBUG
  44.    dprintf(P)(stderr,"%s Stacking %s\n",
  45.                    W(tty),print_stack(level));
  46. #endif
  47.  
  48.    /* setup stacked window */
  49.  
  50.    *stack = *win;    /* structure assignment */
  51.    W(stack) = stack;
  52.  
  53.    /* bcopy(win,stack,sizeof(WINDOW)); */
  54.  
  55.    for(j=0;j<MAXMENU;j++)
  56.       S(menus)[j] = (struct menu_state *) 0;
  57.    for(j=0;j<MAXEVENTS;j++)
  58.       S(events)[j] = (char *) 0;
  59.    for(j=0;j<MAXBITMAPS;j++)
  60.       S(bitmaps)[j] = (BITMAP *) 0;
  61.    S(save) = (BITMAP *) 0;
  62.    S(clip_list) = (char *) 0;
  63.  
  64.    /* setup each pushed item */
  65.  
  66.    for(i=1;i!=P_MAX;i <<= 1)
  67.       switch (level&i) {
  68.          case P_MENU:        /* save the menus */
  69. #ifdef DEBUG
  70.               dprintf(P)(stderr,"  menus ");
  71. #endif
  72.               for(j=0;j<MAXMENU;j++)
  73.                  if (W(menus)[j] && (level&P_CLEAR)) {
  74.                     S(menus)[j] = W(menus)[j]; 
  75.                     W(menus)[j] = (struct menu_state *) 0;
  76. #ifdef DEBUG
  77.                     dprintf(P)(stderr,"%d ",j);
  78. #endif
  79.                     }
  80.                  else if (W(menus)[j]) {
  81.                     S(menus)[j] = menu_copy(W(menus)[j]); 
  82. #ifdef DEBUG
  83.                     dprintf(P)(stderr,"%d ",j);
  84. #endif
  85.                     }
  86. #ifdef DEBUG
  87.               dprintf(P)(stderr,"\n");
  88. #endif
  89.               break;
  90.          case P_EVENT:        /* save the events */
  91.  
  92. #ifdef DEBUG
  93.               dprintf(P)(stderr,"  events ");
  94. #endif
  95.               if (IS_EVENT(win,EVENT_STACK))
  96.                  EVENT_SET_MASK(win,EVENT_STFLAG);
  97.  
  98.               if (level&P_CLEAR) 
  99.                  W(event_mask) = IS_EVENT(win,EVENT_STFLAG);
  100.               else
  101.                  EVENT_CLEAR_MASK(win,EVENT_STACK);
  102.  
  103.               for(j=0;j<MAXEVENTS;j++)
  104.                  if (W(events)[j] && (level&P_CLEAR)) {
  105.                     S(events)[j] = W(events)[j]; 
  106.                     W(events)[j] = (char *) 0;
  107. #ifdef DEBUG
  108.                     dprintf(P)(stderr,"%d ",j);
  109. #endif
  110.                     }
  111.                  else if (W(events)[j]) {
  112.                     S(events)[j] = save_line(W(events)[j]); 
  113. #ifdef DEBUG
  114.                     dprintf(P)(stderr,"%d ",j);
  115. #endif
  116.                     }
  117. #ifdef DEBUG
  118.               dprintf(P)(stderr,"\n");
  119.                         
  120. #endif
  121.               break;
  122.          case P_CURSOR:        /* restore the cursor style */
  123.               if (level&P_CLEAR)
  124.                  W(curs_type) = CS_BLOCK;
  125.               break;
  126.          case P_BITMAP:        /* save the bitmaps */
  127. #ifdef DEBUG
  128.               dprintf(P)(stderr,"  bitmaps ");
  129. #endif
  130.               for(j=0;j<MAXBITMAPS;j++)
  131.                  if (W(bitmaps)[j] && level&P_CLEAR) {
  132.                     S(bitmaps)[j] = W(bitmaps)[j];
  133.                     W(bitmaps)[j] = (BITMAP *) 0;
  134. #ifdef DEBUG
  135.                     dprintf(P)(stderr,"%d ",j);
  136. #endif
  137.                     }
  138.                  else if (W(bitmaps)[j]) {
  139.                     S(bitmaps)[j] = bit_alloc(BIT_WIDE(W(bitmaps)[j]),
  140.                                        BIT_HIGH(W(bitmaps)[j]),NULL_DATA,
  141.                                        BIT_DEPTH(W(bitmaps)[j]));
  142.                     bit_blit(S(bitmaps)[j],0,0,BIT_WIDE(W(bitmaps)[j]),
  143.                              BIT_HIGH(W(bitmaps)[j]),BIT_SRC,W(bitmaps)[j],0,0);
  144. #ifdef DEBUG
  145.                     dprintf(P)(stderr,"%d ",j);
  146. #endif
  147.                     }
  148. #ifdef DEBUG
  149.               dprintf(P)(stderr,"\n");
  150. #endif
  151.               break;
  152.          case P_WINDOW:        /* save the bit image */
  153. #ifdef DEBUG
  154.               dprintf(P)(stderr,"  window\n");
  155. #endif
  156.               S(save) = bit_alloc(BIT_WIDE(W(border)),BIT_HIGH(W(border)),
  157.                                   NULL_DATA,DEPTH);
  158.               if (W(save) && !(W(flags)&W_ACTIVE))
  159.                  bit_blit(S(save),0,0,BIT_WIDE(W(save)),BIT_HIGH(W(save)),
  160.                           BIT_SRC,W(save),0,0);
  161.               else
  162.                  bit_blit(S(save),0,0,BIT_WIDE(W(border)),BIT_HIGH(W(border)),
  163.                           BIT_SRC,W(border),0,0);
  164.               break;
  165.          case P_POSITION:    /* save the window position */
  166. #ifdef DEBUG
  167.               dprintf(P)(stderr,"  position\n");
  168. #endif
  169.               S(esc)[1] = BIT_WIDE(W(border));
  170.               S(esc)[2] = BIT_HIGH(W(border));
  171.               break;
  172.          case P_TEXT:        /* save text region */
  173.               if (level&P_CLEAR) {
  174.                  W(text).x = 0;
  175.                  W(text).y = 0;
  176.                  W(text).wide = 0;
  177.                  W(text).high = 0;
  178.                  }
  179.               break;
  180.          case P_MOUSE:        /* save mouse position */
  181. #ifdef DEBUG
  182.               dprintf(P)(stderr,"  mouse\n");
  183. #endif
  184.               S(esc)[3] = mousex;
  185.               S(esc)[4] = mousey;
  186.               break;
  187.          case P_FLAGS:        /* save window flags  */
  188.               if (level&P_CLEAR) {
  189.                  W(flags)  &= ~W_SAVE;
  190.                  W(flags)  |= W_BACKGROUND;
  191.                  W(style) = NOCOLOR&BIT_SRC | GETCOLOR(BLACK);
  192.                  W(background) = NOCOLOR&W(background) | GETCOLOR(WHITE);
  193.                  if (win == active)
  194.                     border(win,SUM_BDR-1,1);
  195.                  else
  196.                     border(win,BLK_BDR,WH_BDR);
  197.                  W(dup) = '\0';        /* clear the dupkey mode */
  198.                  }
  199.               break;
  200.          }
  201.  
  202.    S(code) = level;
  203.    S(window) = (BITMAP *) 0;
  204.    S(border) = (BITMAP *) 0;
  205.    S(snarf) = (char *) 0;
  206.    S(bitmap) = (BITMAP *) 0;
  207.    return(level);
  208.    }
  209.  
  210. /* pop the window stack */
  211.  
  212. int
  213. win_pop(win)
  214. WINDOW *win;                /* window to pop to */
  215.    {
  216.    register int i,j;
  217.    register WINDOW *stack = W(stack);    /* window to pop from */
  218.    char *print_stack();
  219.  
  220.    if (stack == (WINDOW *) 0) {
  221. #ifdef DEBUG
  222.       dprintf(P)(stderr,"  No environment to pop\n");
  223. #endif
  224.       return(-1);
  225.       }
  226.  
  227. #ifdef DEBUG
  228.    dprintf(P)(stderr,"%s popping %s\n",W(tty),print_stack(S(code)));
  229. #endif
  230.  
  231.    /* pop each item stacked */
  232.  
  233.    for(i=1;i!=P_MAX;i <<= 1)
  234.       switch (S(code)&i) {
  235.          case P_MENU:        /* restore the menus */
  236. #ifdef DEBUG
  237.               dprintf(P)(stderr,"  menus ");
  238. #endif
  239.               W(menu[0]) = S(menu[0]);
  240.               W(menu[1]) = S(menu[1]);
  241.               for(j=0;j<MAXMENU;j++) {
  242.                  if (W(menus)[j]) {
  243. #ifdef DEBUG
  244.                     dprintf(P)(stderr,"d(%d) ",j);
  245. #endif
  246.                     menu_destroy(W(menus)[j]);
  247.                     }
  248.                  if (S(menus)[j]) {
  249. #ifdef DEBUG
  250.                     dprintf(P)(stderr,"r(%d) ",j);
  251. #endif
  252.                     W(menus)[j] = S(menus)[j];
  253.                     S(menus)[j] = (struct menu_state *) 0;
  254.                     }
  255.                  else
  256.                     W(menus)[j] = (struct menu_state *) 0;
  257.                  }
  258. #ifdef DEBUG
  259.               dprintf(P)(stderr,"\n");
  260. #endif
  261.               break;
  262.          case P_EVENT:        /* restore the events */
  263.  
  264. #ifdef DEBUG
  265.               dprintf(P)(stderr,"  events ");
  266. #endif
  267.               for(j=0;j<MAXEVENTS;j++) {
  268.                  if (W(events)[j]) {
  269. #ifdef DEBUG
  270.                     dprintf(P)(stderr,"d(%d) ",j);
  271. #endif
  272.                     free(W(events)[j]);
  273.                     }
  274.                  W(events)[j] = S(events)[j];
  275.                  S(events)[j] = (char *) 0;
  276.                  }
  277.               W(event_mask) = S(event_mask);
  278. #ifdef DEBUG
  279.               dprintf(P)(stderr,"\n");
  280. #endif
  281.               break;
  282.          case P_CURSOR:        /* restore the cursor position */
  283.               W(x) = S(x);
  284.               W(y) = S(y);
  285.               W(gx) = S(gx);
  286.               W(gy) = S(gy);
  287.               W(curs_type) = S(curs_type);
  288.               break;
  289.          case P_BITMAP:        /* restore the bitmaps */
  290.               for(j=0;j<MAXBITMAPS;j++) {
  291.                  if (W(bitmaps)[j])
  292.                     bit_destroy(W(bitmaps)[j]);
  293.                  W(bitmaps)[j] = S(bitmaps)[j];
  294.                  S(bitmaps)[j] = (BITMAP *) 0;
  295.                  }
  296. #ifdef DEBUG
  297.               dprintf(P)(stderr,"  bitmaps\n");
  298. #endif
  299.               break;
  300.          case P_FONT:        /* restore font */
  301.               W(font) = S(font);
  302.               break;
  303.          case P_TEXT:        /* restore text region */
  304.               W(text) = S(text);
  305.               break;
  306.          case P_POSITION:    /* restore the window position */
  307.               if (win!= active)
  308.                  cursor_off();
  309.               ACTIVE_OFF();
  310.               expose(win);
  311.  
  312.               shape(S(x0),S(y0),S(esc)[1],S(esc)[2]);
  313.  
  314.               ACTIVE_ON();
  315. #ifdef DEBUG
  316.               dprintf(P)(stderr,"  position\n");
  317. #endif
  318.               break;
  319.          case P_WINDOW:        /* restore the window contents */
  320.               if (W(save))
  321.                  bit_destroy(W(save));
  322.               W(save) = bit_alloc(BIT_WIDE(W(border)),BIT_HIGH(W(border)),
  323.                                   NULL_DATA,DEPTH);
  324.               bit_blit(W(border),0,0,BIT_WIDE(S(save)),BIT_HIGH(S(save)),
  325.                        BIT_SRC,S(save),0,0);
  326. #ifdef DEBUG
  327.               dprintf(P)(stderr,"  window\n");
  328. #endif
  329.               break;
  330.          case P_FLAGS:        /* restore the window flags */
  331.               W(op) = S(op);
  332.               W(style) = S(style);
  333.               W(background) = S(background);
  334.               W(dup) = S(dup);
  335.               W(flags) = (S(flags)&W_SAVE) | (W(flags)&(~W_SAVE));
  336.               if (win == active)
  337.                  border(win,SUM_BDR-1,1);
  338.               else
  339.                  border(win,BLK_BDR,WH_BDR);
  340. #ifdef DEBUG
  341.               dprintf(P)(stderr,"  flags\n");
  342. #endif
  343.               break;
  344.          case P_MOUSE:        /* save mouse position */
  345. #ifdef DEBUG
  346.               dprintf(P)(stderr,"  mouse\n");
  347. #endif
  348.               mousex =S(esc)[3] ;
  349.               mousey =S(esc)[4] ;
  350.               break;
  351.          }
  352. #ifdef DEBUG
  353.    dprintf(P)(stderr,"%s\n",S(stack)?"another stack":"no environments stacked");
  354. #endif
  355.    W(stack) = S(stack);
  356.    unlink_win(stack,0);
  357.  
  358.    return(0);
  359.    }
  360.  
  361. /* in-implemented window stack manipulation */
  362.  
  363. win_swap(win,x,y)
  364. WINDOW *win;
  365. int x,y;        /* entries on stack to swap  1=1st stack entry */
  366.    {
  367.    register int i,j;
  368.    WINDOW *winx, *winy;
  369.    }
  370.