home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / c / curses / src / _creatwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-30  |  4.3 KB  |  143 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : _creatwin.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
  7.  *
  8.  * Date     : Friday 23rd August 1991.
  9.  *
  10.  * Desc     : Creats a new window, which may or may not be a sub window.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1991, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is provided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectivly.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log:    _creatwin.c,v $
  41.  * Revision 1.6  92/06/10  23:45:07  sie
  42.  * Added serial support.
  43.  * 
  44.  * Revision 1.5  91/12/30  10:30:22  sie
  45.  * Removed LRLine and LRATTRS.
  46.  * The speed increase caused by them was too insignificant.
  47.  * 
  48.  * Revision 1.4  91/12/28  22:46:13  sie
  49.  * changed attrs to UBYTE from short + some tidying up.
  50.  * 
  51.  * Revision 1.3  91/12/28  14:01:54  sie
  52.  * Removed WinStat.
  53.  * Renamed LineElement as lnel.
  54.  * 
  55.  * Revision 1.2  91/12/26  14:40:31  sie
  56.  * removed use of Next and Prev in WinStat as linked list is no longer
  57.  * relevant.
  58.  * 
  59.  * Revision 1.1  91/09/07  11:52:46  sie
  60.  * Initial revision
  61.  * 
  62.  *
  63.  */
  64.  
  65. static char *rcsid = "$Header: SRC:lib/curses/src/RCS/_creatwin.c,v 1.6 92/06/10 23:45:07 sie Exp $";
  66.  
  67. #include <stdlib.h>
  68. #include "acurses.h"
  69.  
  70.  
  71. /* Orig is NULL and StartCol/Line are not used for newwin() calls */
  72. WINDOW *CreatWindow(int NLines, int NCols, int StartLine, int StartCol, WINDOW *Orig)
  73. {
  74.   int Line;
  75.   WINDOW *NewWinPtr;
  76.   
  77.   /* If either are zero then make them max */
  78.   if(!NLines)
  79.     NLines = LINES - StartLine;
  80.   if(!NCols)
  81.     NCols = COLS - StartCol;
  82.   
  83.   if(NLines>LINES || NCols>COLS || StartLine>LINES || StartCol>COLS)
  84.     return NULL;
  85.   
  86.   if(StartLine < 0)
  87.     StartLine = 0;
  88.   if(StartCol < 0)
  89.     StartCol = 0;
  90.   
  91.   /* Create a new WINDOW structure */
  92.   if(!(NewWinPtr=(WINDOW *)malloc(sizeof(WINDOW)))) {
  93.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  94.     return NULL;
  95.   }
  96.   NewWinPtr->ParentWin = Orig;
  97.   NewWinPtr->ScrollTop = 0;
  98.   NewWinPtr->ScrollBot = NLines - 1;
  99.   NewWinPtr->NLines = NLines;
  100.   /* Allocate space for LnArry[] */
  101.   if(!(NewWinPtr->LnArry = (struct lnel *)malloc(sizeof(struct lnel)*NLines))) {
  102.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  103.     return NULL;
  104.   }
  105.   /* Allocate space for Line and ATTRS */
  106.   for(Line = 0; Line < NLines; Line++) {
  107.     if(Orig) {  /* If this is a subwindow */
  108.       /* Set up pointers into parent window */
  109.       NewWinPtr->LnArry[Line].Line =
  110.     &Orig->LnArry[Line+StartLine].Line[StartCol];
  111.       NewWinPtr->LnArry[Line].ATTRS =
  112.     &Orig->LnArry[Line+StartLine].ATTRS[StartCol];
  113.     } else {  /* New window, allocate space for lines */
  114.       /* malloc lines and ATTRS */
  115.       if((NewWinPtr->LnArry[Line].Line = malloc(NCols)) == NULL) {
  116.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  117.     return (WINDOW *)NULL;
  118.       }
  119.       if((NewWinPtr->LnArry[Line].ATTRS = (UBYTE *)malloc(NCols)) == NULL) {
  120.     fprintf(stderr, "CreatWindow() - Not enough memory\n");
  121.     return (WINDOW *)NULL;
  122.       }
  123.     }
  124.     NewWinPtr->LnArry[Line].Touched = FALSE;
  125.     NewWinPtr->LnArry[Line].StartCol = NCols;
  126.     NewWinPtr->LnArry[Line].EndCol = 0;
  127.   }
  128.   /* Initialise rest of the window structure */
  129.   NewWinPtr->_cury = 0;
  130.   NewWinPtr->_curx = 0;
  131.   NewWinPtr->_maxy = NLines - 1;
  132.   NewWinPtr->_maxx = NCols - 1;
  133.   NewWinPtr->_begy = StartLine;
  134.   NewWinPtr->_begx = StartCol;
  135.   NewWinPtr->_flags = 0;
  136.   NewWinPtr->_attrs = A_NORMAL | COLOR_WHITE;
  137.   NewWinPtr->_clear = FALSE;
  138.   NewWinPtr->_scroll = FALSE;
  139.   NewWinPtr->_nodelay = 0;
  140.   
  141.   return NewWinPtr;
  142. }
  143.