C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Window Support

Manage NCurses windows and color settings. More...

Functions

int box2_new (int wlines, int wcols, int wbegy, int wbegx, char *wtitle, bool win_pair)
 Create a new window with optional box and title.
int box_new (int wlines, int wcols, int wbegy, int wbegx, char *wtitle, bool win_pair)
 Create a new window with optional box and title.
void cbox (WINDOW *box)
 Draw a box around the specified window.
void cbox2 (WINDOW *box)
 Draw a box with a separator line around the specified window.
void destroy_curses ()
 Gracefully shut down NCurses and restore terminal settings.
void mvwaddstr_fill (WINDOW *w, int y, int x, char *s, int l)
 For lines shorter than their display area, fill the rest with spaces.
bool open_curses (SIO *sio)
 Initialize NCurses and color settings.
void restore_wins ()
 Restore all windows after a screen resize.
void view_full_screen_resize (Init *init)
 Resize the full screen view and its components.
void view_win_resize (Init *init, char *title)
 Resize the current window and its box, and update the title.
int win2_new (int wlines, int wcols, int wbegy, int wbegx)
 Create a new window with specified dimensions and position.
WINDOW * win_del ()
 Delete the current window and its associated box window.
void win_init_attrs ()
 Initialize window attributes.
int win_new (int wlines, int wcols, int wbegy, int wbegx)
 Create a new window with specified dimensions and position.
void win_redraw (WINDOW *win)
 Redraw the specified window.
void win_resize (int wlines, int wcols, char *title)
 Resize the current window and its box, and update the title.
int xwgetch (WINDOW *win, Chyron *chyron, int n)
 Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line, and accepts a sinigle character answer.

Detailed Description

Manage NCurses windows and color settings.

Function Documentation

◆ box2_new()

int box2_new ( int wlines,
int wcols,
int wbegy,
int wbegx,
char * wtitle,
bool win_pair )

Create a new window with optional box and title.

box2_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
wbegyBeginning Y position
wbegxBeginning X position
wtitleWindow title
win_pairIf true, creates a pair of windows (box and inner window)
Returns
0 if successful, 1 if error

Definition at line 697 of file dwin.c.

698 {
699 int maxx;
700 if (win_ptr >= MAXWIN) {
701 ssnprintf(em0, MAXLEN - 1, "Maximum number of windows (%d) exceeded");
702 abend(-1, em0);
703 }
704 win_ptr++;
705 wlines = min(wlines, LINES - 2);
706 wcols = min(wcols, COLS - 2);
707 win_box[win_ptr] = newwin(wlines + 4, wcols + 2, wbegy, wbegx);
708 if (win_box[win_ptr] == nullptr) {
709 win_ptr--;
710 return 1;
711 }
712#ifdef DEBUG_IMMEDOK
713 immedok(win_box[win_ptr], true);
714#endif
715 wbkgrndset(win_box[win_ptr], &CCC_BOX);
717 mvwaddnwstr(win_box[win_ptr], 0, 1, &bw_rt, 1);
718 mvwaddnwstr(win_box[win_ptr], 0, 2, &bw_sp, 1);
719 mvwaddstr(win_box[win_ptr], 0, 3, wtitle);
720 maxx = getmaxx(win_box[win_ptr]);
721 int s = strlen(wtitle);
722 if ((s + 3) < maxx)
723 mvwaddch(win_box[win_ptr], 0, (s + 3), ' ');
724 if ((s + 4) < maxx)
725 mvwaddnwstr(win_box[win_ptr], 0, (s + 4), &bw_lt, 1);
726 wnoutrefresh(win_box[win_ptr]);
727 win_win[win_ptr] = nullptr;
728 win_win2[win_ptr] = nullptr;
729 if (win_pair) {
730 win_new(wlines - 1, wcols, wbegy, wbegx);
731 win2_new(2, wcols, wbegy + wlines, wbegx);
732 }
733 return 0;
734}
#define MAXWIN
Definition cm.h:542
bool win_pair
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:56
#define MAXLEN
Definition curskeys.c:15
const wchar_t bw_rt
Definition dwin.c:103
WINDOW * win_win[MAXWIN]
Definition dwin.c:122
WINDOW * win_win2[MAXWIN]
Definition dwin.c:123
const wchar_t bw_sp
Definition dwin.c:104
const wchar_t bw_lt
Definition dwin.c:102
cchar_t CCC_BOX
Definition dwin.c:159
int win_ptr
Definition dwin.c:130
char em0[MAXLEN]
Definition dwin.c:141
WINDOW * win_box[MAXWIN]
Definition dwin.c:124
int win2_new(int wlines, int wcols, int wbegy, int wbegx)
Create a new window with specified dimensions and position.
Definition dwin.c:814
int win_new(int, int, int, int)
Create a new window with specified dimensions and position.
Definition dwin.c:788
void cbox2(WINDOW *)
Draw a box with a separator line around the specified window.
Definition dwin.c:989
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1588
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:311

References abend(), bw_lt, bw_rt, bw_sp, cbox2(), CCC_BOX, em0, ssnprintf(), win2_new(), win_box, win_new(), win_ptr, win_win, and win_win2.

Referenced by open_pick_win().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_new()

