gambas-source-code/gb.ncurses/src/c_screen.c

273 lines
5.2 KiB
C
Raw Normal View History

/*
* c_screen.c - gb.ncurses Screen class
*
* Copyright (C) 2012/3 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_SCREEN_C
#include <stdio.h>
#include <signal.h>
#include <assert.h>
#include <ncurses.h>
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
#include <panel.h>
#include "gambas.h"
#include "main.h"
#include "c_screen.h"
#include "c_input.h"
#define THIS _active
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
#define E_UNSUPP "Unsupported value"
static CSCREEN *_active;
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
GB_SIGNAL_CALLBACK *_sigwinch_cb;
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
DECLARE_EVENT(EVENT_Resize);
static void SCREEN_sigwinch(int signum, intptr_t data)
{
/* TODO: ncurses may be configured to provide its own SIGWINCH
* handler. See resizeterm(3X). */
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
if (signum == SIGWINCH)
GB.Raise(_active, EVENT_Resize, 0);
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
}
int SCREEN_init()
{
_sigwinch_cb = GB.Signal.Register(SIGWINCH, SCREEN_sigwinch,
(intptr_t) NULL);
return 0;
}
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
void SCREEN_exit()
{
GB.Signal.Unregister(SIGWINCH, _sigwinch_cb);
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
}
void SCREEN_refresh()
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
{
if (!NCURSES_RUNNING)
return;
update_panels();
doupdate();
}
BEGIN_METHOD_VOID(Screen_init)
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
_active = GB.AutoCreate(GB.FindClass("Screen"), 0);
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
END_METHOD
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
static int CSCREEN_cursor(CSCREEN *scr, int mode)
{
if (mode >= 0 && mode <= 2)
curs_set(mode);
else
return -1;
scr->cursor = mode;
return 0;
}
static void CSCREEN_echo(CSCREEN *scr, int mode)
{
if (mode)
echo();
else
noecho();
scr->echo = mode;
}
BEGIN_METHOD_VOID(Screen_new)
CSCREEN_cursor(THIS, 1);
CSCREEN_echo(THIS, 1);
INPUT_mode(THIS, INPUT_CBREAK);
END_METHOD
#if 0
BEGIN_METHOD(Screen_new, GB_STRING termpath)
char path[LENGTH(termpath) + 1];
FILE *finout;
strncpy(path, STRING(termpath), LENGTH(termpath));
path[LENGTH(termpath)] = 0;
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
finout = fopen(path, "r+");
if (!finout) {
GB.Error(NULL);
return;
}
assert(_maxscreen < MAX_SCREENS);
_screens[_maxscreen] = THIS;
THIS->index = _curscreen = _maxscreen++;
THIS->screen = newterm(NULL, finout, finout);
set_term(THIS->screen);
THIS->finout = finout;
THIS->buffered = 1;
CSCREEN_cursor(THIS, 0);
CSCREEN_echo(THIS, 0);
INPUT_mode(THIS, INPUT_CBREAK);
refresh();
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
END_METHOD
BEGIN_METHOD_VOID(Screen_free)
void *dst, *src;
if (THIS->index != _maxscreen - 1) {
dst = &_screens[THIS->index];
src = dst + sizeof(_screens[0]);
memmove(dst, src, _maxscreen - THIS->index);
}
_screens[THIS->index] = NULL;
if (_curscreen)
_curscreen--;
_maxscreen--;
endwin();
fclose(THIS->finout);
delscreen(THIS->screen);
if (!_maxscreen) {
SCREEN_exit();
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
return;
}
set_term(_active->screen);
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
END_METHOD
#endif
BEGIN_METHOD_VOID(Screen_Beep)
beep();
END_METHOD
BEGIN_METHOD_VOID(Screen_Flash)
flash();
END_METHOD
BEGIN_METHOD_VOID(Screen_Refresh)
SCREEN_refresh();
END_METHOD
BEGIN_METHOD(Screen_Resize, GB_INTEGER lines; GB_INTEGER cols)
resizeterm(VARG(lines), VARG(cols));
END_METHOD
GB_DESC CCursorDesc[] = {
GB_DECLARE("Cursor", 0),
GB_NOT_CREATABLE(),
/* According to curs_set */
GB_CONSTANT("Hidden", "i", 0),
GB_CONSTANT("Visible", "i", 1),
GB_CONSTANT("VeryVisible", "i", 2),
GB_END_DECLARE
};
BEGIN_PROPERTY(Screen_Cursor)
if (READ_PROPERTY) {
GB.ReturnInteger(THIS->cursor);
return;
}
if (CSCREEN_cursor(THIS, VPROP(GB_INTEGER)) == -1)
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
GB.Error(E_UNSUPP);
END_PROPERTY
BEGIN_PROPERTY(Screen_Echo)
if (READ_PROPERTY) {
GB.ReturnBoolean(THIS->echo);
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
return;
}
CSCREEN_echo(THIS, !!VPROP(GB_BOOLEAN));
END_PROPERTY
BEGIN_PROPERTY(Screen_Input)
if (READ_PROPERTY) {
GB.ReturnInteger(THIS->input);
return;
}
INPUT_mode(THIS, VPROP(GB_INTEGER));
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
END_PROPERTY
BEGIN_PROPERTY(Screen_Lines)
if (READ_PROPERTY) {
GB.ReturnInteger(LINES);
return;
}
resizeterm(VPROP(GB_INTEGER), COLS);
END_PROPERTY
BEGIN_PROPERTY(Screen_Cols)
if (READ_PROPERTY) {
GB.ReturnInteger(COLS);
return;
}
resizeterm(LINES, VPROP(GB_INTEGER));
END_PROPERTY
GB_DESC CScreenDesc[] = {
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
GB_DECLARE("Screen", sizeof(CSCREEN)),
GB_AUTO_CREATABLE(),
GB_NOT_CREATABLE(),
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
GB_EVENT("Resize", NULL, NULL, &EVENT_Resize),
GB_STATIC_METHOD("_init", NULL, Screen_init, NULL),
GB_STATIC_METHOD("Beep", NULL, Screen_Beep, NULL),
GB_STATIC_METHOD("Flash", NULL, Screen_Flash, NULL),
GB_STATIC_METHOD("Refresh", NULL, Screen_Refresh, NULL),
GB_STATIC_METHOD("Resize", NULL, Screen_Resize, "(Lines)i(Cols)i"),
GB_STATIC_PROPERTY("Cursor", "i", Screen_Cursor),
GB_STATIC_PROPERTY("Echo", "b", Screen_Echo),
[GB.NCURSES] * NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen reflects better that these routines affect the entire screen * NEW: Window has a Caption property to display a caption within the border frame; only visible when the Window has a border * NEW: Add NoDelay input mode to Screen class (for use with caution and a true tty). This mode lets the programmer artifically set the keyboard repeat delay for the program (beware: still broken) * NEW: Add IsConsole property to check if one can enter NoDelay mode * NEW: Add Repeater property to Screen to specify keyboard repeat delay. This specifies the minimum interval of sucessively risen Read events and Window.Read() calls * NEW: Rename Window.WaitKey() to .Read() * NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise() * NEW: Add very-visible mode for cursor, according to ncurses doc * NEW: Window class has a new optional parameter to specify the parent Screen, if none given, the currently active Screen is used. * NEW: Window class does not get a default event name anymore. If the Read event is risen and the active Window cannot raise events, the parent Screen raises it (beware: still broken) * NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to choose the border look * NEW: Cursor resides on the new location after Window.Print() now * OPT: Remove redundant wrapping code in Print function because ncurses waddch() does this by itself * OPT: Stream inheritance entirely useless due to future ReadLine() function, hence it was removed * OPT: Remove NCurses class, it contained only component-global routines that were moved to main module * BUG: Turning off attributes with the Normal attribute now works * BUG: Changes on color attributes (also on color pairs) are immediately visible now * BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and .PrintCenter() * BUG: Newline to Window.Print() really works now and gives the desired effect of not returning to x=0 on the next line (like ncurses does) git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
GB_STATIC_PROPERTY("Input", "i", Screen_Input),
GB_STATIC_PROPERTY("Height", "i", Screen_Lines),
GB_STATIC_PROPERTY("H", "i", Screen_Lines),
GB_STATIC_PROPERTY("Width", "i", Screen_Cols),
GB_STATIC_PROPERTY("W", "i", Screen_Cols),
GB_END_DECLARE
};