Category : C Source Code
Archive   : TC15WIND.ZIP
Filename : WINDOWS.C

 
Output of file : WINDOWS.C contained in archive : TC15WIND.ZIP
/*===============================================================*\
* *
* W W IIII N N DDDDD OOO W W SSS *
* W W II NN N D D O O W W S S *
* W W II N N N D D O O W W S *
* W W II N N N D D O O W W S *
* W W W II N N N D D O O W W W S *
* W W W W II N N N D D O O W W W W S *
* W W W W II N NN D D O O W W W W S S *
* WW WW IIII N N DDDDD OOO WW WW SSS *
* *
\*===============================================================*/

#define IN_WINDOWS_C
#include
#include
#include
#include "windows.h"

/**********************************************************************\
* *
* Box equates -- Upper Left, Upper Right, Lower Right, Lower Left, *
* Horrizontal, Vertical *
* *
\**********************************************************************/
static BYTE SINGLE[6] = { 218, 191, 217, 192, 196, 179 };
static BYTE DOUBLE[6] = { 201, 187, 188, 200, 205, 186 };
static BYTE * boxes;
#define UL 0
#define UR 1
#define LR 2
#define LL 3
#define H 4
#define V 5

/*********************************************\
* *
* Pointer to window on top of the screen. *
* *
\*********************************************/
static struct window_info * WINDOW_TOP = NULL;

/*======================================================================*\
* *
* C R E A T E W I N D O W *
* -------------------------- *
* *
* Create a boardered window which will be active on top of the *
* screen. This window will have its own ID so once another *
* window covers it, the window may be reestablished on top of *
* screen. This routine will not create two windows with the *
* same ID. *
* *
\*======================================================================*/
int create_window ( char * id,
BYTE winleft,
BYTE wintop,
BYTE winright,
BYTE winbottom,
BYTE window_foreground,
BYTE window_background,
BOX boarder,
BYTE boarder_foreground,
BYTE boarder_background )
{
struct window_info * windptr;
BYTE dx, dy, k;

/*----------------------------------------------------------------------
First we must check if there already exists a window with this ID.
----------------------------------------------------------------------*/
windptr = WINDOW_TOP;
while (windptr != NULL) {
if (strcmp(id, windptr->id) == 0) return (WINDOW_ALREADY_EXISTS);
windptr = windptr->under;
}

/*--------------------------------------------------------
Allocate space for this window's information record.
--------------------------------------------------------*/
windptr = (struct window_info *) malloc (sizeof(struct window_info));
if (windptr == NULL) return (WINDOW_CANT_ALLOCATE);

/*-----------------------------------------------------------------
Set up window pointers and if this window is going to overlay
another, save that window's cover information (text currently
written in the window).
-----------------------------------------------------------------*/
windptr->under = WINDOW_TOP;
windptr->over = NULL;
gettextinfo (&windptr->last);
if (WINDOW_TOP != NULL) {
WINDOW_TOP->over = windptr;
dx = WINDOW_TOP->winright - WINDOW_TOP->winleft + 1;
dy = WINDOW_TOP->winbottom - WINDOW_TOP->wintop + 1;
if (WINDOW_TOP->cover != NULL) free (WINDOW_TOP->cover);
WINDOW_TOP->cover = (BYTE *) malloc (2*dx*dy);
if (WINDOW_TOP->cover == NULL) return (WINDOW_CANT_ALLOCATE);
gettext (WINDOW_TOP->winleft, WINDOW_TOP->wintop,
WINDOW_TOP->winright, WINDOW_TOP->winbottom,
WINDOW_TOP->cover);
WINDOW_TOP->curx = windptr->last.curx;
WINDOW_TOP->cury = windptr->last.cury;
}

/*-----------------------------------------------------------------
Fill in the rest of the window record with the passed values.
-----------------------------------------------------------------*/
windptr->id = id;
windptr->winleft = winleft;
windptr->wintop = wintop;
windptr->winright = winright;
windptr->winbottom = winbottom;
windptr->window_foreground = window_foreground;
windptr->window_background = window_background;
windptr->boarder = boarder;
windptr->boarder_foreground = boarder_foreground;
windptr->boarder_background = boarder_background;
windptr->cover = NULL;
windptr->curx = 1;
windptr->cury = 1;

/*----------------------------------------------------------
Save the text which will be covered by current window.
----------------------------------------------------------*/
dx = winright - winleft + 1;
dy = winbottom - wintop + 1;
windptr->covered = (BYTE *) malloc (2*dx*dy);
if (windptr->covered == NULL) return (WINDOW_CANT_ALLOCATE);
gettext (winleft, wintop, winright, winbottom, windptr->covered);

/*-----------------------------------------
Make this window the top of the list.
-----------------------------------------*/
WINDOW_TOP = windptr;

/*----------------------------------------------------------------
The passed dimensions describe the position of the boarder
window. The actural window is one unit smaller in both
directions. The boarder window is cleared with the boarder
background and if the boarder is boxed, the correct style is
applied in the boarder foreground.
----------------------------------------------------------------*/
window (winleft, wintop, winright, winbottom);
textcolor (boarder_foreground);
textbackground (boarder_background);
clrscr ();
switch (boarder) {
case SINGLE_LINE : boxes = SINGLE; break;
case DOUBLE_LINE : boxes = DOUBLE; break;
default : boxes = NULL;
}
if (boxes != NULL) {
putch (boxes [LL]);
for (k = 2; k < dx; k++) putch (boxes [H]);
putch (boxes [LR]);
movetext (winleft, wintop, winright, wintop, winleft, winbottom);
gotoxy (1, 1); putch (boxes [UL]);
gotoxy (dx, 1); putch (boxes [UR]);
putch (boxes [V]);
for (k = 2; k < (dy-1); k++) {
gotoxy (dx, k);
putch (boxes [V]);
putch (boxes [V]);
}
gotoxy (dx, dy-1);
putch (boxes [V]);
}

/*------------------------------------------------------------------
Open actural window as one unit inside the boarder, i.e. there
exists a single line of boarder around the window.
------------------------------------------------------------------*/
window (winleft + 1, wintop + 1, winright - 1, winbottom - 1);
textcolor (window_foreground);
textbackground (window_background);
clrscr ();

/*----------------------------------------------------------------
Everything went just fine if we made it here so report A.O.K
----------------------------------------------------------------*/
return (WINDOW_OK);

}