int box_new ( int wlines,
int wcols,
int wbegy,
int wbegx,
char * wtitle,
bool win_pair )

Create a new window with optional box and title.

box_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
wbegyBeginning Y position
wbegxBeginning X position
wtitleWindow title
win_pairIf true, creates a pair of windows (box and inner window)
Returns
0 if successful, 1 if error

Definition at line 745 of file dwin.c.

746 {
747 int maxx;
748 if (win_ptr >= MAXWIN) {
749 ssnprintf(em0, MAXLEN - 1, "Maximum number of windows (%d) exceeded");
750 abend(-1, em0);
751 }
752 win_ptr++;
753 wlines = min(wlines, LINES - 2);
754 wcols = min(wcols, COLS - 2);
755 win_box[win_ptr] = newwin(wlines + 2, wcols + 2, wbegy, wbegx);
756 if (win_box[win_ptr] == nullptr) {
757 win_ptr--;
758 return 1;
759 }
760#ifdef DEBUG_IMMEDOK
761 immedok(win_box[win_ptr], true);
762#endif
763 wbkgrndset(win_box[win_ptr], &CCC_BOX);
765 mvwaddnwstr(win_box[win_ptr], 0, 1, &bw_rt, 1);
766 mvwaddnwstr(win_box[win_ptr], 0, 2, &bw_sp, 1);
767 mvwaddstr(win_box[win_ptr], 0, 3, wtitle);
768 maxx = getmaxx(win_box[win_ptr]);
769 int s = strlen(wtitle);
770 if ((s + 3) < maxx)
771 mvwaddch(win_box[win_ptr], 0, (s + 3), ' ');
772 if ((s + 4) < maxx)
773 mvwaddnwstr(win_box[win_ptr], 0, (s + 4), &bw_lt, 1);
774 wnoutrefresh(win_box[win_ptr]);
775 win_win[win_ptr] = nullptr;
776 if (win_pair)
777 win_new(wlines, wcols, wbegy, wbegx);
778 return 0;
779}
void cbox(WINDOW *)
Draw a box around the specified window.
Definition dwin.c:957

References abend(), bw_lt, bw_rt, bw_sp, cbox(), CCC_BOX, em0, ssnprintf(), win_box, win_new(), win_ptr, and win_win.

Referenced by action_disposition(), answer_yn(), display_error(), display_form(), init_view_boxwin(), menu_engine(), Perror(), popup_ckeys(), and wait_mk_win().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cbox()

void cbox ( WINDOW * box)

Draw a box around the specified window.

cbox

Parameters
boxPointer to the window to draw the box around

This function uses NCurses functions to draw a box around the specified window. It adds the appropriate characters for the corners and edges of the box based on the current character set. Use this function when you want to visually separate a window from the rest of the screen with a border.

Definition at line 957 of file dwin.c.

957 {
958 int x, y;
959 int maxx;
960 int maxy;
961
962 maxx = getmaxx(box);
963 maxx--;
964 mvwaddnwstr(box, 0, 0, &bw_tl, 1);
965 for (x = 1; x < maxx; x++)
966 waddnwstr(box, &bw_ho, 1);
967 waddnwstr(box, &bw_tr, 1);
968 maxy = getmaxy(box);
969 maxy--;
970 for (y = 1; y < maxy; y++) {
971 mvwaddnwstr(box, y, 0, &bw_ve, 1);
972 mvwaddnwstr(box, y, maxx, &bw_ve, 1);
973 }
974 mvwaddnwstr(box, maxy, 0, &bw_bl, 1);
975 for (x = 1; x < maxx; x++)
976 waddnwstr(box, &bw_ho, 1);
977 waddnwstr(box, &bw_br, 1);
978}
const wchar_t bw_ho
Definition dwin.c:96
const wchar_t bw_tl
Definition dwin.c:98
const wchar_t bw_tr
Definition dwin.c:99
const wchar_t bw_bl
Definition dwin.c:100
const wchar_t bw_ve
Definition dwin.c:97
const wchar_t bw_br
Definition dwin.c:101

References bw_bl, bw_br, bw_ho, bw_tl, bw_tr, and bw_ve.

Referenced by box_new(), view_win_resize(), and win_resize().

Here is the caller graph for this function:

◆ cbox2()

void cbox2 ( WINDOW * box)

Draw a box with a separator line around the specified window.

cbox2

Parameters
boxPointer to the window to draw the box around

This function draws a box around the specified window, similar to cbox(), but it also includes a horizontal separator line that divides the box into two sections. The separator line is drawn at a fixed position (line 00, page 00) and extends across the width of the box. Use this function when you want to visually separate two sections within a window, such as for a header and content area.

Definition at line 989 of file dwin.c.

