[GB.NCURSES]

* NEW: Created gb.ncurses component
* NEW: Added NCurses static class
* NEW: Added Window class



git-svn-id: svn://localhost/gambas/trunk@4621 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Tobias Boege 2012-04-13 15:16:23 +00:00
parent a04d1a9113
commit 572d7aa9e4
26 changed files with 1848 additions and 0 deletions

View file

@ -1,5 +1,6 @@
SUBDIRS = \
main \
@ncurses_dir@ \
@bzlib2_dir@ \
@zlib_dir@ \
@mysql_dir@ \

View file

@ -9,6 +9,7 @@ AC_INIT(configure.ac)
AC_CONFIG_SUBDIRS(main)
GB_CONFIG_SUBDIRS(ncurses, gb.ncurses)
GB_CONFIG_SUBDIRS(bzlib2, gb.compress.bzlib2)
GB_CONFIG_SUBDIRS(zlib, gb.compress.zlib)
GB_CONFIG_SUBDIRS(mysql, gb.db.mysql)

0
gb.ncurses/AUTHORS Normal file
View file

1
gb.ncurses/COPYING Symbolic link
View file

@ -0,0 +1 @@
../COPYING

0
gb.ncurses/ChangeLog Normal file
View file

1
gb.ncurses/INSTALL Symbolic link
View file

@ -0,0 +1 @@
../INSTALL

3
gb.ncurses/Makefile.am Normal file
View file

@ -0,0 +1,3 @@
ACLOCAL_AMFLAGS = -I m4 --install
SUBDIRS = @NCURSES_DIR@
EXTRA_DIST = reconf spec gambas.h gb*.h

0
gb.ncurses/NEWS Normal file
View file

0
gb.ncurses/README Normal file
View file

1
gb.ncurses/acinclude.m4 Symbolic link
View file

@ -0,0 +1 @@
../acinclude.m4

1
gb.ncurses/component.am Symbolic link
View file

@ -0,0 +1 @@
../component.am

22
gb.ncurses/configure.ac Normal file
View file

@ -0,0 +1,22 @@
dnl ---- configure.ac for gb.ncurses
AC_INIT(configure.ac)
AC_CONFIG_MACRO_DIR([m4])
GB_INIT(gb.ncurses)
AC_PROG_LIBTOOL
GB_COMPONENT(
ncurses,
NCURSES,
[NCURSES component],
[src],
[GB_FIND(ncurses.h panel.h, /usr/lib /usr, include)],
[GB_FIND(libncurses.$SHLIBEXT libpanel.$SHLIBEXT, /usr/local /usr, lib)],
[-lpanel -lncurses])
AC_OUTPUT( \
Makefile \
src/Makefile \
)
GB_PRINT_MESSAGES

1
gb.ncurses/depcomp Symbolic link
View file

@ -0,0 +1 @@
../depcomp

1
gb.ncurses/gambas.h Symbolic link
View file

@ -0,0 +1 @@
../main/share/gambas.h

1
gb.ncurses/gb_common.h Symbolic link
View file

@ -0,0 +1 @@
../main/share/gb_common.h

1
gb.ncurses/m4 Symbolic link
View file

@ -0,0 +1 @@
../m4

1
gb.ncurses/missing Symbolic link
View file

@ -0,0 +1 @@
../missing

1
gb.ncurses/reconf Symbolic link
View file

@ -0,0 +1 @@
../reconf

View file

@ -0,0 +1,15 @@
COMPONENT = gb.ncurses
include $(top_srcdir)/component.am
INCLUDES = @NCURSES_INC@
gblib_LTLIBRARIES = gb.ncurses.la
gb_ncurses_la_LIBADD = @NCURSES_LIB@
gb_ncurses_la_LDFLAGS = -module @LD_FLAGS@ @NCURSES_LDFLAGS@
gb_ncurses_la_SOURCES = \
main.h main.c \
c_ncurses.h c_ncurses.c \
c_window.h c_window.c

212
gb.ncurses/src/c_ncurses.c Normal file
View file