/*=============================================================*\
* *
* A C T I V A T E W I N D O W *
* ----------------------------- *
* *
* Search through the window list looking for a window *
* with same ID. If the window is found it is moved to *
* the top of the list (top of screen). *
* *
\*=============================================================*/
int activate_window ( char * id )
{
struct window_info * named, * windptr;
BYTE found = 0, dx, dy;
unsigned count = 0, k;

/*---------------------------------
Try to locate window with ID.
---------------------------------*/
windptr = WINDOW_TOP;
while (windptr != NULL) {
if (strcmp (id, windptr->id) == 0) {
found = 1;
break;
}
else
found = 0;
count++;
windptr = windptr->under;
}
if (!found) return (WINDOW_DOES_NOT_EXIST);
if (count == 0) return (WINDOW_OK);
named = windptr;

/*------------------------------------------------
Save the contents of the current top window.
------------------------------------------------*/
dx = WINDOW_TOP->winright - WINDOW_TOP->winleft + 1;
dy = WINDOW_TOP->winbottom - WINDOW_TOP->wintop + 1;
if (WINDOW_TOP->cover != NULL) free (WINDOW_TOP->cover);
WINDOW_TOP->cover = (BYTE *) malloc (2*dx*dy);
if (WINDOW_TOP->cover == NULL) return (WINDOW_CANT_ALLOCATE);
gettext (WINDOW_TOP->winleft, WINDOW_TOP->wintop, WINDOW_TOP->winright,
WINDOW_TOP->winbottom, WINDOW_TOP->cover);
WINDOW_TOP->curx = wherex ();
WINDOW_TOP->cury = wherey ();

/*------------------------------------------------------------
Replace what the windows cover from the top window down.
------------------------------------------------------------*/
windptr = WINDOW_TOP;
for (k = 1; k <= count + 1; k++) {
puttext (windptr->winleft, windptr->wintop, windptr->winright,
windptr->winbottom, windptr->covered);
free (windptr->covered);
windptr = windptr->under;
}

/*-------------------------------------------------------------
Set up the window which existed under the matched window.
-------------------------------------------------------------*/
window (named->last.winleft, named->last.wintop, named->last.winright,
named->last.winbottom);
textattr (named->last.attribute);
gotoxy (named->last.curx, named->last.cury);

/*------------------------------------------------
Re-route pointers around the matched window.
------------------------------------------------*/
named->over->under = named->under;
if (named->under != NULL) named->under->over = named->over;
windptr = named->over;

/*-------------------------------------------------
Replace above windows in bottom to top order.
-------------------------------------------------*/
for (k = 1; k <= count; k++) {
gettextinfo (&windptr->last);
dx = windptr->winright - windptr->winleft + 1;
dy = windptr->winbottom - windptr->wintop + 1;
windptr->covered = (BYTE *) malloc (2*dx*dy);
gettext (windptr->winleft, windptr->wintop, windptr->winright,
windptr->winbottom, windptr->covered);
puttext (windptr->winleft, windptr->wintop, windptr->winright,
windptr->winbottom, windptr->cover);
window (windptr->winleft + 1, windptr->wintop + 1,
windptr->winright - 1, windptr->winbottom - 1);
textcolor (windptr->window_foreground);
textbackground (windptr->window_background);
gotoxy (windptr->curx, windptr->cury);
windptr = windptr->over;
}

/*----------------------------------------------------------
Replace the named window as active on top of the list.
----------------------------------------------------------*/
gettextinfo (&named->last);
dx = named->winright - named->winleft + 1;
dy = named->winbottom - named->wintop + 1;
named->covered = (BYTE *) malloc (2*dx*dy);
gettext (named->winleft, named->wintop, named->winright,
named->winbottom, named->covered);
puttext (named->winleft, named->wintop, named->winright,
named->winbottom, named->cover);
window (named->winleft + 1, named->wintop + 1,
named->winright - 1, named->winbottom - 1);
textcolor (named->window_foreground);
textbackground (named->window_background);
gotoxy (named->curx, named->cury);

/*---------------------------
Adjust window pointers.
---------------------------*/
WINDOW_TOP->over = named;
named->under = WINDOW_TOP;
named->over = NULL;
WINDOW_TOP = named;

/*----------------------------------------------------------------
Everything went just fine if we made it here so report A.O.K
----------------------------------------------------------------*/
return (WINDOW_OK);

}