989 {
990 int x, y;
991 int maxx;
992 int maxy;
993
994 maxx = getmaxx(box);
995 maxx--;
996 mvwaddnwstr(box, 0, 0, &bw_tl, 1);
997 for (x = 1; x < maxx; x++)
998 waddnwstr(box, &bw_ho, 1);
999 waddnwstr(box, &bw_tr, 1);
1000 maxy = getmaxy(box);
1001 // Verticals
1002 for (y = 1; y < maxy - 4; y++) {
1003 mvwaddnwstr(box, y, 0, &bw_ve, 1);
1004 mvwaddnwstr(box, y, maxx, &bw_ve, 1);
1005 }
1006 // Separator line
1007 mvwaddnwstr(box, y, 0, &bw_lt, 1);
1008 // line 00, page 00
1009 mvwaddnwstr(box, y, 1, &bw_rt, 1);
1010 mvwaddnwstr(box, y, 24, &bw_lt, 1);
1011 for (x = 25; x < maxx; x++)
1012 waddnwstr(box, &bw_ho, 1);
1013 waddnwstr(box, &bw_rt, 1);
1014 // Window 2
1015 y++;
1016 mvwaddnwstr(box, y, 0, &bw_ve, 1);
1017 mvwaddnwstr(box, y, maxx, &bw_ve, 1);
1018 y++;
1019 mvwaddnwstr(box, y, 0, &bw_ve, 1);
1020 mvwaddnwstr(box, y, maxx, &bw_ve, 1);
1021 // Bottom
1022 y++;
1023 mvwaddnwstr(box, y, 0, &bw_bl, 1);
1024 for (x = 1; x < maxx; x++)
1025 waddnwstr(box, &bw_ho, 1);
1026 waddnwstr(box, &bw_br, 1);
1027}

References bw_bl, bw_br, bw_ho, bw_lt, bw_rt, bw_tl, bw_tr, and bw_ve.

Referenced by box2_new().

Here is the caller graph for this function:

◆ destroy_curses()

void destroy_curses ( )

Gracefully shut down NCurses and restore terminal settings.

destroy_curses

This function should be called before exiting the program to ensure that the terminal is left in a usable state. It checks if NCurses was initialized and, if so, it erases the screen, refreshes it, and ends the NCurses session. It also restores the original terminal settings using restore_shell_tioctl and resets signal handlers to their default state with sig_dfl_mode.

Definition at line 540 of file dwin.c.

540 {
541 if (!f_curses_open)
542 return;
543 while (win_ptr > 0) {
544 if (win_win[win_ptr])
545 delwin(win_win[win_ptr]);
546 if (win_win2[win_ptr])
547 delwin(win_win2[win_ptr]);
548 if (win_box[win_ptr])
549 delwin(win_box[win_ptr]);
550 win_win[win_ptr] = nullptr;
551 win_win2[win_ptr] = nullptr;
552 win_box[win_ptr] = nullptr;
553 win_ptr--;
554 }
555 werase(stdscr);
556 wrefresh(stdscr);
557 endwin();
558 delscreen(screen);
559 fclose(ncurses_fp);
560 f_curses_open = false;
562 sig_dfl_mode();
563 return;
564}
bool f_curses_open
Definition sig.c:33
SCREEN * screen
Definition dwin.c:79
FILE * ncurses_fp
Definition dwin.c:169
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:56
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:42

References f_curses_open, ncurses_fp, restore_shell_tioctl(), screen, sig_dfl_mode(), win_box, win_ptr, win_win, and win_win2.

Referenced by abend(), and open_curses().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mvwaddstr_fill()

void mvwaddstr_fill ( WINDOW * w,
int y,
int x,
char * s,
int l )

For lines shorter than their display area, fill the rest with spaces.

mvwaddstr_fill

Parameters
wPointer to window
yY coordinate
xX coordinate
sString to display
lLength of display area

Definition at line 1515 of file dwin.c.

1515 {
1516 char *d, *e;
1517 char tmp_str[MAXLEN];
1518
1519 l = min(l, MAXLEN - 1);
1520 e = d = tmp_str;
1521 e += l;
1522 while (d < e) {
1523 if (*s == '\0' || *s == '\n')
1524 *d++ = ' ';
1525 else
1526 *d++ = *s++;
1527 }
1528 *d = '\0';
1529 mvwaddstr(w, y, x, tmp_str);
1530}

Referenced by display_page(), menu_cmd_processor(), picker(), reverse_object(), and unreverse_object().

Here is the caller graph for this function:

◆ open_curses()

bool open_curses ( SIO * sio)

Initialize NCurses and color settings.

open_curses

Parameters
sioPointer to SIO struct with terminal and color settings
Returns
true if successful, false if error

This function initializes NCurses and sets up color pairs based on the settings in the SIO struct. It also applies gamma correction to colors. Use this function to initialize NCurses if you don't want NCurses to receive data from the stdin pipe

1. saves stdin and stdout file descriptors in SIO
2. opens a terminal device for NCurses screen IO
3. replaces STDERR_FILENO with terminal file descriptor
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:696

open the terminal device for reading and writing

We use SCREEN and newterm because this allows us to

specify the terminal FILE

Set gamma correction values

These are read from ~/.minitrc

We need these values when initializing colors

Definition at line 192 of file dwin.c.

192 {
193 char tmp_str[MAXLEN];
194 char emsg0[MAXLEN];
195
196 if (ttyname_r(STDERR_FILENO, sio->tty_name, sizeof(sio->tty_name)) != 0) {
197 strerror_r(errno, tmp_str, MAXLEN - 1);
198 strnz__cpy(emsg0, "ttyname_r failed ", MAXLEN - 1);
199 strnz__cat(emsg0, tmp_str, MAXLEN - 1);
200 fprintf(stderr, "%s\n", tmp_str);
201 exit(0);
202 }
204 ncurses_fp = fopen(sio->tty_name, "r+");
205 if (ncurses_fp == nullptr) {
206 strerror_r(errno, tmp_str, MAXLEN - 1);
207 strnz__cpy(emsg0, "fopen(sio->tty_name) failed ", MAXLEN - 1);
208 strnz__cat(emsg0, tmp_str, MAXLEN - 1);
209 fprintf(stderr, "%s\n", tmp_str);
210 exit(0);
211 }
214 screen = newterm(nullptr, ncurses_fp, ncurses_fp);
215 if (screen == nullptr) {
216 strerror_r(errno, tmp_str, MAXLEN - 1);
217 strnz__cpy(emsg0, "newterm failed ", MAXLEN - 1);
218 strnz__cat(emsg0, tmp_str, MAXLEN - 1);
219 fprintf(stderr, "%s\n", tmp_str);
220 exit(0);
221 }
222 set_term(screen);
223 f_curses_open = true;
224 if (!has_colors()) {
226 abend(-1, "Terminal color support required");
227 }
228 start_color();
229 if (!can_change_color()) {
231 fprintf(stderr, "Terminal cannot change colors\n");
232 fprintf(stderr, "Check TERM environment variable\n");
233 fprintf(stderr, "Check terminfo for missing \"ccc\"\n");
234 abend(-1, "fatal error");
235 }
240 RED_GAMMA = sio->red_gamma;
241 GREEN_GAMMA = sio->green_gamma;
242 BLUE_GAMMA = sio->blue_gamma;
243 GRAY_GAMMA = sio->gray_gamma;
244
245 // cp_ variables are indices for ncurses color pairs, created with get_clr_pair function. These color pairs are used to set the foreground and background colors for different elements of the interface, such as windows, text, and boxes. By defining these color pair indices as global variables, we can easily reference them throughout the code when applying colors to various parts of the interface using NCurses functions that accept color pair indices.
254 // CCC_ variables are cchar_t versions of the color pairs, created with mkccc function for use in NCurses functions that require cchar_t attributes. These are used to set the background color of windows and other elements in the interface. By creating these cchar_t variables, we can easily apply the desired color pairs to various parts of the interface using NCurses functions that accept cchar_t attributes.
255 CCC_NORM = mkccc(cp_norm, WA_NORMAL, " ");
256 CCC_WIN = mkccc(cp_win, WA_NORMAL, " ");
257 CCC_NT = mkccc(cp_nt, WA_NORMAL, " ");
258 CCC_NT_REV = mkccc(cp_nt_rev, WA_NORMAL, " ");
259 CCC_NT_HL_REV = mkccc(cp_nt_hl_rev, WA_NORMAL, " ");
260 CCC_NT_HL = mkccc(cp_nt_hl, WA_NORMAL, " ");
261 CCC_BOX = mkccc(cp_box, WA_NORMAL, " ");
262 CCC_LN = mkccc(cp_ln, WA_NORMAL, " ");
263 noecho();
264 keypad(stdscr, true);
265 idlok(stdscr, false);
266 idcok(stdscr, false);
267 wbkgrndset(stdscr, &CCC_NT);
268#ifdef DEBUG_IMMEDOK
269 immedok(stdscr, true);
270#endif
271 win_ptr = -1;
272 return sio;
273}
@ CLR_FG
Definition cm.h:141
@ CLR_NT_FG
Definition cm.h:146
@ CLR_WHITE
Definition cm.h:131
@ CLR_NT_REV_BG
Definition cm.h:149
@ CLR_BLACK
Definition cm.h:124
@ CLR_LN_BG
Definition cm.h:145
@ CLR_NT_HL_REV_BG
Definition cm.h:153
@ CLR_BO
Definition cm.h:143
@ CLR_NT_HL_FG
Definition cm.h:150
@ CLR_LN
Definition cm.h:144
@ CLR_NT_HL_BG
Definition cm.h:151
@ CLR_NT_HL_REV_FG
Definition cm.h:152
@ CLR_BG
Definition cm.h:142
@ CLR_NT_BG
Definition cm.h:147
@ CLR_NT_REV_FG
Definition cm.h:148
int cp_box
Definition dwin.c:147
int cp_nt
Definition dwin.c:148
int cp_nt_hl
Definition dwin.c:150
cchar_t CCC_LN
Definition dwin.c:164
int cp_win
Definition dwin.c:146
cchar_t CCC_WIN
Definition dwin.c:157
double BLUE_GAMMA
Definition dwin.c:118
int cp_ln
Definition dwin.c:152
int cp_nt_hl_rev
Definition dwin.c:151
SIO * sio
Definition dwin.c:80
cchar_t CCC_NT_HL_REV
Definition dwin.c:162
cchar_t CCC_NT_HL
Definition dwin.c:163
double GRAY_GAMMA
Definition dwin.c:112
double RED_GAMMA
Definition dwin.c:114
int cp_nt_rev
Definition dwin.c:149
double GREEN_GAMMA
Definition dwin.c:116
cchar_t CCC_NORM
Definition dwin.c:156
cchar_t CCC_NT_REV
Definition dwin.c:161
int cp_norm
Definition dwin.c:145
cchar_t CCC_NT
Definition dwin.c:160
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:540
bool init_clr_palette(SIO *)
Initialize color palette based on SIO settings.
Definition dwin.c:429
cchar_t mkccc(int, attr_t, char *)
Create a cchar_t with the specified color pair index.
Definition dwin.c:625
int get_clr_pair(int fg, int bg)
Get color pair index for foreground and background colors.
Definition dwin.c:284
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:435
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:464

References abend(), BLUE_GAMMA, SIO::blue_gamma, CCC_BOX, CCC_LN, CCC_NORM, CCC_NT, CCC_NT_HL, CCC_NT_HL_REV, CCC_NT_REV, CCC_WIN, CLR_BG, CLR_BLACK, CLR_BO, CLR_FG, CLR_LN, CLR_LN_BG, CLR_NT_BG, CLR_NT_FG, CLR_NT_HL_BG, CLR_NT_HL_FG, CLR_NT_HL_REV_BG, CLR_NT_HL_REV_FG, CLR_NT_REV_BG, CLR_NT_REV_FG, CLR_WHITE, cp_box, cp_ln, cp_norm, cp_nt, cp_nt_hl, cp_nt_hl_rev, cp_nt_rev, cp_win, destroy_curses(), f_curses_open, get_clr_pair(), GRAY_GAMMA, SIO::gray_gamma, GREEN_GAMMA, SIO::green_gamma, init_clr_palette(), mkccc(), ncurses_fp, RED_GAMMA, SIO::red_gamma, screen, strnz__cat(), strnz__cpy(), SIO::tty_name, and win_ptr.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore_wins()

void restore_wins ( )

Restore all windows after a screen resize.

restore_wins

This function is used to restore the display of all windows after a screen resize event. It clears the standard screen and then iterates through all existing windows, touching and refreshing them to ensure they are redrawn correctly on the resized screen. Use this function in response to a SIGWINCH signal to handle terminal resizing gracefully.

Definition at line 933 of file dwin.c.

933 {
934 int i;
935 for (i = 0; i <= win_ptr; i++) {
936 if (win_box[i] != nullptr) {
937 touchwin(win_box[i]);
938 wnoutrefresh(win_box[i]);
939 wrefresh(win_box[i]);
940 }
941 if (win_win[i] == nullptr)
942 continue;
943 touchwin(win_win[i]);
944 wnoutrefresh(win_win[i]);
945 wrefresh(win_win[i]);
946 }
947}

References win_box, win_ptr, and win_win.

Referenced by dmon(), enter_file_spec(), exec_objects(), fork_exec(), form_exec_receiver(), full_screen_shell(), menu_cmd_processor(), menu_engine(), view_cmd_processor(), and write_view_buffer().

Here is the caller graph for this function:

◆ view_full_screen_resize()

void view_full_screen_resize ( Init * init)

Resize the full screen view and its components.

Parameters
initPointer to the Init structure containing view settings.

This function resizes the full screen view and its components, including the command line window, line number window, and main content pad. It also recalculates the dimensions for the full screen mode and updates the scroll regions accordingly.

Definition at line 115 of file init_view.c.

115 {
116 erase();
117 wnoutrefresh(stdscr);
118 wrefresh(stdscr);
120 mvwin(view->cmdln_win, view->lines - 1, 0);
121 wresize(view->cmdln_win, 1, view->cols);
122 wnoutrefresh(view->cmdln_win);
123
124 // wresize(view->ln_win, view->ln_win_lines, view->ln_win_cols);
125 wresize(view->ln_win, view->ln_win_lines - 1, view->ln_win_cols);
126 wsetscrreg(view->ln_win, 0, view->scroll_lines - 1);
127 wnoutrefresh(view->ln_win);
128
129 wresize(view->pad, view->lines - 1, PAD_COLS);
130 wsetscrreg(view->pad, 0, view->lines - 1);
131}
Init * init
Definition init.c:74
#define PAD_COLS
Definition view.h:30
View * view
Definition mem.c:48
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:140

References View::cmdln_win, View::cols, View::lines, View::ln_win, View::ln_win_cols, View::ln_win_lines, View::pad, View::scroll_lines, view, and view_calc_full_screen_dimensions().

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view_win_resize()

void view_win_resize ( Init * init,
char * title )

Resize the current window and its box, and update the title.

Parameters
initPointer to the Init structure containing view settings.
titleWindow title

This function resizes the current window and its associated box window to the specified number of lines and columns. It also updates the title of the box window if a title is provided. After resizing, it refreshes the windows to apply the changes.

Definition at line 265 of file init_view.c.

265 {
266 int maxx;
267 erase();
268 wnoutrefresh(stdscr);
269 wrefresh(stdscr);
271#ifdef DEBUG_RESIZE
272 ssnprintf(em0, MAXLEN - 1, "view->box: begy=%d, begx=%d, lines=%d, cols=%d",
273 view->begy, view->begx, view->lines + 2, view->cols + 2);
275#endif
276 mvwin(view->box, view->begy, view->begx);
277 wresize(view->box, view->lines + 2, view->cols + 2);
278 wbkgrnd(view->box, &CCC_BOX);
279 wbkgrndset(view->box, &CCC_BOX);
280 cbox(view->box);
281 if (title != nullptr && *title != '\0') {
282 wmove(view->box, 0, 1);
283 waddnstr(view->box, (const char *)&bw_rt, 1);
284 wmove(view->box, 0, 2);
285 waddnstr(view->box, (const char *)&bw_sp, 1);
286 mvwaddnwstr(view->box, 0, 1, &bw_rt, 1);
287 mvwaddnwstr(view->box, 0, 2, &bw_sp, 1);
288 int len = strlen(title);
289 if (len > (view->cols - 4)) {
290 len -= (view->cols - 4);
291 mvwaddstr(view->box, 0, 3, &title[len]);
292 } else
293 mvwaddstr(view->box, 0, 3, title);
294 maxx = getmaxx(view->box);
295 int s = strlen(title);
296 if ((s + 3) < maxx)
297 mvwaddch(view->box, 0, (s + 3), ' ');
298 if ((s + 4) < maxx)
299 mvwaddnwstr(view->box, 0, (s + 4), &bw_lt, 1);
300 }
301 wnoutrefresh(view->box);
302#ifdef DEBUG_RESIZE
303 ssnprintf(em0, MAXLEN - 1,
304 "view->cmdln_win: begy=%d, begx=%d, lines=%d, cols=%d",
305 view->begy + view->lines, view->begx + 1, 1, view->cols);
307#endif
308 mvwin(view->cmdln_win, view->begy + view->lines, view->begx + 1);
309 wresize(view->cmdln_win, 1, view->cols);
310 wnoutrefresh(view->cmdln_win);
311#ifdef DEBUG_RESIZE
312 ssnprintf(em0, MAXLEN - 1,
313 "(285)view->ln_win: begy=%d, begx=%d, lines=%d, cols=%d, "
314 "scroll_lines %d",
315 view->begy + 1, view->begx + 1, view->ln_win_lines + 2,
316 view->ln_win_cols, view->scroll_lines);
318#endif
319 if (view->f_ln) {
320 if (view->ln_win == nullptr) {
321 view->ln_win = newwin(view->ln_win_lines, view->ln_win_cols,
322 view->begy + 1, view->begx + 1);
323 keypad(view->ln_win, false);
324 idlok(view->ln_win, false);
325 idcok(view->ln_win, false);
326 wbkgrnd(view->ln_win, &CCC_LN);
327 wbkgrndset(view->ln_win, &CCC_LN);
328 scrollok(view->ln_win, true);
329 wsetscrreg(view->ln_win, 0, view->scroll_lines - 1);
330#ifdef DEBUG_IMMEDOK
331 immedok(view->ln_win, true);
332#endif
333 } else {
334 mvwin(view->ln_win, view->begy + 1, view->begx + 1);
335 wresize(view->ln_win, view->ln_win_lines, view->ln_win_cols);
336 wsetscrreg(view->ln_win, 0, view->scroll_lines);
337 wnoutrefresh(view->ln_win);
338 }
339 } else if (view->ln_win != nullptr) {
340 delwin(view->ln_win);
341 view->ln_win = nullptr;
342 }
343 view->sminrow = view->begy + 1;
344 view->smincol = view->begx + 1;
345 view->smaxrow = view->begy + view->lines;
346 view->smaxcol = view->begx + view->cols;
347#ifdef DEBUG_RESIZE
348 ssnprintf(em0, MAXLEN - 1,
349 "view->pad: sminrow=%d, smincol=%d, smaxrow=%d, smaxcol=%d",
350 view->sminrow, view->smincol, view->smaxrow, view->smaxcol);
352#endif
353 wresize(view->pad, view->lines - 1, PAD_COLS);
354 wsetscrreg(view->pad, 0, view->scroll_lines);
355}
void write_cmenu_log_nt(char *)
Write message to C-Menu log file without timestamp.
Definition futil.c:1562
void view_calc_win_dimensions(Init *, char *title)
Calculate the dimensions and position of the box window for C-Menu View.
Definition init_view.c:367

References View::begx, View::begy, View::box, bw_lt, bw_rt, bw_sp, cbox(), CCC_BOX, CCC_LN, View::cmdln_win, View::cols, View::f_ln, View::lines, View::ln_win, View::ln_win_cols, View::ln_win_lines, View::pad, View::scroll_lines, View::smaxcol, View::smaxrow, View::smincol, View::sminrow, view, and view_calc_win_dimensions().

Referenced by view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ win2_new()

int win2_new ( int wlines,
int wcols,
int wbegy,
int wbegx )

Create a new window with specified dimensions and position.

win2_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
wbegyBeginning Y position
wbegxBeginning X position
Returns
0 if successful, 1 if error

Definition at line 814 of file dwin.c.

814 {
815 wbegy += 1;
816 wbegx += 1;
817 win_win2[win_ptr] = newwin(wlines, wcols, wbegy, wbegx);
818 if (win_win2[win_ptr] == nullptr) {
819 delwin(win_box[win_ptr]);
820 return 1;
821 }
822#ifdef DEBUG_IMMEDOK
823 immedok(win_win2[win_ptr], true);
824#endif
825 wbkgrndset(win_win2[win_ptr], &CCC_NT);
826 keypad(win_win2[win_ptr], true);
827 idlok(win_win2[win_ptr], false);
828 idcok(win_win2[win_ptr], false);
829 return 0;
830}

References CCC_NT, win_box, win_ptr, and win_win2.

Referenced by box2_new().

Here is the caller graph for this function:

◆ win_del()

WINDOW * win_del ( )

Delete the current window and its associated box window.

win_del

Returns
nullptr

This function deletes the current window and its associated box window, if they exist. It also refreshes the remaining windows to ensure the display is updated correctly. After calling this function, the global win_ptr variable is decremented to point to the previous window in the stack.

Definition at line 893 of file dwin.c.

893 {
894 int i;
895 curs_set(0);
896 if (win_ptr >= 0) {
897 if (win_win[win_ptr] != nullptr) {
898 touchwin(win_win[win_ptr]);
899 wbkgrndset(win_win[win_ptr], &CCC_NT);
900 werase(win_win[win_ptr]);
901 wnoutrefresh(win_win[win_ptr]);
902 delwin(win_win[win_ptr]);
903 }
904 if (win_box[win_ptr] != nullptr) {
905 touchwin(win_box[win_ptr]);
906 wbkgrndset(win_box[win_ptr], &CCC_NT);
907 werase(win_box[win_ptr]);
908 wnoutrefresh(win_box[win_ptr]);
909 delwin(win_box[win_ptr]);
910 }
911 for (i = 0; i < win_ptr; i++) {
912 if (win_box[i] != nullptr) {
913 touchwin(win_box[i]);
914 wnoutrefresh(win_box[i]);
915 }
916 if (win_win[i] == nullptr)
917 continue;
918 touchwin(win_win[i]);
919 wnoutrefresh(win_win[i]);
920 }
921 win_ptr--;
922 }
923 return 0;
924}

References CCC_NT, win_box, win_ptr, and win_win.

Referenced by action_disposition(), answer_yn(), display_error(), init_form(), init_pick(), menu_engine(), Perror(), popup_ckeys(), popup_view(), and wait_destroy().

Here is the caller graph for this function:

◆ win_init_attrs()

void win_init_attrs ( )

Initialize window attributes.

This function initializes color pairs for the window cp_norm, cp_win, and cp_box are global variables

Definition at line 176 of file dwin.c.

176{ return; }

Referenced by main().

Here is the caller graph for this function:

◆ win_new()

int win_new ( int wlines,
int wcols,
int wbegy,
int wbegx )

Create a new window with specified dimensions and position.

win_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
wbegyBeginning Y position
wbegxBeginning X position
Returns
0 if successful, 1 if error

Definition at line 788 of file dwin.c.

788 {
789 wbegy += 1;
790 wbegx += 1;
791 win_win[win_ptr] = newwin(wlines, wcols, wbegy, wbegx);
792 if (win_win[win_ptr] == nullptr) {
793 delwin(win_box[win_ptr]);
794 return 1;
795 }
796#ifdef DEBUG_IMMEDOK
797 immedok(win_win[win_ptr], true);
798#endif
799 wbkgrndset(win_win[win_ptr], &CCC_NT);
800 keypad(win_win[win_ptr], true);
801 idlok(win_win[win_ptr], false);
802 idcok(win_win[win_ptr], false);
803 scrollok(win_win[win_ptr], true);
804 return 0;
805}

References CCC_NT, win_box, win_ptr, and win_win.

Referenced by box2_new(), and box_new().

Here is the caller graph for this function:

◆ win_redraw()

void win_redraw ( WINDOW * win)

Redraw the specified window.

win_redraw

Parameters
winPointer to the window to redraw

This function erases the contents of the specified window and then refreshes it to update the display. Use this function when you need to clear and redraw a window, such as after resizing or when updating its contents.

Definition at line 881 of file dwin.c.

881 {
882 werase(win);
883 wnoutrefresh(win);
884}
WINDOW * win
Definition dwin.c:121

◆ win_resize()

void win_resize ( int wlines,
int wcols,
char * title )

Resize the current window and its box, and update the title.

win_resize

Parameters
wlinesNumber of lines
wcolsNumber of columns
titleWindow title

This function resizes the current window and its associated box window to the specified number of lines and columns. It also updates the title of the box window if a title is provided. After resizing, it refreshes the windows to apply the changes.

Definition at line 841 of file dwin.c.

841 {
842 int maxx;
843 wrefresh(stdscr);
844 wresize(win_box[win_ptr], wlines + 2, wcols + 2);
845 wbkgrndset(win_box[win_ptr], &CCC_BOX);
847 if (title != nullptr && *title != '\0') {
848 wmove(win_box[win_ptr], 0, 1);
849 waddnstr(win_box[win_ptr], (const char *)&bw_rt, 1);
850 wmove(win_box[win_ptr], 0, 2);
851 waddnstr(win_box[win_ptr], (const char *)&bw_sp, 1);
852 mvwaddnwstr(win_box[win_ptr], 0, 1, &bw_rt, 1);
853 mvwaddnwstr(win_box[win_ptr], 0, 2, &bw_sp, 1);
854 mvwaddstr(win_box[win_ptr], 0, 3, title);
855 maxx = getmaxx(win_box[win_ptr]);
856 int s = strlen(title);
857 if ((s + 3) < maxx)
858 mvwaddch(win_box[win_ptr], 0, (s + 3), ' ');
859 if ((s + 4) < maxx)
860 mvwaddnwstr(win_box[win_ptr], 0, (s + 4), &bw_lt, 1);
861 }
862 wnoutrefresh(win_box[win_ptr]);
863 wresize(win_win[win_ptr], wlines, wcols);
864 wbkgrndset(win_win[win_ptr], &CCC_NT);
865 wsetscrreg(win_win[win_ptr], 0, wlines - 1);
866 keypad(win_win[win_ptr], TRUE);
867 idlok(win_win[win_ptr], false);
868 idcok(win_win[win_ptr], false);
869 scrollok(win_win[win_ptr], true);
870#ifdef DEBUG_IMMEDOK
871 immedok(win_win[win_ptr], true);
872#endif
873}
#define TRUE
Definition iloan.c:19

References bw_lt, bw_rt, bw_sp, cbox(), CCC_BOX, CCC_NT, win_box, win_ptr, and win_win.

Here is the call graph for this function:

◆ xwgetch()

int xwgetch ( WINDOW * win,
Chyron * chyron,
int n )

Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line, and accepts a sinigle character answer.

xwgetch

Parameters
winPointer to window
chyronPointer to chyron struct
nNumber of seconds to wait before timing out
     0: Wait indefinitely for user input (raw mode)
         accept a single character answer, and don't wait for Enter key
     1: Wait for 1 decisecond
     n > 1: Wait for n/10 seconds
Returns
Key code or ERR if interrupted by signal

Get mouse event and check if it's a left click or double click. If the click is outside the window, ignore it. If it's on the chyron line, get the corresponding key command. Otherwise, store the click coordinates as click_y and click_x for later use.

Definition at line 1651 of file dwin.c.

1651 {
1652 int c;
1653 MEVENT event;
1654 mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON4_PRESSED |
1655 BUTTON5_PRESSED,
1656 nullptr);
1657 click_y = event.y = -1;
1658 click_x = event.x = -1;
1659
1660 if (n == -1) {
1661 struct termios raw_tioctl;
1662 raw_tioctl = curses_tioctl;
1663 mk_raw_tioctl(&raw_tioctl);
1664 } else if (n == 0)
1665 halfdelay(1);
1666 else
1667 halfdelay(min(255, max(0, n * 10)));
1668 tcflush(2, TCIFLUSH);
1669 curs_set(1);
1670 do {
1671 c = wgetch(win);
1672 if (sig_received != 0) {
1674 c = display_error(em0, em1, em2, nullptr);
1675 if (c == 'q' || c == 'Q' || c == KEY_F(9))
1676 exit(EXIT_FAILURE);
1677 }
1678 if (n > 0 && c == ERR) {
1679 c = 0;
1680 break;
1681 }
1682 if (c == ERR)
1683 continue;
1684 if (c == KEY_MOUSE) {
1685 if (getmouse(&event) != OK) {
1686 c = 0;
1687 continue;
1688 }
1689 if (event.bstate & BUTTON4_PRESSED) {
1690 curs_set(0);
1691 return KEY_UP;
1692 } else if (event.bstate & BUTTON5_PRESSED) {
1693 curs_set(0);
1694 return KEY_DOWN;
1695 }
1696 if (event.bstate & BUTTON1_CLICKED ||
1697 event.bstate & BUTTON1_DOUBLE_CLICKED) {
1698 if (wenclose(win, event.y, event.x)) {
1699 wmouse_trafo(win, &event.y, &event.x, false);
1700 click_y = event.y;
1701 click_x = event.x;
1702 if (chyron && event.y == getmaxy(win) - 1) {
1703 c = get_chyron_key(chyron, event.x);
1704 break;
1705 }
1706 }
1707 c = ERR;
1708 continue;
1709 }
1710 }
1711 } while (c == ERR);
1712 curs_set(0);
1714 return c;
1715}
volatile sig_atomic_t sig_received
Definition sig.c:31
bool handle_signal(sig_atomic_t)
struct termios shell_tioctl curses_tioctl
Definition scriou.c:34
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:49
char em1[MAXLEN]
Definition dwin.c:142
int click_x
Definition dwin.c:49
int click_y
Definition dwin.c:48
char em2[MAXLEN]
Definition dwin.c:143
int display_error(char *em0, char *em1, char *em2, char *em3)
Display an error message window or print to stderr.
Definition dwin.c:1102
int get_chyron_key(Chyron *, int)
Get keycode from chyron.
Definition dwin.c:1499
bool restore_curses_tioctl()
restore_curses_tioctl() - restore curses terminal settings
Definition scriou.c:81
bool mk_raw_tioctl(struct termios *)
mk_raw_tioctl() - set terminal to raw mode
Definition scriou.c:126

References click_x, click_y, curses_tioctl, display_error(), em0, em1, em2, get_chyron_key(), handle_signal(), mk_raw_tioctl(), restore_curses_tioctl(), and sig_received.

Referenced by action_disposition(), answer_yn(), display_error(), field_editor(), form_post(), form_process(), get_cmd_arg(), get_cmd_char(), menu_cmd_processor(), Perror(), remove_file(), and wait_continue().

Here is the call graph for this function:
Here is the caller graph for this function: