windows.c
Go to the documentation of this file.00001 #include <curses.h>
00002 #include <stddef.h>
00003 #include <stdlib.h>
00004 #include "mucurses.h"
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 int delwin ( WINDOW *win ) {
00019 if ( win == NULL )
00020 return ERR;
00021
00022
00023
00024
00025
00026 wmove( win, 0, 0 );
00027 chtype killch = (chtype)' ';
00028 do {
00029 _wputch( win, killch, WRAP );
00030 } while ( win->curs_x + win->curs_y );
00031
00032 free( win );
00033
00034 wmove ( stdscr, 0, 0 );
00035
00036 return OK;
00037 }
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 WINDOW *derwin ( WINDOW *parent, int nlines, int ncols,
00050 int begin_y, int begin_x ) {
00051 WINDOW *child;
00052 if ( parent == NULL )
00053 return NULL;
00054 if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
00055 return NULL;
00056 if ( ( (unsigned)ncols > parent->width ) ||
00057 ( (unsigned)nlines > parent->height ) )
00058 return NULL;
00059 child->ori_y = parent->ori_y + begin_y;
00060 child->ori_x = parent->ori_x + begin_x;
00061 child->height = nlines;
00062 child->width = ncols;
00063 child->parent = parent;
00064 child->scr = parent->scr;
00065 return child;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 WINDOW *dupwin ( WINDOW *orig ) {
00075 WINDOW *copy;
00076 if ( orig == NULL )
00077 return NULL;
00078 if ( ( copy = malloc( sizeof( WINDOW ) ) ) == NULL )
00079 return NULL;
00080 copy->scr = orig->scr;
00081 copy->attrs = orig->attrs;
00082 copy->ori_y = orig->ori_y;
00083 copy->ori_x = orig->ori_x;
00084 copy->curs_y = orig->curs_y;
00085 copy->curs_x = orig->curs_x;
00086 copy->height = orig->height;
00087 copy->width = orig->width;
00088 return copy;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 int mvwin ( WINDOW *win, int y, int x ) {
00100 if ( win == NULL )
00101 return ERR;
00102 if ( ( ( (unsigned)y + win->height ) > LINES ) ||
00103 ( ( (unsigned)x + win->width ) > COLS ) )
00104 return ERR;
00105
00106 win->ori_y = y;
00107 win->ori_x = x;
00108
00109 return OK;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
00122 WINDOW *win;
00123 if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
00124 return NULL;
00125 if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
00126 ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
00127 return NULL;
00128 win->ori_y = begin_y;
00129 win->ori_x = begin_x;
00130 win->height = nlines;
00131 win->width = ncols;
00132 win->scr = stdscr->scr;
00133 win->parent = stdscr;
00134 return win;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 WINDOW *subwin ( WINDOW *parent, int nlines, int ncols,
00148 int begin_y, int begin_x ) {
00149 WINDOW *child;
00150 if ( parent == NULL )
00151 return NULL;
00152 if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
00153 return NULL;
00154 child = newwin( nlines, ncols, begin_y, begin_x );
00155 child->parent = parent;
00156 child->scr = parent->scr;
00157 return child;
00158 }