@ -0,0 +1,212 @@
/*
* c_ncurses.c - gb.ncurses NCurses static class
*
* Copyright (C) 2012 Tobias Boege <tobias@gambas-buch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#define __C_NCURSES_C
#include <stdio.h>
#include <signal.h>
#include <ncurses.h>
#include "c_ncurses.h"
#include "main.h"
#define E_END "Could not end ncurses"
#define E_UNSUPP "Unsupported value"
#define CURSOR_HIDDEN 0
#define CURSOR_VISIBLE 1
#define INPUT_COOKED 0
#define INPUT_CBREAK 1
#define INPUT_RAW 2
static bool nc_cursor;
static int nc_input;
static int nc_echo;
DECLARE_EVENT(EVENT_Resize);
/*
* Signal handler for the SIGWINCH signal.
* @signum: signal number given
* This routine dispatches the Resize Event
*/
void nc_sigwinch_handler(int signum)
{
/* TODO: I wonder if this works... */
if (signum == SIGWINCH) GB.Raise(NULL, EVENT_Resize, 0);
}
BEGIN_PROPERTY(CNCurses_cursor)
if (READ_PROPERTY)
{
GB.ReturnInteger(nc_cursor);
return;
}
/* Hide if setting cursor is not supported */
switch (VPROP(GB_INTEGER))
{
case CURSOR_HIDDEN:
curs_set(0);
break;
case CURSOR_VISIBLE:
curs_set(1);
break;
default:
GB.Error(E_UNSUPP);
return;
}
nc_cursor = VPROP(GB_INTEGER);
END_PROPERTY
BEGIN_PROPERTY(CNCurses_input)
if (READ_PROPERTY)
{
GB.ReturnInteger(nc_input);
return;
}
switch (VPROP(GB_INTEGER))
{
case INPUT_COOKED:
noraw();
nocbreak();
break;
case INPUT_CBREAK:
cbreak();
break;
case INPUT_RAW:
raw();
break;
default:
GB.Error(E_UNSUPP);
return;
}
nc_input = VPROP(GB_INTEGER);
END_PROPERTY
BEGIN_PROPERTY(CNCurses_echo)
if (READ_PROPERTY)
{
GB.ReturnBoolean(nc_echo);
return;
}
nc_echo = VPROP(GB_BOOLEAN);
if (nc_echo) echo();
else noecho();
END_PROPERTY
BEGIN_PROPERTY(CNCurses_lines)
GB.ReturnInteger(LINES);
END_PROPERTY
BEGIN_PROPERTY(CNCurses_cols)
GB.ReturnInteger(COLS);
END_PROPERTY
BEGIN_METHOD_VOID(CNCurses_init)
struct sigaction sa;
initscr();
/* global variable default setup */
nc_cursor = CURSOR_VISIBLE;
nc_input = INPUT_CBREAK;
nc_echo = 0;
/* accordingly... */
curs_set(1);
cbreak();
noecho();
sa.sa_handler = nc_sigwinch_handler;
sigemptyset(&(sa.sa_mask));
sa.sa_flags = 0;
if (sigaction(SIGWINCH, &sa, NULL) == -1)
{
fprintf(stderr, "gb.ncurses: Could not install SIGWINCH signal handler");
}
refresh();
END_METHOD
DECLARE_METHOD(CNCurses_off);
BEGIN_METHOD_VOID(CNCurses_exit)
CALL_METHOD_VOID(CNCurses_off);
END_METHOD
BEGIN_METHOD_VOID(CNCurses_on)
if (NCURSES_RUNNING) return;
refresh();
END_METHOD
BEGIN_METHOD_VOID(CNCurses_off)
if (!NCURSES_RUNNING) return;
if (endwin() == ERR) GB.Error(E_END);
END_METHOD
GB_DESC CNCursesDesc[] =
{
GB_DECLARE("NCurses", 0),
GB_NOT_CREATABLE(),
GB_CONSTANT("Hidden", "i", CURSOR_HIDDEN),
GB_CONSTANT("Visible", "i", CURSOR_VISIBLE),
GB_CONSTANT("Cooked", "i", INPUT_COOKED),
GB_CONSTANT("CBreak", "i", INPUT_CBREAK),
GB_CONSTANT("Raw", "i", INPUT_RAW),
GB_STATIC_PROPERTY("Cursor", "i", CNCurses_cursor),
GB_STATIC_PROPERTY("Input", "i", CNCurses_input),
GB_STATIC_PROPERTY("Echo", "b", CNCurses_echo),
GB_STATIC_PROPERTY_READ("Lines", "i", CNCurses_lines),
GB_STATIC_PROPERTY_READ("Cols", "i", CNCurses_cols),
GB_STATIC_METHOD("_init", NULL, CNCurses_init, NULL),
GB_STATIC_METHOD("_exit", NULL, CNCurses_exit, NULL),
GB_STATIC_METHOD("On", NULL, CNCurses_on, NULL),
GB_STATIC_METHOD("Off", NULL, CNCurses_off, NULL),
GB_END_DECLARE
};

