home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / Libraries / Window / c / Show < prev    next >
Encoding:
Text File  |  1993-05-11  |  3.7 KB  |  126 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Window.Show.c
  12.     Author:  Copyright © 1992 Jason Williams
  13.     Version: 1.00 (19 Mar 1992)
  14.     Purpose: High-level window management functions: Show a window
  15. */
  16.  
  17.  
  18. #include "WimpSWIs.h"
  19. #include "Window.h"
  20. #include "Screen.h"
  21.  
  22. static wimp_point lastopenpos = {-1, -1};
  23.  
  24.  
  25. extern void Window_Show(window_handle window, window_openpos openpos)
  26. {
  27.   window_state  wstate;
  28.   wimp_point    moveto = {0, 0};
  29.   int           w, h;
  30.  
  31.   Screen_CacheModeInfo();            /* Ensure got correct screen mode info. */
  32.  
  33.   Wimp_GetWindowState(window, &wstate);
  34.   wstate.openblock.behind = -1;                             /* open in front */
  35.  
  36.   w = wstate.openblock.screenrect.max.x - wstate.openblock.screenrect.min.x;
  37.   h = wstate.openblock.screenrect.max.y - wstate.openblock.screenrect.min.y;
  38.                                         
  39.   switch(openpos)
  40.   {
  41.     case open_CENTERED:
  42.       moveto.x = (screen_size.x - w) / 2;
  43.       moveto.y = (screen_size.y + h) / 2;
  44.       break;
  45.  
  46.     case open_OVERCARET:
  47.       {
  48.         caret_block  caret;
  49.         window_state wstate;
  50.  
  51.         Wimp_GetCaretPosition(&caret);
  52.  
  53.         if (caret.window > 0)
  54.         {
  55.           Wimp_GetWindowState(caret.window, &wstate);
  56.  
  57.           moveto.x = wstate.openblock.screenrect.min.x +
  58.                      (caret.offset.x - wstate.openblock.scroll.x) - 64;
  59.           moveto.y = wstate.openblock.screenrect.max.y -
  60.                      (caret.offset.y - wstate.openblock.scroll.y) + 64;
  61.         }
  62.         else
  63.         {
  64.           /* No caret, so just open centered on screen */
  65.           moveto.x = (screen_size.x - w) / 2;
  66.           moveto.y = (screen_size.y + h) / 2;
  67.         }
  68.       }
  69.       break;
  70.  
  71.     case open_UNDERPOINTER:
  72.       {
  73.         mouse_block ptr;
  74.  
  75.         Wimp_GetPointerInfo(&ptr);
  76.         moveto.x = ptr.pos.x - 64;
  77.         moveto.y = ptr.pos.y + 64;
  78.       }
  79.       break;
  80.  
  81.     case open_NEARLAST:
  82.       if (lastopenpos.x >= 0)
  83.       {
  84.         moveto.x = lastopenpos.x + 16;
  85.         moveto.y = lastopenpos.y - 16;
  86.       }
  87.       else
  88.       {
  89.         moveto.x = (screen_size.x - w) / 2;
  90.         moveto.y = (screen_size.y + h) / 2;
  91.       }
  92.       
  93.       if (moveto.x > ((screen_size.x / 2) + 128))
  94.         moveto.x = (screen_size.x / 2) - 128;
  95.  
  96.       if (moveto.y < ((screen_size.y / 2) - 128))
  97.         moveto.y = (screen_size.y / 2) + 128;
  98.       break;
  99.  
  100.     default:
  101.       /* Open wherever it is defined in the template file. */
  102.       moveto.x = wstate.openblock.screenrect.min.x;
  103.       moveto.y = wstate.openblock.screenrect.max.y;
  104.       break;
  105.   }
  106.  
  107.   if (moveto.x < 0)  moveto.x = 0;
  108.   if (moveto.y < 64) moveto.y = 64;
  109.   if (moveto.x > screen_size.x - 96) moveto.x = screen_size.x - 96;
  110.   if (moveto.y > screen_size.y - 32) moveto.y = screen_size.y - 32;
  111.  
  112.   wstate.openblock.screenrect.min.x = moveto.x;
  113.   wstate.openblock.screenrect.max.y = moveto.y;
  114.  
  115.   wstate.openblock.screenrect.max.x = wstate.openblock.screenrect.min.x + w;
  116.   wstate.openblock.screenrect.min.y = wstate.openblock.screenrect.max.y - h;
  117.  
  118.   if (openpos == open_NEARLAST)
  119.   {
  120.     lastopenpos.x = wstate.openblock.screenrect.min.x;  /* save last open pos*/
  121.     lastopenpos.y = wstate.openblock.screenrect.max.y;
  122.   }
  123.  
  124.   Wimp_OpenWindow(&wstate.openblock);
  125. }
  126.