From 813955dc4517183537f2842d039bfd048d41875e Mon Sep 17 00:00:00 2001 From: Chuck Haatvedt Date: Thu, 19 Sep 2024 16:28:02 -0500 Subject: [PATCH] adding multiple window support using panels --- TODO | 11 + config/rm.words | 370 +++++++++--------- libcob/common.h | 9 + libcob/screenio.c | 964 ++++++++++++++++++++++++++++++++++++++++------ libcob/system.def | 9 +- 5 files changed, 1054 insertions(+), 309 deletions(-) diff --git a/TODO b/TODO index cb5db8424..c08426fd9 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,17 @@ GnuCOBOL TODO -*- outline -*- The following is only a part of the things to do; many more can be found in the issue trackers. +myscreenio + +conditional if defined on local prototypes configure with --without-curses + +add libcob changelog change all curses functions to use new static window pointer "mywin" +and for curses functions which implicitly use stdscr use the window specific version of +the function specifying "mywin". + +replace refresh with refresh_mywin to reposition cursor from window relative position to screen relative positon + +check for possible unneeded if at line 3709 1 Pending requests diff --git a/config/rm.words b/config/rm.words index cf593c75a..b59cf0385 100644 --- a/config/rm.words +++ b/config/rm.words @@ -31,114 +31,114 @@ # ignored if GnuCOBOL uses that word as a reserved word. # Entries of the form word-1=word-2 define word-1 as an alias for default # reserved word word-2. No spaces are allowed around the equal sign. -reserved: ACCEPT -reserved: ACCESS -reserved: ADD -reserved: ADDRESS -reserved: ADVANCING -reserved: AFTER -reserved: ALL -reserved: ALPHABET -reserved: ALPHABETIC -reserved: ALPHABETIC-LOWER -reserved: ALPHABETIC-UPPER -reserved: ALPHANUMERIC -reserved: ALPHANUMERIC-EDITED -reserved: ALSO -reserved: ALTER -reserved: ALTERNATE -reserved: AND -reserved: ANY -reserved: ARE -reserved: AREA -reserved: AREAS -reserved: AS -reserved: ASCENDING -reserved: ASSIGN -reserved: AT -reserved: AUTHOR -reserved: AUTO* -reserved: AUTO-SKIP*=AUTO -reserved: AUTOMATIC* -reserved: BACKGROUND*=BACKGROUND-COLOR -reserved: BACKGROUND-COLOR* -reserved: BEEP=BELL -reserved: BEFORE -reserved: BELL -reserved: BINARY -reserved: BINARY-SEQUENTIAL* -reserved: BLANK -reserved: BLINK -reserved: BLOCK -reserved: BOTTOM -reserved: BY -reserved: CALL -reserved: CANCEL -reserved: CASE-INSENSITIVE* -reserved: CASE-SENSITIVE* -reserved: CD -reserved: CENTURY-DATE -reserved: CENTURY-DAY -reserved: CHARACTER -reserved: CHARACTERS -reserved: CLASS -reserved: CLOCK-UNITS -reserved: CLOSE -reserved: CODE -reserved: CODE-SET -reserved: COL -reserved: COLLATING -reserved: COLUMN -reserved: COMMA -reserved: COMMON -reserved: COMMUNICATION -reserved: COMP -reserved: COMP-1 -reserved: COMP-3 -reserved: COMP-4 -reserved: COMP-5 -reserved: COMP-6 -reserved: COMPUTATIONAL=COMP -reserved: COMPUTATIONAL-1=COMP-1 -reserved: COMPUTATIONAL-3=COMP-3 -reserved: COMPUTATIONAL-4=COMP-4 -reserved: COMPUTATIONAL-5=COMP-5 -reserved: COMPUTATIONAL-6=COMP-6 -reserved: COMPUTE -reserved: CONFIGURATION -reserved: CONTAINS -reserved: CONTENT -reserved: CONTINUE -reserved: CONTROL -reserved: COBOL -reserved: CONVERT -reserved: CONVERTING -reserved: COPY -reserved: CORR=CORRESPONDING -reserved: CORRESPONDING -reserved: COUNT -reserved: COUNT-MAX -reserved: COUNT-MIN -reserved: CRT* -reserved: CURRENCY -reserved: CURSOR -reserved: CYCLE* -reserved: DATA -reserved: DATA-POINTER -reserved: DATE -reserved: DATE-AND-TIME -reserved: DATE-COMPILED -reserved: DATE-WRITTEN -reserved: DAY -reserved: DAY-AND-TIME +reserved: ACCEPT +reserved: ACCESS +reserved: ADD +reserved: ADDRESS +reserved: ADVANCING +reserved: AFTER +reserved: ALL +reserved: ALPHABET +reserved: ALPHABETIC +reserved: ALPHABETIC-LOWER +reserved: ALPHABETIC-UPPER +reserved: ALPHANUMERIC +reserved: ALPHANUMERIC-EDITED +reserved: ALSO +reserved: ALTER +reserved: ALTERNATE +reserved: AND +reserved: ANY +reserved: ARE +reserved: AREA +reserved: AREAS +reserved: AS +reserved: ASCENDING +reserved: ASSIGN +reserved: AT +reserved: AUTHOR +reserved: AUTO* +reserved: AUTO-SKIP*=AUTO +reserved: AUTOMATIC* +reserved: BACKGROUND*=BACKGROUND-COLOR +reserved: BACKGROUND-COLOR* +reserved: BEEP=BELL +reserved: BEFORE +reserved: BELL +reserved: BINARY +reserved: BINARY-SEQUENTIAL* +reserved: BLANK +reserved: BLINK +reserved: BLOCK +reserved: BOTTOM +reserved: BY +reserved: CALL +reserved: CANCEL +reserved: CASE-INSENSITIVE* +reserved: CASE-SENSITIVE* +reserved: CD +reserved: CENTURY-DATE +reserved: CENTURY-DAY +reserved: CHARACTER +reserved: CHARACTERS +reserved: CLASS +reserved: CLOCK-UNITS +reserved: CLOSE +reserved: CODE +reserved: CODE-SET +reserved: COL +reserved: COLLATING +reserved: COLUMN +reserved: COMMA +reserved: COMMON +reserved: COMMUNICATION +reserved: COMP +reserved: COMP-1 +reserved: COMP-3 +reserved: COMP-4 +reserved: COMP-5 +reserved: COMP-6 +reserved: COMPUTATIONAL=COMP +reserved: COMPUTATIONAL-1=COMP-1 +reserved: COMPUTATIONAL-3=COMP-3 +reserved: COMPUTATIONAL-4=COMP-4 +reserved: COMPUTATIONAL-5=COMP-5 +reserved: COMPUTATIONAL-6=COMP-6 +reserved: COMPUTE +reserved: CONFIGURATION +reserved: CONTAINS +reserved: CONTENT +reserved: CONTINUE +reserved: CONTROL +reserved: COBOL +reserved: CONVERT +reserved: CONVERTING +reserved: COPY +reserved: CORR=CORRESPONDING +reserved: CORRESPONDING +reserved: COUNT +reserved: COUNT-MAX +reserved: COUNT-MIN +reserved: CRT* +reserved: CURRENCY +reserved: CURSOR +reserved: CYCLE* +reserved: DATA +reserved: DATA-POINTER +reserved: DATE +reserved: DATE-AND-TIME +reserved: DATE-COMPILED +reserved: DATE-WRITTEN +reserved: DAY +reserved: DAY-AND-TIME # note: the following words are reserved but cannot be used - DEBUGGING module not supported -reserved: DEBUG-CONTENTS -reserved: DEBUG-ITEM -reserved: DEBUG-LINE -reserved: DEBUG-NAME -reserved: DEBUG-SUB-1 -reserved: DEBUG-SUB-2 -reserved: DEBUG-SUB-3 +reserved: DEBUG-CONTENTS +reserved: DEBUG-ITEM +reserved: DEBUG-LINE +reserved: DEBUG-NAME +reserved: DEBUG-SUB-1 +reserved: DEBUG-SUB-2 +reserved: DEBUG-SUB-3 # end of not included DEBUGGING module reserved: DEBUGGING reserved: DECIMAL-POINT @@ -222,7 +222,7 @@ reserved: GLOBAL reserved: GO reserved: GOBACK reserved: GREATER -reserved: HIGH +reserved: HIGH=HIGHLIGHT reserved: HIGH-VALUE reserved: HIGH-VALUES=HIGH-VALUE reserved: HIGHEST-VALUE # SPECIAL-REGISTER @@ -266,7 +266,7 @@ reserved: LINE-SEQUENTIAL* reserved: LINES reserved: LINKAGE reserved: LOCK -reserved: LOW +reserved: LOW=LOWLIGHT reserved: LOW-VALUE reserved: LOW-VALUES=LOW-VALUE reserved: LOWEST-VALUE # SPECIAL-REGISTER @@ -445,90 +445,90 @@ reserved: ZEROS=ZERO # registered more "unused" words because these are reserved words in # unsupported modules of ANSI 85 or other COBOL dialects: -reserved: CF -reserved: CH -reserved: CONTROLS -reserved: DE -reserved: DETAIL -reserved: FINAL -reserved: FUNCTION -reserved: GENERATE -reserved: GROUP -reserved: HEADING -reserved: INITIATE -reserved: LIMIT -reserved: LINE-COUNTER -reserved: PAGE-COUNTER -reserved: PF -reserved: PH -reserved: PROCEDURES -reserved: RD -reserved: RECORDING -reserved: REFERENCES -reserved: REPORT -reserved: REPORTING -reserved: REPORTS -reserved: RESET -reserved: RF -reserved: RH -reserved: SUM -reserved: TERMINATE -reserved: TYPE -reserved: VARIABLE +reserved: CF +reserved: CH +reserved: CONTROLS +reserved: DE +reserved: DETAIL +reserved: FINAL +reserved: FUNCTION +reserved: GENERATE +reserved: GROUP +reserved: HEADING +reserved: INITIATE +reserved: LIMIT +reserved: LINE-COUNTER +reserved: PAGE-COUNTER +reserved: PF +reserved: PH +reserved: PROCEDURES +reserved: RD +reserved: RECORDING +reserved: REFERENCES +reserved: REPORT +reserved: REPORTING +reserved: REPORTS +reserved: RESET +reserved: RF +reserved: RH +reserved: SUM +reserved: TERMINATE +reserved: TYPE +reserved: VARIABLE # list of registers: # TO-DO: Should PROCEDURE-NAME [IN|OF] {PARAGRAPH|PROCEDURE|SECTION} be a register? -not-register: DIALECT-ALL # disable all registers, specify used below -# register: "ADDRESS\ IN" -register: "ADDRESS\ OF" -# register: "COUNT-MAX\ IN" -# register: "COUNT-MAX\ OF" -# register: "COUNT-MIN\ IN" -# register: "COUNT-MIN\ OF" -# register: "COUNT\ IN" -# register: "COUNT\ OF" -register: DEBUG-ITEM -# register: "HIGHEST-VALUE\ IN" -# register: "HIGHEST-VALUE\ OF" -# register: "INITIAL-VALUE\ IN" -# register: "INITIAL-VALUE\ OF" -# register: "LENGTH\ IN" -register: "LENGTH\ OF" -# register: "LINAGE-COUNTER\ IN" -# register: "LINAGE-COUNTER\ OF" -# register: "LOWEST-VALUE\ IN" -# register: "LOWEST-VALUE\ OF" -# register: "MAX-VALUE\ IN" -# register: "MAX-VALUE\ OF" -# register: "MIN-VALUE\ IN" -# register: "MIN-VALUE\ OF" -# register: PROGRAM-ID -register: RETURN-CODE -register: WHEN-COMPILED +not-register: DIALECT-ALL # disable all registers, specify used below +# register: "ADDRESS\ IN" +register: "ADDRESS\ OF" +# register: "COUNT-MAX\ IN" +# register: "COUNT-MAX\ OF" +# register: "COUNT-MIN\ IN" +# register: "COUNT-MIN\ OF" +# register: "COUNT\ IN" +# register: "COUNT\ OF" +register: DEBUG-ITEM +# register: "HIGHEST-VALUE\ IN" +# register: "HIGHEST-VALUE\ OF" +# register: "INITIAL-VALUE\ IN" +# register: "INITIAL-VALUE\ OF" +# register: "LENGTH\ IN" +register: "LENGTH\ OF" +# register: "LINAGE-COUNTER\ IN" +# register: "LINAGE-COUNTER\ OF" +# register: "LOWEST-VALUE\ IN" +# register: "LOWEST-VALUE\ OF" +# register: "MAX-VALUE\ IN" +# register: "MAX-VALUE\ OF" +# register: "MIN-VALUE\ IN" +# register: "MIN-VALUE\ OF" +# register: PROGRAM-ID +register: RETURN-CODE +register: WHEN-COMPILED # list of system names: -not-system-name: DIALECT-ALL-SWITCHES -system-name: SWITCH-1 -system-name: SWITCH-2 -system-name: SWITCH-3 -system-name: SWITCH-4 -system-name: SWITCH-5 -system-name: SWITCH-6 -system-name: SWITCH-7 -system-name: SWITCH-8 -system-name: UPSI-0 -system-name: UPSI-1 -system-name: UPSI-2 -system-name: UPSI-3 -system-name: UPSI-4 -system-name: UPSI-5 -system-name: UPSI-6 -system-name: UPSI-7 +not-system-name: DIALECT-ALL-SWITCHES +system-name: SWITCH-1 +system-name: SWITCH-2 +system-name: SWITCH-3 +system-name: SWITCH-4 +system-name: SWITCH-5 +system-name: SWITCH-6 +system-name: SWITCH-7 +system-name: SWITCH-8 +system-name: UPSI-0 +system-name: UPSI-1 +system-name: UPSI-2 +system-name: UPSI-3 +system-name: UPSI-4 +system-name: UPSI-5 +system-name: UPSI-6 +system-name: UPSI-7 -system-name: CONSOLE +system-name: CONSOLE # Intrinsic Functions - explicit not supported by RM-COBOL -not-intrinsic-function: DIALECT-ALL +not-intrinsic-function: DIALECT-ALL diff --git a/libcob/common.h b/libcob/common.h index cbdbadff6..353549d25 100644 --- a/libcob/common.h +++ b/libcob/common.h @@ -1050,6 +1050,8 @@ typedef cob_s64_t cob_flags_t; #define COB_SCREEN_NO_UPDATE ((cob_flags_t)1 << 34) /* used for syntax checking */ #define COB_SCREEN_SCROLL_UP ((cob_flags_t)1 << 35) /* used for syntax checking */ #define COB_SCREEN_GRID ((cob_flags_t)1 << 36) /* used for syntax checking */ +#define COB_SCREEN_POPUP_CREATE ((cob_flags_t)1 << 61) +#define COB_SCREEN_POPUP_REMOVE ((cob_flags_t)1 << 62) #define COB_SCREEN_TYPE_GROUP 0 #define COB_SCREEN_TYPE_FIELD 1 @@ -2178,6 +2180,13 @@ COB_EXPIMP int cob_sys_get_scr_size (unsigned char *, unsigned char *); COB_EXPIMP int cob_sys_set_scr_size (unsigned char *, unsigned char *); COB_EXPIMP int cob_sys_scr_dump (unsigned char *); COB_EXPIMP int cob_sys_scr_restore (unsigned char *); +COB_EXPIMP int cob_sys_new_window (void *); +COB_EXPIMP int cob_sys_move_window (void *); +COB_EXPIMP int cob_sys_show_window (void *); +COB_EXPIMP int cob_sys_hide_window (void *); +COB_EXPIMP int cob_sys_delete_window (void *); +COB_EXPIMP int cob_sys_top_window (void *); +COB_EXPIMP int cob_sys_bottom_window (void *); COB_EXPIMP int cob_sys_get_char (unsigned char *); COB_EXPIMP int cob_get_text (char *, int); COB_EXPIMP int cob_get_scr_cols (void); diff --git a/libcob/screenio.c b/libcob/screenio.c index 17a3c9df0..cb836d788 100644 --- a/libcob/screenio.c +++ b/libcob/screenio.c @@ -44,24 +44,36 @@ #if defined (HAVE_NCURSESW_NCURSES_H) #include +#include #define WITH_EXTENDED_SCREENIO +#define WITH_PANELS #elif defined (HAVE_NCURSESW_CURSES_H) #include +#include #define WITH_EXTENDED_SCREENIO +#define WITH_PANELS #elif defined (HAVE_NCURSES_H) #include +#include #define WITH_EXTENDED_SCREENIO +#define WITH_PANELS #elif defined (HAVE_NCURSES_NCURSES_H) #include +#include #define WITH_EXTENDED_SCREENIO +#define WITH_PANELS #elif defined (HAVE_PDCURSES_H) #define PDC_NCMOUSE /* use ncurses compatible mouse API */ #include +#include #define WITH_EXTENDED_SCREENIO +#define WITH_PANELS #elif defined (HAVE_PDCURSES_CURSES_H) #define PDC_NCMOUSE /* use ncurses compatible mouse API */ #include +#include #define WITH_EXTENDED_SCREENIO +#define WITH_PANELS #elif defined (HAVE_XCURSES_H) #define PDC_NCMOUSE /* use ncurses compatible mouse API */ #include @@ -151,8 +163,10 @@ static size_t cob_has_color; static int global_return; static int cob_current_y; static int cob_current_x; -static short fore_color /* "const" default foreground (pair 0 on init) */; -static short back_color /* "const" default background (pair 0 on init) */; +static short fore_color /* "const" default foreground (pair 0 on init) */; +static short back_color /* "const" default background (pair 0 on init) */; +static short stdscr_fore_color /* "const" default foreground (pair 0 on init) */; +static short stdscr_back_color /* "const" default background (pair 0 on init) */; static int origin_y; static int origin_x; static int display_cursor_y; @@ -161,6 +175,73 @@ static int accept_cursor_y; static int accept_cursor_x; static int pending_accept; static int got_sys_char; +static int save_cursor_x = 0; +static int save_cursor_y = 0; +static unsigned int curr_setting_insert_mode = INT_MAX; +static WINDOW *mywin; + +#ifdef WITH_PANELS +#define MAX_PANELS 20 +#define CBL_NEW_WINDOW 1 +#define CBL_DELETE_WINDOW 2 +#define CBL_MOVE_WINDOW 3 +#define CBL_SHOW_WINDOW 4 +#define CBL_HIDE_WINDOW 5 +#define CBL_TOP_WINDOW 6 +#define CBL_BOTTOM_WINDOW 7 + +typedef struct __PANEL_ENTRY + { + PANEL *pan; + WINDOW *win; + int starty; + int startx; + int win_rows; + int win_cols; + int hidden; + short fg_color; + short bg_color; + int pan_number; + } PANEL_ENTRY, *PPANEL_ENTRY; + +typedef struct __PARM_FLD + { + int pan_number; + int starty; + int startx; + int win_rows; + int win_cols; + int fg_color; + int bg_color; + int hidden; + int ret_code; + } PARM_FLD, *PPARM_FLD; + + static PANEL_ENTRY my_panels[MAX_PANELS] = + { { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 1} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 2} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 3} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 4} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 5} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 6} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 7} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 8} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 9} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 10} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 11} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 12} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 13} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 14} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 15} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 16} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 17} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 18} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 19} , + { NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 20 } }; + + +#endif + #ifdef HAVE_MOUSEMASK static unsigned int curr_setting_mouse_flags = UINT_MAX; #endif @@ -170,6 +251,9 @@ static unsigned int curr_setting_mouse_flags = UINT_MAX; static int cob_screen_init (void); +int check_panel_parm (int parm_type, PPARM_FLD parm); + +void cob_update_all_windows (void); /* Local functions */ /* @@ -300,6 +384,22 @@ handle_status (const int fret, const enum screen_statement stmt) #ifdef WITH_EXTENDED_SCREENIO +static COB_INLINE COB_A_INLINE void +refresh_mywin (WINDOW *curr_win) +{ + int pos_y, pos_x; + + if (curr_win != stdscr) { + getyx (curr_win, pos_y, pos_x); + if (wmouse_trafo(curr_win, &pos_y, &pos_x, 1)) { + move(pos_y, pos_x); + } + } + + wrefresh(curr_win); + return; +} + static void cob_beep (void) { @@ -324,7 +424,7 @@ raise_ec_on_invalid_line_or_col (const int line, const int column) int max_y; int max_x; - getmaxyx (stdscr, max_y, max_x); + getmaxyx (mywin, max_y, max_x); if (line < 0 || line >= max_y) { cob_set_exception (COB_EC_SCREEN_LINE_NUMBER); } @@ -336,7 +436,7 @@ raise_ec_on_invalid_line_or_col (const int line, const int column) static int cob_move_cursor (const int line, const int column) { - int status = move (line, column); + int status = wmove (mywin ,line, column); if (status == ERR) { raise_ec_on_invalid_line_or_col (line, column); @@ -348,7 +448,7 @@ void cob_set_cursor_pos (int line, int column) { init_cob_screen_if_needed (); - (void) move (line, column); + (void) wmove (mywin ,line, column); } #if 0 /* currently unused */ @@ -358,9 +458,9 @@ cob_move_to_beg_of_last_line (void) int max_y; int max_x; - getmaxyx (stdscr, max_y, max_x); + getmaxyx (mywin, max_y, max_x); /* We don't need to check for exceptions here; it will always be fine */ - move (max_y, 0); + wmove (mywin ,max_y, 0); COB_UNUSED (max_x); } @@ -371,7 +471,7 @@ static short cob_get_color_pair (const short fg_color, const short bg_color) { /* default color (defined from terminal, read during init ) */ - if (fg_color == fore_color && bg_color == back_color) { + if (fg_color == stdscr_fore_color && bg_color == stdscr_back_color) { return 0; } /* reserved color "all black", defined during init */ @@ -413,11 +513,11 @@ cob_activate_color_pair (const short color_pair_number) int ret; #ifdef HAVE_COLOR_SET - ret = color_set (color_pair_number, NULL); + ret = wcolor_set (mywin ,color_pair_number, NULL); #else - ret = attrset (COLOR_PAIR(color_pair_number)); + ret = wattrset (mywin, COLOR_PAIR(color_pair_number)); #endif - bkgdset (COLOR_PAIR(color_pair_number)); + wbkgdset (mywin ,COLOR_PAIR(color_pair_number)); return ret; } @@ -956,9 +1056,9 @@ cob_screen_attr (cob_field *fgc, cob_field *bgc, cob_flags_t attr, #endif /* apply attributes */ - attrset (A_NORMAL); + wattrset (mywin ,A_NORMAL); if (styles != A_NORMAL) { - attron (styles); + wattron (mywin ,styles); } /* apply colors */ @@ -975,24 +1075,24 @@ cob_screen_attr (cob_field *fgc, cob_field *bgc, cob_flags_t attr, } /* BLANK SCREEN colors the whole screen. */ if (attr & COB_SCREEN_BLANK_SCREEN) { - getyx (stdscr, line, column); - clear (); + getyx (mywin, line, column); + wclear (mywin); cob_move_cursor (line, column); } if (stmt == DISPLAY_STATEMENT) { /* BLANK LINE colors the whole line. */ if (attr & COB_SCREEN_BLANK_LINE) { - getyx (stdscr, line, column); + getyx (mywin, line, column); cob_move_cursor (line, 0); - clrtoeol (); + wclrtoeol (mywin); cob_move_cursor (line, column); } if (attr & COB_SCREEN_ERASE_EOL) { - clrtoeol (); + wclrtoeol (mywin); } if (attr & COB_SCREEN_ERASE_EOS) { - clrtobot (); + wclrtobot (mywin); } } if (attr & COB_SCREEN_BELL) { @@ -1054,6 +1154,14 @@ cob_screen_init (void) cob_runtime_error (_("failed to initialize curses")); return 1; } + + /* set mywin pointer to mywin pointer for future + implementation of panels functionality + Note that stdscr WINDOW pointer can not + be altered as the keyboard and mouse + still require this pointer */ + mywin = stdscr; + cobglobptr->cob_screen_initialized = 1; #ifdef HAVE_USE_LEGACY_CODING use_legacy_coding (2); @@ -1069,12 +1177,14 @@ cob_screen_init (void) #endif cbreak (); - keypad (stdscr, 1); + keypad (mywin, 1); nonl (); noecho (); if (has_colors ()) { start_color (); pair_content ((short)0, &fore_color, &back_color); + stdscr_fore_color = fore_color; + stdscr_back_color = back_color; /* fix bad settings of the terminal on start */ if (fore_color == back_color) { if (fore_color == COLOR_BLACK) { @@ -1114,8 +1224,8 @@ cob_screen_init (void) #endif } } - attrset (A_NORMAL); - getmaxyx (stdscr, COB_MAX_Y_COORD, COB_MAX_X_COORD); + wattrset (mywin ,A_NORMAL); + getmaxyx (mywin, COB_MAX_Y_COORD, COB_MAX_X_COORD); cob_settings_screenio (); @@ -1317,7 +1427,7 @@ pass_cursor_to_program (void) cob_field *cursor_field = COB_MODULE_PTR->cursor_pos; int sline; int scolumn; - getyx (stdscr, sline, scolumn); + getyx (mywin, sline, scolumn); sline++; scolumn++; /* zero-based in curses */ if (COB_FIELD_IS_NUMERIC (cursor_field) && COB_FIELD_TYPE (cursor_field) != COB_TYPE_NUMERIC_DISPLAY) { @@ -1415,8 +1525,8 @@ raise_ec_on_truncation (const int item_size) int max_y; int max_x; - getyx (stdscr, y, x); - getmaxyx (stdscr, max_y, max_x); + getyx (mywin, y, x); + getmaxyx (mywin, max_y, max_x); if (x + item_size - 1 > max_x) { cob_set_exception (COB_EC_SCREEN_ITEM_TRUNCATED); @@ -1430,7 +1540,7 @@ static void cob_addnstr (const char *data, const int size) { raise_ec_on_truncation (size); - addnstr (data, size); + waddnstr (mywin ,data, size); } /* variant of cob_addnstr that outputs each character separately, @@ -1446,182 +1556,182 @@ cob_addnstr_graph (const char *data, const int size) switch (c) { case 'j': /* lower-right corner */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_LRCORNER); + wadd_wch (mywin ,WACS_LRCORNER); #else - addch (ACS_LRCORNER); + waddch (mywin ,ACS_LRCORNER); #endif break; case 'J': /* lower-right corner, double */ #if defined (WACS_D_LRCORNER) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_LRCORNER); + wadd_wch (mywin ,WACS_D_LRCORNER); #elif defined (ACS_D_LRCORNER) - addch (ACS_D_LRCORNER); + waddch (mywin ,ACS_D_LRCORNER); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'k': /* upper-right corner */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_URCORNER); + wadd_wch (mywin ,WACS_URCORNER); #else - addch (ACS_URCORNER); + waddch (mywin ,ACS_URCORNER); #endif break; case 'K': /* upper-right corner, double */ #if defined (WACS_D_URCORNER) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_URCORNER); + wadd_wch (mywin ,WACS_D_URCORNER); #elif defined (ACS_D_URCORNER) - addch (ACS_D_URCORNER); + waddch (mywin ,ACS_D_URCORNER); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'm': /* lower-left corner */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_LLCORNER); + wadd_wch (mywin ,WACS_LLCORNER); #else - addch (ACS_LLCORNER); + waddch (mywin ,ACS_LLCORNER); #endif break; case 'M': /* lower-left corner, double */ #if defined (WACS_D_LLCORNER) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_LLCORNER); + wadd_wch (mywin ,WACS_D_LLCORNER); #elif defined (ACS_D_LLCORNER) - addch (ACS_D_LLCORNER); + waddch (mywin ,ACS_D_LLCORNER); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'l': /* upper-left corner */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_ULCORNER); + wadd_wch (mywin ,WACS_ULCORNER); #else - addch (ACS_ULCORNER); + waddch (mywin ,ACS_ULCORNER); #endif break; case 'L': /* upper-left corner, double */ #if defined (WACS_D_ULCORNER) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_ULCORNER); + wadd_wch (mywin ,WACS_D_ULCORNER); #elif defined (ACS_D_ULCORNER) - addch (ACS_D_ULCORNER); + waddch (mywin ,ACS_D_ULCORNER); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'n': /* plus */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_PLUS); + wadd_wch (mywin ,WACS_PLUS); #else - addch (ACS_PLUS); + waddch (mywin ,ACS_PLUS); #endif break; case 'N': /* plus, double */ #if defined (WACS_D_PLUS) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_PLUS); + wadd_wch (mywin ,WACS_D_PLUS); #elif defined (ACS_D_PLUS) - addch (ACS_D_PLUS); + waddch (mywin ,ACS_D_PLUS); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'q': /* horizontal line */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_HLINE); + wadd_wch (mywin ,WACS_HLINE); #else - addch (ACS_HLINE); + waddch (mywin ,ACS_HLINE); #endif break; case 'Q': /* horizontal line, double */ #if defined (WACS_D_HLINE) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_HLINE); + wadd_wch (mywin ,WACS_D_HLINE); #elif defined (ACS_D_HLINE) - addch (ACS_D_HLINE); + waddch (mywin ,ACS_D_HLINE); #else - addch ((const chtype)'-'); + waddch (mywin ,(const chtype)'-'); #endif break; case 'x': /* vertical line */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_VLINE); + wadd_wch (mywin ,WACS_VLINE); #else - addch (ACS_VLINE); + waddch (mywin ,ACS_VLINE); #endif break; case 'X': /* vertical line, double */ #if defined (WACS_D_VLINE) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_VLINE); + wadd_wch (mywin ,WACS_D_VLINE); #elif defined (ACS_D_VLINE) - addch (ACS_D_VLINE); + waddch (mywin ,ACS_D_VLINE); #else - addch ((const chtype)'|'); + waddch (mywin ,(const chtype)'|'); #endif break; case 't': /* left tee */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_LTEE); + wadd_wch (mywin ,WACS_LTEE); #else - addch (ACS_LTEE); + waddch (mywin ,ACS_LTEE); #endif break; case 'T': /* left tee , double */ #if defined (WACS_D_LTEE) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_LTEE); + wadd_wch (mywin ,WACS_D_LTEE); #elif defined (ACS_D_LTEE) - addch (ACS_D_LTEE); + waddch (mywin ,ACS_D_LTEE); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'u': /* right tee */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_RTEE); + wadd_wch (mywin ,WACS_RTEE); #else - addch (ACS_RTEE); + waddch (mywin ,ACS_RTEE); #endif break; case 'U': /* right tee , double */ #if defined (WACS_D_RTEE) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_RTEE); + wadd_wch (mywin ,WACS_D_RTEE); #elif defined (ACS_D_RTEE) - addch (ACS_D_RTEE); + waddch (mywin ,ACS_D_RTEE); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'v': /* bottom tee */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_BTEE); + wadd_wch (mywin ,WACS_BTEE); #else - addch (ACS_BTEE); + waddch (mywin ,ACS_BTEE); #endif break; case 'V': /* bottom tee , double */ #if defined (WACS_D_BTEE) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_BTEE); + wadd_wch (mywin ,WACS_D_BTEE); #elif defined (ACS_D_BTEE) - addch (ACS_D_BTEE); + waddch (mywin ,ACS_D_BTEE); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; case 'w': /* top tee */ #if defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_TTEE); + wadd_wch (mywin ,WACS_TTEE); #else - addch (ACS_TTEE); + waddch (mywin ,ACS_TTEE); #endif break; case 'W': /* top tee , double */ #if defined (WACS_D_TTEE) && defined (WITH_WIDE_FUNCTIONS) - add_wch (WACS_D_TTEE); + wadd_wch (mywin ,WACS_D_TTEE); #elif defined (ACS_D_TTEE) - addch (ACS_D_TTEE); + waddch (mywin ,ACS_D_TTEE); #else - addch ((const chtype)'+'); + waddch (mywin ,(const chtype)'+'); #endif break; default: - addch ((const chtype)c); + waddch (mywin ,(const chtype)c); } } } @@ -1630,14 +1740,14 @@ static void cob_addch (const chtype c) { raise_ec_on_truncation (1); - addch (c); + waddch (mywin ,c); } /* Use only when raise_ec_on_truncation is called beforehand. */ static void cob_addch_no_trunc_check (const chtype c) { - addch (c); + waddch (mywin ,c); } static void @@ -1838,7 +1948,7 @@ cob_screen_puts (cob_screen *s, cob_field *f, const cob_u32_t is_input, accept_cursor_x = column + f->size; } - refresh (); + refresh_mywin (mywin); } static COB_INLINE COB_A_INLINE int @@ -2025,7 +2135,7 @@ refresh_field (cob_screen *s) int y; int x; - getyx (stdscr, y, x); + getyx (mywin, y, x); cob_screen_puts (s, s->field, cobsetptr->cob_legacy, ACCEPT_STATEMENT); cob_move_cursor (y, x); } @@ -2438,9 +2548,9 @@ cob_screen_get_all (const int initial_curs, const int accept_timeout) default_prompt_char = COB_CH_UL; } - refresh (); + refresh_mywin (mywin); errno = 0; - timeout (accept_timeout); + wtimeout (mywin ,accept_timeout); keyp = getch (); /* FIXME: modularize (cob_screen_get_all, field_accept) and @@ -2476,7 +2586,7 @@ cob_screen_get_all (const int initial_curs, const int accept_timeout) continue; } - getyx (stdscr, cline, ccolumn); + getyx (mywin, cline, ccolumn); switch (keyp) { case KEY_ENTER: @@ -2724,6 +2834,10 @@ cob_screen_get_all (const int initial_curs, const int accept_timeout) { int mline = mevent.y; int mcolumn = mevent.x; + if (!wmouse_trafo(mywin, &mline, &mcolumn, 0)) { + cob_beep (); + continue; + } /* handle depending on state */ if (mevent.bstate & BUTTON1_PRESSED && COB_MOUSE_FLAGS & 1) { @@ -2899,7 +3013,7 @@ cob_screen_get_all (const int initial_curs, const int accept_timeout) cob_beep (); } screen_return: - refresh (); + refresh_mywin (mywin); } static int @@ -2936,7 +3050,7 @@ cob_screen_moveyx (cob_screen *s) if (s->line || s->column || s->attr & (COB_SCREEN_LINE_PLUS | COB_SCREEN_LINE_MINUS | COB_SCREEN_COLUMN_PLUS | COB_SCREEN_COLUMN_MINUS)) { - getyx (stdscr, y, x); + getyx (mywin, y, x); if (x < 0 || y < 0) { /* not translated as "testing only" (should not happen) */ cob_runtime_warning ("negative values from getyx"); @@ -2974,7 +3088,7 @@ cob_screen_moveyx (cob_screen *s) } cob_move_cursor (line, column); - refresh (); + refresh_mywin (mywin); cob_current_y = line; cob_current_x = column; } @@ -3178,7 +3292,7 @@ screen_display (cob_screen *s, const int line, const int column) pending_accept = 1; } cob_screen_iterate (s); - refresh (); + refresh_mywin (mywin); } static int @@ -3324,10 +3438,10 @@ field_display (cob_field *f, cob_flags_t fattr, const int line, const int column if (fattr & COB_SCREEN_SCROLL_DOWN) { sline = -sline; } - scrollok (stdscr, 1); - scrl (sline); - scrollok (stdscr, 0); - refresh (); + scrollok (mywin, 1); + wscrl (mywin ,sline); + scrollok (mywin, 0); + refresh_mywin (mywin); } sline = line; @@ -3375,7 +3489,7 @@ field_display (cob_field *f, cob_flags_t fattr, const int line, const int column } cob_move_cursor (sline, 0); } - refresh (); + refresh_mywin (mywin); } static void @@ -3436,10 +3550,10 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum if (fattr & COB_SCREEN_SCROLL_DOWN) { keyp = -keyp; } - scrollok (stdscr, 1); - scrl (keyp); - scrollok (stdscr, 0); - refresh (); + scrollok (mywin, 1); + wscrl (mywin ,keyp); + scrollok (mywin, 0); + refresh_mywin (mywin); } cobglobptr->cob_exception_code = 0; @@ -3494,7 +3608,7 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum } } /* SIZE IS greater than field, blank out trailing screen */ - if (size_accept > (int)f->size) { + if (size_accept > f->size) { cob_addnch (size_accept - f->size, COB_CH_SP); } /* start position within the field, if specified (all 1-based) */ @@ -3524,7 +3638,7 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum cursor_off = cursor_clause_col - scolumn + 1; } } - move (sline, scolumn + cursor_off - 1); + wmove (mywin ,sline, scolumn + cursor_off - 1); } } #if 0 /* RXWRXW - Screen update */ @@ -3549,14 +3663,14 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum } count = 0; - timeout (get_accept_timeout (ftimeout)); + wtimeout (mywin ,get_accept_timeout (ftimeout)); /* Get characters from keyboard, processing each one. */ for (; ;) { /* Show prompt characters. */ if (f) { /* Get current line, column. */ - getyx (stdscr, cline, ccolumn); + getyx (mywin, cline, ccolumn); /* Trailing prompts. */ if (fattr & COB_SCREEN_NO_ECHO) { prompt_char = COB_CH_SP; @@ -3607,7 +3721,9 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum /* Cursor to current column. */ cob_move_cursor (cline, ccolumn); /* Refresh screen. */ - refresh (); + refresh_mywin (mywin); + } else if (mywin != stdscr) { + refresh_mywin (mywin); } errno = 0; @@ -3723,6 +3839,10 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum { int mline = mevent.y; int mcolumn = mevent.x; + if (!wmouse_trafo(mywin, &mline, &mcolumn, 0)) { + cob_beep (); + continue; + } mevent.bstate &= cob_mask_accept; if (mevent.bstate != 0) { fret = mouse_to_exception_code (mevent.bstate); @@ -3950,6 +4070,10 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum { int mline = mevent.y; int mcolumn = mevent.x; + if (!wmouse_trafo(mywin, &mline, &mcolumn, 0)) { + cob_beep (); + continue; + } /* handle depending on state */ if (mevent.bstate & BUTTON1_PRESSED && COB_MOUSE_FLAGS & 1) { @@ -4080,7 +4204,7 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum if (cursor) { /* horizontal position stored in CURSOR clause */ if (!COB_FIELD_CONSTANT (cursor)) { - getyx (stdscr, cline, ccolumn); + getyx (mywin, cline, ccolumn); if (cline == sline) { cob_set_int (cursor, ccolumn + 1 - scolumn); } @@ -4097,7 +4221,7 @@ field_accept (cob_field *f, cob_flags_t fattr, const int sline, const int scolum memset (COB_TERM_BUFF, ' ', size_accept); #endif } - refresh (); + refresh_mywin (mywin); } static void @@ -4109,7 +4233,7 @@ field_accept_from_curpos (cob_field *f, cob_field *fgc, size_t ccolumn; /* Get current line, column. */ - getyx (stdscr, cline, ccolumn); + getyx (mywin, cline, ccolumn); /* accept field */ field_accept (f, (cob_flags_t)fattr, cline, ccolumn, fgc, bgc, @@ -4125,7 +4249,7 @@ field_display_at_curpos (cob_field *f, size_t ccolumn; /* Get current line, column. */ - getyx (stdscr, cline, ccolumn); + getyx (mywin, cline, ccolumn); field_display (f, (cob_flags_t)fattr, cline, ccolumn, fgc, bgc, fscroll, size_is, NULL, NULL); @@ -4360,8 +4484,8 @@ cob_sys_clear_screen (void) { init_cob_screen_if_needed (); - clear (); - refresh (); + wclear (mywin); + refresh_mywin (mywin); cob_current_y = 0; cob_current_x = 0; return 0; @@ -4377,14 +4501,14 @@ cob_screen_set_mode (const cob_u32_t smode) if (!smode) { if (cobglobptr->cob_screen_initialized) { - refresh (); + refresh_mywin (mywin); def_prog_mode (); endwin (); } } else { if (cobglobptr->cob_screen_initialized) { reset_prog_mode (); - refresh (); + refresh_mywin (mywin); } else { cob_screen_init (); } @@ -4522,11 +4646,11 @@ cob_exit_screen (void) } cobglobptr->cob_screen_initialized = 0; #if 0 /* CHECKME: Shouldn't be necessary */ - clear (); + wclear (mywin); cob_move_to_beg_of_last_line (); #endif endwin (); /* ends curses' terminal mode */ - delwin (stdscr); /* free storage related to screen not active */ + delwin (mywin); /* free storage related to screen not active */ #ifdef HAVE_CURSES_FREEALL /* cleanup storage that would otherwise be shown to be "still reachable" with valgrind */ @@ -4558,6 +4682,8 @@ cob_exit_screen_from_signal (int ss_only) #if (!defined (NCURSES_VERSION_MAJOR) || NCURSES_VERSION_MAJOR < 6) \ && (!defined (PDC_BUILD) || PDC_BUILD < 4305) if (ss_only) return; +#else + COB_UNUSED (ss_only); #endif if (cobglobptr->cob_screen_initialized) { @@ -4767,7 +4893,7 @@ cob_sys_get_csr_pos (unsigned char *fld) init_cob_screen_if_needed (); #ifdef WITH_EXTENDED_SCREENIO - getyx (stdscr, cline, ccol); + getyx (mywin, cline, ccol); if (f && f->size == 4) { /* group with sizes up to 64k (2 * 2 bytes) as used by Fujitsu (likely with a limit of @@ -4864,7 +4990,7 @@ cob_sys_set_csr_pos (unsigned char *fld) cline = fld[0]; ccol= fld[1]; } - return move (cline, ccol); + return wmove (mywin ,cline, ccol); #else COB_UNUSED (fld); return 0; @@ -4916,7 +5042,7 @@ cob_sys_set_scr_size (unsigned char *line, unsigned char *col) #endif } - /* save the current stdscr screen to a file */ +/* save the current mywin screen to a file */ int cob_sys_scr_dump(unsigned char *parm) { @@ -4931,20 +5057,21 @@ cob_sys_scr_dump(unsigned char *parm) if (filename && (filep = fopen(filename, "wb")) != NULL) { refresh(); - result = putwin(stdscr, filep); + result = putwin(mywin, filep); fclose(filep); return result; } return ERR; #else + COB_UNUSED (parm); return -1; #endif } - /* restore the current stdscr screen from a file */ +/* restore the current mywin screen from a file */ int cob_sys_scr_restore(unsigned char *parm) { #ifdef WITH_EXTENDED_SCREENIO @@ -4962,7 +5089,7 @@ int cob_sys_scr_restore(unsigned char *parm) if (replacement) { - result = overwrite(replacement, stdscr); + result = overwrite(replacement, mywin); refresh(); delwin(replacement); return result; @@ -4971,6 +5098,7 @@ int cob_sys_scr_restore(unsigned char *parm) return ERR; #else + COB_UNUSED (parm); return -1; #endif @@ -5101,3 +5229,593 @@ cob_init_screenio (cob_global *lptr, cob_settings *sptr) cob_settings_screenio (); } + +/* Check the parms used for the panel functions */ +int +check_panel_parm (int parm_type, PPARM_FLD parm) +{ + if (mywin == stdscr) { + getyx (stdscr, save_cursor_y, save_cursor_x); + stdscr_fore_color = fore_color; + stdscr_back_color = back_color; + } + + parm->ret_code = 0; + switch (parm_type) { + case CBL_NEW_WINDOW: + if (parm->starty > COB_MAX_Y_COORD) + parm->ret_code = 2; + if (parm->startx > COB_MAX_X_COORD) + parm->ret_code = 4; + if (parm->win_rows > COB_MAX_Y_COORD) + parm->ret_code = 6; + if (parm->win_cols > COB_MAX_X_COORD) + parm->ret_code = 7; + if (parm->bg_color < 0 || parm->bg_color > 7) + parm->ret_code = 8; + if (parm->fg_color < 0 || parm->fg_color > 7) + parm->ret_code = 9; + if (parm->fg_color == parm->bg_color) + parm->ret_code = 11; + break; + case CBL_DELETE_WINDOW: + if (parm->pan_number < 1 || parm->pan_number > MAX_PANELS) + parm->ret_code = 10; + break; + case CBL_MOVE_WINDOW: + if (parm->starty > COB_MAX_Y_COORD) + parm->ret_code = 2; + if (parm->startx > COB_MAX_X_COORD) + parm->ret_code = 4; + if (parm->pan_number < 1 || parm->pan_number > MAX_PANELS) + parm->ret_code = 10; + break; + case CBL_HIDE_WINDOW: + if (parm->pan_number < 1 || parm->pan_number > MAX_PANELS) + parm->ret_code = 10; + if (parm->hidden != 1 ) + parm->ret_code = 12; + break; + case CBL_SHOW_WINDOW: + if (parm->pan_number < 1 || parm->pan_number > MAX_PANELS) + parm->ret_code = 10; + if (parm->hidden != 0 ) + parm->ret_code = 14; + break; + case CBL_TOP_WINDOW: + if (parm->pan_number < 1 || parm->pan_number > MAX_PANELS) + parm->ret_code = 16; + break; + case CBL_BOTTOM_WINDOW: + if (parm->pan_number < 1 || parm->pan_number > MAX_PANELS) + parm->ret_code = 18; + break; + } + + return parm->ret_code; +} + +/* this function updates all the windows which are not hidden + and then does the final "doupdate" to update the physical screen */ +void +cob_update_all_windows (void) +{ + PANEL *ptr_pan; + WINDOW *ptr_win; + + /* first get the top panel */ + + ptr_pan =ceiling_panel(NULL); + + if (!ptr_pan) { + mywin = stdscr; + refresh_mywin (mywin); + doupdate (); + return; + } + + for(;ptr_pan;) { + ptr_win = panel_window (ptr_pan); + wnoutrefresh(ptr_win); + ptr_pan = panel_below(ptr_pan); + } + + + update_panels(); + refresh_mywin (mywin); + doupdate(); +} + +/* CBL_GC_NEW_WINDOW - create a new panel / window pair */ +int +cob_sys_new_window (void *a) +{ + +#ifndef WITH_PANELS + return -1; +#endif + + PPARM_FLD parm; + PPANEL_ENTRY pan_first = &my_panels[0]; + PPANEL_ENTRY pan_last = &my_panels[MAX_PANELS]; + PPANEL_ENTRY ptr_pan_entry; + PANEL *ptr_pan; + WINDOW *ptr_win; + int ret; + short fg_color; + short bg_color; + short color_pr; + + COB_CHK_PARMS (CBL_GC_NEW_WINDOW, 1); + init_cob_screen_if_needed (); + parm = a; + ret = check_panel_parm(CBL_NEW_WINDOW, parm); + switch (ret) { + case 99: + return -4; + break; + case 0: + break; + default: + parm->ret_code = ret; + return -1; + break; + } + + /* find empty slot in panel array */ + + for(ptr_pan_entry = pan_first; ptr_pan_entry <= pan_last; ptr_pan_entry++) { + if (ptr_pan_entry->pan == NULL) + break; + } + + /* if no empty slot exists then set error code */ + + if (ptr_pan_entry > pan_last) { + parm->ret_code = 20; + return -1; + } + + ptr_win = newwin(parm->win_rows, + parm->win_cols, + parm->starty - 1, + parm->startx - 1); + if (!ptr_win) { + parm->ret_code = 22; + return -1; + } + + ptr_pan = new_panel(ptr_win); + if (!ptr_pan) { + parm->ret_code = 24; + return -1; + } + + cob_to_curses_color (parm->fg_color, &fg_color); + cob_to_curses_color (parm->bg_color, &bg_color); + + parm->pan_number = ptr_pan_entry->pan_number; + ptr_pan_entry->pan = ptr_pan; + ptr_pan_entry->win = ptr_win; + ptr_pan_entry->win_rows = parm->win_rows; + ptr_pan_entry->win_cols = parm->win_cols; + ptr_pan_entry->startx = parm->startx - 1; + ptr_pan_entry->starty = parm->starty - 1; + ptr_pan_entry->hidden = 0; + ptr_pan_entry->fg_color = fg_color; + ptr_pan_entry->bg_color = bg_color; + + if (set_panel_userptr (ptr_pan, ptr_pan_entry)) { + parm->ret_code = 26; + return -1; + } + + mywin = ptr_win; + color_pr = cob_get_color_pair(fg_color, bg_color); + wbkgdset (mywin ,COLOR_PAIR(color_pr)); + werase(mywin); + fore_color = ptr_pan_entry->fg_color; + back_color = ptr_pan_entry->bg_color; + cob_update_all_windows (); + return 0; +} + +/* CBL_GC_MOVE_WINDOW - move the panel within stdscr */ +int +cob_sys_move_window (void *a) +{ + +#ifndef WITH_PANELS + return -1; +#endif + + + + PPARM_FLD parm; + PPANEL_ENTRY ptr_pan_entry; + PANEL *ptr_pan; + int ret; + + COB_CHK_PARMS (CBL_GC_NEW_WINDOW, 1); + init_cob_screen_if_needed (); + parm = a; + ret = check_panel_parm(CBL_MOVE_WINDOW, parm); + switch (ret) { + case 99: + return -4; + break; + case 0: + break; + default: + parm->ret_code = ret; + return -1; + break; + } + + ptr_pan_entry = &my_panels[parm->pan_number - 1]; + if (!ptr_pan_entry->pan) { + parm->ret_code = 28; + return -1; + } + + ptr_pan = ptr_pan_entry->pan; + + if (!panel_hidden(ptr_pan_entry->pan)) { + parm->ret_code = 40; + return -1; + } + + if (move_panel (ptr_pan, + parm->starty - 1, + parm->startx - 1) ) { + parm->ret_code = 29; + return -1; + } + + ptr_pan_entry->startx = parm->startx - 1; + ptr_pan_entry->starty = parm->starty - 1; + + ptr_pan = ceiling_panel(NULL); + mywin = panel_window (ptr_pan); + ptr_pan_entry = (PPANEL_ENTRY)panel_userptr(ptr_pan); + fore_color = ptr_pan_entry->fg_color; + back_color = ptr_pan_entry->bg_color; + + cob_update_all_windows (); + return 0; +} + +/* CBL_GC_SHOW_WINDOW - show the panel within stdscr */ + +int +cob_sys_show_window (void *a) +{ + +#ifndef WITH_PANELS + return -1; +#endif + + PPARM_FLD parm; + PPANEL_ENTRY ptr_pan_entry; + PANEL *ptr_pan; + int ret; + + COB_CHK_PARMS (CBL_GC_NEW_WINDOW, 1); + init_cob_screen_if_needed (); + parm = a; + ret = check_panel_parm(CBL_SHOW_WINDOW, parm); + switch (ret) { + case 99: + return -4; + break; + case 0: + break; + default: + parm->ret_code = ret; + return -1; + break; + } + + ptr_pan_entry = &my_panels[parm->pan_number - 1]; + if (!ptr_pan_entry->pan) { + parm->ret_code = 28; + return -1; + } + + if (panel_hidden(ptr_pan_entry->pan)) { + parm->ret_code = 42; + return -1; + } + + ptr_pan = ptr_pan_entry->pan; + + if (show_panel(ptr_pan)) { + parm->ret_code = 30; + return -1; + } + + ptr_pan_entry->hidden = 0; + + ptr_pan = ceiling_panel(NULL); + mywin = panel_window (ptr_pan); + ptr_pan_entry = (PPANEL_ENTRY)panel_userptr(ptr_pan); + fore_color = ptr_pan_entry->fg_color; + back_color = ptr_pan_entry->bg_color; + + cob_update_all_windows (); + return 0; + +} + +/* CBL_GC_HIDE_WINDOW - hide the panel within stdscr */ +int +cob_sys_hide_window (void *a) +{ + +#ifndef WITH_PANELS + return -1; +#endif + + PPARM_FLD parm; + PPANEL_ENTRY ptr_pan_entry; + PANEL *ptr_pan; + int ret; + + COB_CHK_PARMS (CBL_GC_NEW_WINDOW, 1); + init_cob_screen_if_needed (); + parm = a; + ret = check_panel_parm(CBL_HIDE_WINDOW, parm); + switch (ret) { + case 99: + return -4; + break; + case 0: + break; + default: + parm->ret_code = ret; + return -1; + break; + } + + ptr_pan_entry = &my_panels[parm->pan_number - 1]; + if (!ptr_pan_entry->pan) { + parm->ret_code = 28; + return -1; + } + + ptr_pan = ptr_pan_entry->pan; + + if (!panel_hidden(ptr_pan_entry->pan)) { + parm->ret_code = 40; + return -1; + } + + if (hide_panel(ptr_pan)) { + parm->ret_code = 32; + return -1; + } + + /* note the following is needed in case the top panel + was hidden. then the next panel will be on top */ + + ptr_pan = ceiling_panel(NULL); + + if (ptr_pan) { + mywin = panel_window (ptr_pan); + ptr_pan_entry = (PPANEL_ENTRY)panel_userptr(ptr_pan); + fore_color = ptr_pan_entry->fg_color; + back_color = ptr_pan_entry->bg_color; + } else { + mywin = stdscr; + move(save_cursor_y, save_cursor_x); + fore_color = stdscr_fore_color; + back_color = stdscr_back_color; + } + + cob_update_all_windows (); + return 0; + +} + + +/* CBL_GC_TOP_WINDOW - top the panel within stdscr */ +int +cob_sys_top_window (void *a) +{ + +#ifndef WITH_PANELS + return -1; +#endif + + PPARM_FLD parm; + PPANEL_ENTRY ptr_pan_entry; + PANEL *ptr_pan; + int ret; + + COB_CHK_PARMS (CBL_GC_NEW_WINDOW, 1); + init_cob_screen_if_needed (); + parm = a; + ret = check_panel_parm(CBL_BOTTOM_WINDOW, parm); + switch (ret) { + case 99: + return -4; + break; + case 0: + break; + default: + parm->ret_code = ret; + return -1; + break; + } + + ptr_pan_entry = &my_panels[parm->pan_number - 1]; + if (!ptr_pan_entry->pan) { + parm->ret_code = 28; + return -1; + } + + ptr_pan = ptr_pan_entry->pan; + + if (!panel_hidden(ptr_pan_entry->pan)) { + parm->ret_code = 40; + return -1; + } + + if (top_panel(ptr_pan)) { + parm->ret_code = 34; + return -1; + } + + ptr_pan = ceiling_panel(NULL); + mywin = panel_window (ptr_pan); + ptr_pan_entry = (PPANEL_ENTRY)panel_userptr(ptr_pan); + fore_color = ptr_pan_entry->fg_color; + back_color = ptr_pan_entry->bg_color; + + cob_update_all_windows (); + return 0; +} + + +/* CBL_GC_BOTTOM_WINDOW - top the panel within stdscr */ +int +cob_sys_bottom_window (void *a) +{ + +#ifndef WITH_PANELS + return -1; +#endif + + PPARM_FLD parm; + PPANEL_ENTRY ptr_pan_entry; + PANEL *ptr_pan; + int ret; + + COB_CHK_PARMS (CBL_GC_NEW_WINDOW, 1); + init_cob_screen_if_needed (); + parm = a; + ret = check_panel_parm(CBL_BOTTOM_WINDOW, parm); + switch (ret) { + case 99: + return -4; + break; + case 0: + break; + default: + parm->ret_code = ret; + return -1; + break; + } + + ptr_pan_entry = &my_panels[parm->pan_number - 1]; + if (!ptr_pan_entry->pan) { + parm->ret_code = 28; + return -1; + } + + ptr_pan = ptr_pan_entry->pan; + + if (!panel_hidden(ptr_pan_entry->pan)) { + parm->ret_code = 40; + return -1; + } + + if (bottom_panel(ptr_pan)) { + parm->ret_code = 34; + return -1; + } + + ptr_pan = (ceiling_panel(NULL)); + ptr_pan_entry = (PPANEL_ENTRY)(panel_userptr(ptr_pan)); + parm->pan_number = ptr_pan_entry->pan_number; + + ptr_pan = ceiling_panel(NULL); + mywin = panel_window (ptr_pan); + ptr_pan_entry = (PPANEL_ENTRY)panel_userptr(ptr_pan); + fore_color = ptr_pan_entry->fg_color; + back_color = ptr_pan_entry->bg_color; + + cob_update_all_windows (); + return 0; +} + +/* CBL_GC_DELETE_WINDOW - top the panel within stdscr */ +int +cob_sys_delete_window (void *a) +{ + +#ifndef WITH_PANELS + return -1; +#endif + + PPARM_FLD parm; + PPANEL_ENTRY ptr_pan_entry; + PANEL *ptr_pan; + int ret; + + COB_CHK_PARMS (CBL_GC_NEW_WINDOW, 1); + init_cob_screen_if_needed (); + parm = a; + ret = check_panel_parm(CBL_BOTTOM_WINDOW, parm); + switch (ret) { + case 99: + return -4; + break; + case 0: + parm->ret_code = 0; + break; + default: + parm->ret_code = ret; + return -1; + break; + } + + ptr_pan_entry = &my_panels[parm->pan_number - 1]; + if (!ptr_pan_entry->pan) { + parm->ret_code = 28; + return -1; + } + + if (!panel_hidden(ptr_pan_entry->pan)) { + show_panel( ptr_pan_entry->pan); + } + + if (del_panel(ptr_pan_entry->pan)) { + parm->ret_code = 38; + } + + if (delwin(ptr_pan_entry->win)) { + parm->ret_code = 36; + } + + if (parm->ret_code) { + return -1; + } + + ptr_pan_entry->pan = NULL; + ptr_pan_entry->win = NULL; + ptr_pan_entry->win_rows = 0; + ptr_pan_entry->win_cols = 0; + ptr_pan_entry->startx = 0; + ptr_pan_entry->starty = 0; + ptr_pan_entry->hidden = 0; + ptr_pan_entry->fg_color = 0; + ptr_pan_entry->bg_color = 7; + + ptr_pan = ceiling_panel(NULL); + + if (ptr_pan) { + mywin = panel_window (ptr_pan); + ptr_pan_entry = (PPANEL_ENTRY)panel_userptr(ptr_pan); + fore_color = ptr_pan_entry->fg_color; + back_color = ptr_pan_entry->bg_color; + } else { + mywin = stdscr; + move(save_cursor_y, save_cursor_x); + fore_color = stdscr_fore_color; + back_color = stdscr_back_color; + } + + cob_update_all_windows (); + return 0; +} diff --git a/libcob/system.def b/libcob/system.def index 969dd2b78..2ef4e18b2 100644 --- a/libcob/system.def +++ b/libcob/system.def @@ -43,7 +43,14 @@ COB_SYSTEM_GEN ("CBL_GET_CSR_POS", 1, 1, cob_sys_get_csr_pos) COB_SYSTEM_GEN ("CBL_GET_CURRENT_DIR", 3, 3, cob_sys_get_current_dir) COB_SYSTEM_GEN ("CBL_GET_SCR_SIZE", 2, 2, cob_sys_get_scr_size) COB_SYSTEM_GEN ("CBL_GC_SCR_DUMP", 1, 1, cob_sys_scr_dump) -COB_SYSTEM_GEN ("CBL_GC_SCR_RESTORE", 1, 1, cob_sys_scr_restore) +COB_SYSTEM_GEN ("CBL_GC_SCR_RESTORE", 1, 1, cob_sys_scr_restore) +COB_SYSTEM_GEN ("CBL_GC_WINDOW_NEW", 1, 1, cob_sys_new_window) +COB_SYSTEM_GEN ("CBL_GC_WINDOW_MOVE", 1, 1, cob_sys_move_window) +COB_SYSTEM_GEN ("CBL_GC_WINDOW_SHOW", 1, 1, cob_sys_show_window) +COB_SYSTEM_GEN ("CBL_GC_WINDOW_HIDE", 1, 1, cob_sys_hide_window) +COB_SYSTEM_GEN ("CBL_GC_WINDOW_DELETE", 1, 1, cob_sys_delete_window) +COB_SYSTEM_GEN ("CBL_GC_WINDOW_TOP", 1, 1, cob_sys_top_window) +COB_SYSTEM_GEN ("CBL_GC_WINDOW_BOTTOM", 1, 1, cob_sys_bottom_window) COB_SYSTEM_GEN ("CBL_IMP", 3, 3, cob_sys_imp) COB_SYSTEM_GEN ("CBL_NIMP", 3, 3, cob_sys_nimp) COB_SYSTEM_GEN ("CBL_NOR", 3, 3, cob_sys_nor)