View file

@ -0,0 +1,36 @@
/*
* c_ncurses.h - gb.ncurses NCurses static class
*
* Copyright (C) 2012 Tobias Boege <tobias@gambas-buch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef __C_NCURSES_H
#define __C_NCURSES_H
#include <ncurses.h>
#include "gambas.h"
#include "gb_common.h"
#define NCURSES_RUNNING (!isendwin() || stdscr)
#ifndef __C_NCURSES_C
extern GB_DESC CNCursesDesc[];
#endif
#endif /* __C_NCURSES_H */

1322
gb.ncurses/src/c_window.c Normal file

File diff suppressed because it is too large Load diff

139
gb.ncurses/src/c_window.h Normal file
View file

@ -0,0 +1,139 @@
/*
* c_window.h - gb.ncurses Window class
*
* Copyright (C) 2012 Tobias Boege <tobias@gambas-buch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef __C_WINDOW_H
#define __C_WINDOW_H
#include <ncurses.h>
#include <panel.h>
#include "gambas.h"
#include "gb_common.h"
#include "c_ncurses.h"
#define THIS ((struct nc_window *) _object)
#define HAS_BORDER (THIS->border)
#define IS_WRAPPED (THIS->wrap)
/* This will produce final output on terminal screen, shall be called only by Gambas functions
as they assemble all changes for a single functionality and may then output once. */
#define REFRESH() { \
update_panels(); \
doupdate(); \
}
/* Translate linear (absolute) memory addresses and x,y coordinates into each other
most useful when wrapping is needed. */
#define A2XY(win, a, x, y) { \
(x) = (a) % getmaxx(win); \
(y) = (a) / getmaxx(win); \
}
#define XY2A(win, x, y, a) { \
(a) = (y) * getmaxx(win) + (x); \
}
/* Interpret the -1 values in coordinates as to insert the current cursor position */
#define MAKE_COORDS(win, x, y) { \
if ((x) == -1) x = getcurx(win); \
if ((y) == -1) y = getcury(win); \
}
/* Check for out-of-range coordinates */
#define BAD_COORDS(win, x, y) ((x) < 0 || (x) >= getmaxx(win) || \
(y) < 0 || (y) >= getmaxy(win))
#define BAD_DIMENSION(w, h) ((w) <= 0 || (w) > COLS || \
(h) <= 0 || (h) > LINES)
/* @reqs for *_attrs_driver() */
enum
{
/* Return current attributes */
ATTR_DRV_RET,
/* Enable given attributes */
ATTR_DRV_ON,
/* Disable given attributes */
ATTR_DRV_OFF
};
#define WIN_ATTR_METHOD(b, a) { \
if (READ_PROPERTY) \
GB.ReturnBoolean(nc_window_attrs_driver( \
THIS, (a), ATTR_DRV_RET) \
& (a)); \
else nc_window_attrs_driver( \
THIS, (a), (b) ? ATTR_DRV_ON : ATTR_DRV_OFF); \
}
#define WIN_ATTR_METHOD_BOOL(a) WIN_ATTR_METHOD(VPROP(GB_BOOLEAN), a);
#define WIN_ATTR_METHOD_INT(a) WIN_ATTR_METHOD(1, a);
/* Notice the wtouchln() line in the following macro. It seems that a chgat() from
nc_window_char_attrs_driver() doesn't mark anything dirty (no output on screen from
a REFRESH()). So to make the new attribute available immidiately, we touch the affected
line manually. A higher-callstack function may call REFRESH() to get output. */
#define CHAR_ATTR_METHOD(b, a) { \
if (READ_PROPERTY) \
GB.ReturnBoolean(nc_window_char_attrs_driver( \
THIS, (a), THIS->pos.col, THIS->pos.line, \
ATTR_DRV_RET) & (a)); \
else nc_window_char_attrs_driver( \
THIS, (a), THIS->pos.col, THIS->pos.line, \
(b) ? ATTR_DRV_ON : ATTR_DRV_OFF); \
wtouchln(THIS->main, THIS->pos.line + (HAS_BORDER ? 1 : 0), 1, 1); \
}
#define CHAR_ATTR_METHOD_BOOL(a) CHAR_ATTR_METHOD(VPROP(GB_BOOLEAN), a);
#define CHAR_ATTR_METHOD_INT(a) CHAR_ATTR_METHOD(1, a);
//TODO: [x] chgat on line and character basis
// [-] Stream
// [-] Timer
// [-] Color
struct nc_window
{
GB_BASE ob;
GB_STREAM stream; /* Gambas stream structure to enable Print #Window, Expr and other stream-related
syntaxes */
WINDOW *main; /* The main window. */
WINDOW *content; /* This window is used for all content-related operations. Its purpose is turning
the ncurses window borders which are inner-window to outer-window ones thus
separating border from content. If there is no border, this is the same as @main
otherwise a subwindow of it. */
PANEL *pan; /* Panel of the main window to provide overlapping windows */
bool border; /* Whether there is a border */
bool wrap; /* Whether text shall be truncated or wrapped on line ends */
struct /* This structure is used to pass a line and a column number to virtual objects */
{
int line;
int col;
} pos;
};
#ifndef __C_WINDOW_C
extern GB_DESC CWindowDesc[];
extern GB_DESC CWindowAttrsDesc[];
extern GB_DESC CCharAttrsDesc[];
#endif
#define nc_window_main_to_content() (nc_window_copy_window(THIS->main, THIS->content, 0, 0, \
getmaxx(THIS->content), \
getmaxy(THIS->content), 0, 0))
#define nc_window_content_to_main() (nc_window_copy_window(THIS->content, THIS->main, 0, 0, \
getmaxx(THIS->content), \
getmaxy(THIS->content), 0, 0))
#endif /* __C_WINDOW_C */

View file

@ -0,0 +1,5 @@
[Component]
Key=gb.ncurses
Name=NCURSES component
Author=Tobias Boege

49
gb.ncurses/src/main.c Normal file
View file

@ -0,0 +1,49 @@
/*
* main.c - gb.ncurses main object
*
* Copyright (C) 2012 Tobias Boege <tobias@gambas-buch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#define __MAIN_C
#include "c_ncurses.h"
#include "c_window.h"
#include "main.h"
GB_INTERFACE GB EXPORT;
GB_DESC *GB_CLASSES[] EXPORT =
{
CNCursesDesc,
CWindowDesc,
CWindowAttrsDesc,
// CCharAttrsDesc,
NULL
};
int EXPORT GB_INIT()
{
return 0;
}
void EXPORT GB_EXIT()
{
}

33
gb.ncurses/src/main.h Normal file
View file

@ -0,0 +1,33 @@
/*
* main.h - gb.ncurses main object
*
* Copyright (C) 2012 Tobias Boege <tobias@gambas-buch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef __MAIN_H
#define __MAIN_H
#include "gb_common.h"
#include "gambas.h"
#ifndef __MAIN_C
extern GB_INTERFACE GB;
#endif
#endif /* __MAIN_H */