/*==============================================================*\
* *
* R E M O V E W I N D O W *
* ------------------------- *
* *
* Remove a named window from the window list. If the *
* ID is "KILL_ALL_WINDOWS" then the list is removed in *
* top down order. Otherwise an attemp is made to *
* activate the named window and then remove it from the *
* top. *
* *
\*==============================================================*/
int remove_window ( char * id )
{
struct window_info * windptr;

if (strcmp (id, "KILL_ALL_WINDOWS") == 0) {
windptr = WINDOW_TOP;
while (windptr != NULL) {
puttext (windptr->winleft, windptr->wintop, windptr->winright,
windptr->winbottom, windptr->covered);
free (windptr->covered);
free (windptr->cover);
window (windptr->last.winleft, windptr->last.wintop,
windptr->last.winright, windptr->last.winbottom);
textattr (windptr->last.attribute);
gotoxy (windptr->last.curx, windptr->last.cury);
WINDOW_TOP = windptr->under;
free (windptr);
windptr = WINDOW_TOP;
}
return (WINDOW_OK);
}

else
if (activate_window (id) == WINDOW_OK) {
windptr = WINDOW_TOP;
puttext (windptr->winleft, windptr->wintop, windptr->winright,
windptr->winbottom, windptr->covered);
free (windptr->covered);
free (windptr->cover);
window (windptr->last.winleft, windptr->last.wintop,
windptr->last.winright, windptr->last.winbottom);
textattr (windptr->last.attribute);
gotoxy (windptr->last.curx, windptr->last.cury);
WINDOW_TOP = windptr->under;
free (windptr);
return (WINDOW_OK);
}
else
return (WINDOW_DOES_NOT_EXIST);

}


  3 Responses to “Category : C Source Code
Archive   : TC15WIND.ZIP
Filename : WINDOWS.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/