home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !FALCON / NOCREW / MP2_0997.ZIP / mp2_0997 / src / window.c < prev    next >
C/C++ Source or Header  |  1998-11-08  |  4KB  |  188 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "window.h"
  5. #include "replay.h"
  6.  
  7. /* Function from mp2event.c */
  8. extern int quit_program(void);
  9. extern void update_time(void);
  10.  
  11. void window_create(int wind_id)
  12. {
  13.     WINDFORM *wind = &windforms[wind_id];
  14.  
  15.     wind->wind_id = wind_id;
  16.  
  17.     if(!wind->has_opened) {
  18.         form_center(wind->formtree,&wind->form.x,&wind->form.y,
  19.             &wind->form.w,&wind->form.h);
  20.         wind_calc(WC_BORDER,wind->windkind,wind->form.x,wind->form.y,
  21.             wind->form.w,wind->form.h,&wind->wind.x,&wind->wind.y,
  22.             &wind->wind.w,&wind->wind.h);
  23.  
  24.         wind->has_opened = 1;
  25.     }
  26.     
  27.     wind->whandle=wind_create(wind->windkind,wind->wind.x,wind->wind.y,
  28.         wind->wind.w,wind->wind.h);
  29.     wind_set(wind->whandle,WF_NAME,wind->wind_title);
  30.  
  31.     if(wind_id == WIND_CTRL)
  32.         wind_set(wind->whandle,WF_BEVENT,1,0,0,0); /* untoppable */
  33.     
  34.     wind_calc(WC_WORK,wind->windkind,wind->wind.x,wind->wind.y,
  35.         wind->wind.w,wind->wind.h,&wind->form.x,&wind->form.y,
  36.         &wind->form.w,&wind->form.h);
  37.     wind->formtree[wind->firstobj].ob_x=wind->form.x;
  38.     wind->formtree[wind->firstobj].ob_y=wind->form.y;
  39.     wind->formtree[wind->firstobj].ob_width=wind->form.w;
  40.     wind->formtree[wind->firstobj].ob_height=wind->form.h;
  41.  
  42.     add_windhandle(wind->whandle,wind->wind_id);
  43. }
  44.  
  45. void window_open(int wind_id)
  46. {
  47.     wind_open(windforms[wind_id].whandle,
  48.         windforms[wind_id].wind.x,windforms[wind_id].wind.y,
  49.         windforms[wind_id].wind.w,windforms[wind_id].wind.h);
  50.     windforms[wind_id].wind_open=1;
  51. }
  52.  
  53. int window_close(int wind_id)
  54. {
  55.     int whandle;
  56.     
  57.     /* Close topped window if wind_id < 0 */
  58.     if(wind_id < 0) {
  59.         wind_get(0, WF_TOP, &whandle);
  60.         wind_id = find_windform(whandle);
  61.         if(wind_id < 0)
  62.             return 0;
  63.     } else {
  64.         whandle = windforms[wind_id].whandle;
  65.     }
  66.  
  67.     if(!windforms[wind_id].wind_open)
  68.         return 0;
  69.     
  70.     wind_close(whandle);
  71.     wind_delete(whandle);
  72.     del_windhandle(whandle);
  73.     windforms[wind_id].wind_open=0;
  74.     if(wind_id == WIND_CTRL) {
  75.         window_close(WIND_INFO);
  76.         window_close(WIND_SHOE);
  77.         return quit_program();
  78.     }
  79.  
  80.     return 0;
  81. }
  82.  
  83. void window_switch()
  84. {
  85.     WINDHANDLELIST *wind=windhandles, *top;
  86.     int whandle, wind_id;
  87.  
  88.     wind_get(0, WF_TOP, &whandle);
  89.  
  90.     /* find handle of top window */
  91.     while(wind && wind->whandle != whandle)
  92.         wind = wind->next;
  93.     top = wind;
  94.     wind_id = top->wind_id;
  95.     
  96.     /* find handle of next open window */
  97.     if(top->next)
  98.         wind = top->next;
  99.     else
  100.         wind = windhandles;
  101.     while(wind != top && wind_id == top->wind_id) {
  102.         if(windforms[wind->wind_id].wind_open) {
  103.             wind_id = wind->wind_id;
  104.         }
  105.         if(wind->next)
  106.             wind = wind->next;
  107.         else
  108.             wind = windhandles;
  109.     }
  110.         
  111.     if(windforms[wind_id].wind_open)
  112.         wind_set(windforms[wind_id].whandle,WF_TOP);
  113. }
  114.  
  115. void window_move(int wind_id, int x, int y)
  116. {
  117.     WINDFORM *wind = &windforms[wind_id];
  118.  
  119.     if(!wind->has_opened) {
  120.         form_center(wind->formtree,&wind->form.x,&wind->form.y,
  121.             &wind->form.w,&wind->form.h);
  122.         wind_calc(WC_BORDER,wind->windkind,wind->form.x,wind->form.y,
  123.             wind->form.w,wind->form.h,&wind->wind.x,&wind->wind.y,
  124.             &wind->wind.w,&wind->wind.h);
  125.  
  126.         wind->has_opened = 1;
  127.     }
  128.  
  129.     if(wind->wind_open) {
  130.         wind_set(wind->whandle,WF_CURRXYWH,x,y,
  131.             wind->wind.w,wind->wind.h);
  132.     }
  133.     wind->wind.x=x;
  134.     wind->wind.y=y;
  135.     wind_calc(WC_WORK,wind->windkind,
  136.         wind->wind.x, wind->wind.y, wind->wind.w, wind->wind.h,
  137.         &wind->form.x, &wind->form.y, &wind->form.w, &wind->form.h);
  138.     wind->formtree[wind->firstobj].ob_x=wind->form.x;
  139.     wind->formtree[wind->firstobj].ob_y=wind->form.y;
  140.     wind->formtree[wind->firstobj].ob_width=wind->form.w;
  141.     wind->formtree[wind->firstobj].ob_height=wind->form.h;
  142.     if(replayp())
  143.         update_time();
  144. }
  145.  
  146. void add_windhandle(int whandle, int wind_id)
  147. {
  148.     WINDHANDLELIST *new;
  149.     
  150.     new = (WINDHANDLELIST *)malloc(sizeof(WINDHANDLELIST));
  151.     new->next = windhandles;
  152.     new->whandle = whandle;
  153.     new->wind_id = wind_id;
  154.     windhandles = new;
  155. }
  156.  
  157. void del_windhandle(int whandle)
  158. {
  159.     WINDHANDLELIST *wind = windhandles, *last=NULL;
  160.     
  161.     while(wind) {
  162.         if(wind->whandle == whandle) {
  163.             if(last)
  164.                 last->next = wind->next;
  165.             else
  166.                 windhandles = wind->next;
  167.             free(wind);
  168.             break;
  169.         }
  170.         last = wind;
  171.         wind = wind->next;
  172.     }
  173. }
  174.  
  175. int find_windform(int whandle)
  176. {
  177.     WINDHANDLELIST *wind = windhandles;
  178.  
  179.     while(wind) {
  180.         if(wind->whandle == whandle) {
  181.             return wind->wind_id;
  182.         }
  183.         wind = wind->next;
  184.     }
  185.  
  186.     return -1;
  187. }
  188.