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

Manage NCurses windows and color settings. More...

Functions

int border_title (UiSurface *sfc, char *title)
 Draw a box with a title around the specified window.
int border_ysplit (UiSurface *sfc, uint y)
 Draw a box with a separator line around the specified window.
int border_ysplit_text (UiSurface *sfc, char *text, uint separator_line)
 Draw a box with a separator line and text around the specified window.
int cm_surface_destroy (UiSurface *sfc)
 Destroy the most recently created surface.
void destroy_curses ()
 Gracefully shut down NCurses and restore terminal settings.
void view_boxwin_resize (Init *init)
 Resize the current window and its box.
void view_full_screen_resize (Init *init)
 Resize the full screen view and its components.

Detailed Description

Manage NCurses windows and color settings.

Function Documentation

◆ border_title()

int border_title ( UiSurface * sfc,
char * title )

Draw a box with a title around the specified window.

border_title

Parameters
boxPointer to the window to draw the box around
titleTitle text to display at the top of the box

This function draws a box around the specified window, similar to border_draw(), but it also includes a title at the top of the box. The title is displayed in the center of the top edge of the box, and the horizontal line is drawn on either side of the title. Use this function when you want to visually label a window with a title.

Definition at line 676 of file dwin.c.

676 {
677 if (!title || !*title)
678 return 0;
679 uint y = 0;
680 uint x = 0;
681 uint l;
682 uint maxx = ui_getmaxx(sfc, BOX);
683 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_tl, 1);
684 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_rt, 1);
685 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_sp, 1);
686 wchar_t *title_wc;
687 title_wc = mbstr_to_wcstr(title);
688 l = wcswidth(title_wc, wcslen(title_wc));
689 l = min(l, maxx - 7);
690 ui_bkgdset(sfc, BOX, &cell_title);
691 ui_mvwaddnwstr(sfc, BOX, y, x, title_wc, l);
692 ui_bkgdset(sfc, BOX, &cell_box);
693 x += l;
694 free(title_wc);
695 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_sp, 1);
696 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_lt, 1);
697 while (x < maxx - 1)
698 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_ho, 1);
699 ui_render();
700 return 0;
701}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:91
int ui_getmaxx(UiSurface *s, uint w)
Definition ui_ncurses.c:686
void ui_render()
Definition ui_ncurses.c:800
int ui_bkgdset(UiSurface *s, uint w, const UiCell *cell)
Definition ui_ncurses.c:760
int ui_mvwaddnwstr(UiSurface *s, uint w, uint y, uint x, const wchar_t *wstr, int m)
int ui_mvwadd_wchnstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell, uint m)
UiCell cell_sp
Definition dwin.c:120
UiCell cell_tl
Definition dwin.c:109
wchar_t * mbstr_to_wcstr(const char *mb_str)
Definition dwin.c:404
UiCell cell_ho
Definition dwin.c:111
UiCell cell_lt
Definition dwin.c:115
UiCell cell_title
Definition dwin.c:101
UiCell cell_box
Definition dwin.c:98
UiCell cell_rt
Definition dwin.c:116

References BOX, cell_box, cell_ho, cell_lt, cell_rt, cell_sp, cell_title, cell_tl, mbstr_to_wcstr(), ui_bkgdset(), ui_getmaxx(), ui_mvwadd_wchnstr(), ui_mvwaddnwstr(), and ui_render().

Referenced by new_view_file(), ui_box_surface_new(), ui_box_surface_new(), view_boxwin_resize(), and view_file().

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

◆ border_ysplit()

int border_ysplit ( UiSurface * sfc,
uint y )

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

border-ysplit

Parameters
boxPointer to the window to draw the box around
yLine number where the separator line should be drawn

This function draws a box around the specified window, similar to border_draw(), 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 617 of file dwin.c.

617 {
618 uint maxx = ui_getmaxx(sfc, BOX);
619 ui_mvwadd_wchnstr(sfc, BOX, y, 0, &cell_lt, 1);
620 for (uint x = 1; x < maxx - 1; x++)
621 ui_mvwadd_wchnstr(sfc, BOX, y, x, &cell_ho, 1);
622 ui_mvwadd_wchnstr(sfc, BOX, y, maxx - 1, &cell_rt, 1);
623 return 0;
624}

References BOX, cell_ho, cell_lt, cell_rt, ui_getmaxx(), and ui_mvwadd_wchnstr().

Referenced by surface_split_box_win_new().

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

◆ border_ysplit_text()

int border_ysplit_text ( UiSurface * sfc,
char * text,
uint separator_line )

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

border_ysplit_text

Parameters
boxPointer to the window to draw the box around
textText to display in the middle of the separator line
separator_lineLine number where the separator line should be drawn

This function draws a box around the specified window, similar to border_draw(), but it also includes a horizontal separator line that divides the box into two sections. The separator line is drawn at the specified line number and extends across the width of the box, with the provided text displayed in the middle of the line. Use this function when you want to visually separate two sections within a window and label the separator with descriptive text.

Definition at line 637 of file dwin.c.

637 {
638 uint maxx = ui_getmaxx(sfc, BOX);
639 uint l;
640 uint y = separator_line;
641 uint x = 0;
642 // Draw the horizontal line with text in the middle, so we start by drawing
643 // the left edge, then the text, then the right edge, and finally fill in the
644 // horizontal line on either side of the text.
645 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_lt, 1);
646 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_ho, 1);
647 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_rt, 1);
648 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_sp, 1);
649 strnz(text, maxx - 7);
650 wchar_t *text_wc;
651 text_wc = mbstr_to_wcstr(text);
652 l = wcswidth(text_wc, wcslen(text_wc));
653 ui_bkgdset(sfc, BOX, &cell_nt_hl);
654 ui_mvwaddnwstr(sfc, BOX, y, x, text_wc, l);
655 x += l;
656 l = min(l, maxx - 7);
657 free(text_wc);
658 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_sp, 1);
659 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_lt, 1);
660
661 while (x < maxx - 1)
662 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_ho, 1);
663 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_rt, 1);
664 return 0;
665}
UiCell cell_nt_hl
Definition dwin.c:96
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:608

References BOX, cell_ho, cell_lt, cell_nt_hl, cell_rt, cell_sp, mbstr_to_wcstr(), strnz(), ui_bkgdset(), ui_getmaxx(), ui_mvwadd_wchnstr(), and ui_mvwaddnwstr().

Referenced by picker().

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

◆ cm_surface_destroy()

int cm_surface_destroy ( UiSurface * sfc)

Destroy the most recently created surface.

cm_destroy_surface

Returns
0 on success, -1 if no surfaces exist

This function destroys the most recently created surface and decrements the surface pointer. It should be called when a surface is no longer needed to free up resources. If there are no surfaces to destroy, it returns -1.

Note
The difference between this function and ui_surface_destroy() is that this function destroys the surface pointed to by the surface pointer (sfc_ptr) and decrements the surface pointer after destroying the surface.

Definition at line 576 of file dwin.c.

576 {
578 sfc_ptr--;
579 return 0;
580}
void ui_surface_destroy(UiSurface *s)
Definition ui_ncurses.c:377
int sfc_ptr
Definition nckeys.c:47

References sfc_ptr, and ui_surface_destroy().

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

Here is the call graph for this function:
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, 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 384 of file dwin.c.

384 {
385 if (!f_curses_open)
386 return;
387 ui_shutdown();
388 f_curses_open = false;
390 sig_dfl_mode();
391 return;
392}
bool f_curses_open
Definition sig.c:33
void ui_shutdown()
Definition ui_ncurses.c:344
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:57
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:42

References f_curses_open, restore_shell_tioctl(), sig_dfl_mode(), and ui_shutdown().

Referenced by abend(), and main().

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

◆ view_boxwin_resize()

void view_boxwin_resize ( Init * init)

Resize the current window and its box.

Parameters
initPointer to the Init structure containing view settings.

This function resizes the current window and its associated box window to the specified number of lines and columns.

Definition at line 178 of file init_view.c.

178 {
179 View *view = init->view;
181 ui_render();
182 init_view_boxwin(init);
183 border_title(init->view->sfc, init->view->title);
184 // initialize_line_table(init->view);
185}
View * view
Definition mem.c:38
int border_title(UiSurface *sfc, char *title)
Draw a box with a title around the specified window.
Definition dwin.c:676
int init_view_boxwin(Init *init)
Initialize the C-Menu View in box window mode.
Definition init_view.c:147
View * view
Definition common.h:189
Definition view.h:61
char title[MAXLEN]
Definition view.h:81
UiSurface * sfc
Definition view.h:101

References border_title(), init_view_boxwin(), View::sfc, View::title, ui_render(), ui_surface_destroy(), and Init::view.

Referenced by view_cmd_processor().

Here is the call graph for this function:
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 97 of file init_view.c.

97 {
98 ui_erase();
100 View *view = init->view;
102 ui_render();
104}
int ui_erase()
Definition ui_ncurses.c:590
int init_view_full_screen(Init *init)
Initialize C-Menu View in full screen mode.
Definition init_view.c:47
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:113

References init_view_full_screen(), View::sfc, ui_erase(), ui_render(), ui_surface_destroy(), Init::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: