C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
popups.c
Go to the documentation of this file.
1/** @file popups.c
2 @brief functions to create popup windows
3 @author Bill Waller
4 @date 2026-03
5 @details This file contains functions to create popup windows for menu,
6 form, pick, and view. The functions in this file are called by the main
7 function in main.c when the user selects a menu option that requires a popup
8 window. The functions in this file also handle command line arguments that
9 may be passed to the popup windows, such as the number of lines and columns
10 for the view window, and the y and x coordinates for the popup windows. The
11 functions in this file also save the current state of the popup windows
12 before creating a new one, and restore the state after the popup window is
13 closed. The functions in this file also call the appropriate functions to
14 initialize and destroy the popup windows, and to handle the user input for
15 the popup windows. The functions in this file also return the appropriate
16 return codes to the main function in main.c, which will determine how to
17 proceed based on the return codes. The functions in this file also handle any
18 errors that may occur during the creation and handling of the popup windows,
19 and will return appropriate error codes to the main function in main.c, which
20 will determine how to proceed based on the error codes. The functions in this
21 file also handle any cleanup that may be necessary after the popup windows
22 are closed, such as freeing memory and resetting variables. The functions in
23 this file also handle any necessary updates to the main window after the
24 popup windows are closed, such as refreshing the main window and updating any
25 relevant data.
26*/
27
28#include "common.h"
29
30int popup_menu(Init *, int, char **, int, int);
31int popup_form(Init *, int, char **, int, int);
32int popup_pick(Init *, int, char **, int, int);
33int popup_view(Init *, int, char **, int, int, int, int);
34
35/** @brief instantiate a menu popup window
36 @param init the Init struct pointer
37 @param argc the number of command line arguments
38 @param argv the command line arguments
39 @param by the y coordinate for the menu window
40 @param bx the x coordinate for the menu window
41 @details by and bx may be set as command line option arguments, in which
42 case, they will take precedence over arguments passed in the function
43 arguments.
44 @verbatim
45 by, and bx may be set by
46 1. the calling function
47 or
48 2. command line arguments
49 Non-zero command line arguments will override the calling function's
50 arguments.
51 @endverbatim
52*/
53int popup_menu(Init *init, int argc, char **argv, int by, int bx) {
54 int rc;
56 parse_opt_args(init, argc, argv);
57 Menu *sav_menu = init->menu;
58 init->menu = nullptr;
59 init->menu = new_menu(init, init->argc, init->argv, by, bx);
60 rc = menu_engine(init);
62 init->menu = sav_menu;
63 return rc;
64}
65/** @brief instantiate a pick popup window
66 @param init the Init struct pointer
67 @param argc the number of command line arguments
68 @param argv the command line arguments
69 @param by the y coordinate for the pick window
70 @param bx the x coordinate for the pick window
71 @details by and bx may be set as command line option arguments, in which
72 case, they will take precedence over arguments passed in the function
73 arguments.
74 @verbatim
75 by, and bx may be set by
76 1. the calling function
77 or
78 2. command line arguments
79 Non-zero command line arguments will override the calling function's
80 arguments.
81 @endverbatim
82*/
83int popup_pick(Init *init, int argc, char **argv, int by, int bx) {
84 int rc;
86 parse_opt_args(init, argc, argv);
87 Pick *sav_pick = init->pick;
88 init->pick = nullptr;
89 rc = init_pick(init, init->argc, init->argv, by, bx);
91 init->pick = sav_pick;
92 return rc;
93}
94/** @brief instantiate a form popup window
95 @param init the Init struct pointer
96 @param argc the number of command line arguments
97 @param argv the command line arguments
98 @param by the y coordinate for the form window
99 @param bx the x coordinate for the form window
100 @details by and bx may be set as command line option arguments, in which
101 case, they will take precedence over arguments passed in the function
102 arguments.
103 @verbatim
104 by, and bx may be set by
105 1. the calling function
106 or
107 2. command line arguments
108 Non-zero command line arguments will override the calling function's
109 arguments.
110 @endverbatim
111*/
112int popup_form(Init *init, int argc, char **argv, int by, int bx) {
113 int rc;
114 zero_opt_args(init);
115 parse_opt_args(init, argc, argv);
116 Form *sav_form = init->form;
117 init->form = nullptr;
118 rc = init_form(init, init->argc, init->argv, by, bx);
119 destroy_form(init);
120 init->form = sav_form;
121 return rc;
122}
123
124/** @brief instantiate a view popup window
125 @param init the Init struct pointer
126 @param argc the number of command line arguments
127 @param argv the command line arguments
128 @param ilines the number of lines for the view window
129 @param icols the number of columns for the view window
130 @param by the y coordinate for the view window
131 @param bx the x coordinate for the view window
132 @details ilines, cols, by, and bx may also be set as command line option
133 arguments, in which case, they will take precedence over arguments passed in
134 the function arguments.
135 @verbatim
136 ilines, cols, by, and bx may be set by
137 1. the calling function
138 or
139 2. command line arguments
140 Non-zero command line arguments will override the calling function's
141 arguments.
142 @endverbatim
143*/
144int popup_view(Init *init, int argc, char **argv, int ilines, int icols, int by,
145 int bx) {
146 int rc = 0;
147 zero_opt_args(init);
148 parse_opt_args(init, argc, argv);
149 // view_stack_push(&view_stack, *init->view);
150 View *view_sav = init->view;
151 init->view = nullptr;
152 View *view = nullptr;
153 view = nullptr;
154 view = new_view(init);
155
156 if (init->lines > 0 && init->cols > 0) {
157 ilines = init->lines;
158 icols = init->cols;
159 }
160 if (init->begy > 0 || init->begx > 0) {
161 by = init->begy;
162 bx = init->begx;
163 }
164 view->begy = by;
165 view->begx = bx;
166 view->lines = ilines;
167 view->cols = icols;
168 view->f_full_screen = false;
169 if (!init_view_boxwin(init))
170 rc = view_file(init);
171 destroy_view(init);
172 init->view = view_sav;
173 // view_stack_pop(&view_stack, init->view);
174 return rc;
175}
int popup_form(Init *, int, char **, int, int)
instantiate a form popup window
Definition popups.c:112
int popup_menu(Init *, int, char **, int, int)
instantiate a menu popup window
Definition popups.c:53
int popup_view(Init *, int, char **, int, int, int, int)
instantiate a view popup window
Definition popups.c:144
int popup_pick(Init *, int, char **, int, int)
instantiate a pick popup window
Definition popups.c:83
int init_form(Init *, int, char **, int, int)
Initialize form data structure and parse description file.
Definition form_engine.c:61
int parse_opt_args(Init *, int, char **)
Parse command-line options and set Init struct values accordingly.
Definition init.c:559
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
Definition init.c:574
int init_view_boxwin(Init *)
Initialize the C-Menu View in box window mode.
Definition init_view.c:194
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:356
Menu * new_menu(Init *, int, char **, int, int)
Create and initialize Menu structure.
Definition mem.c:145
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:166
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:286
View * new_view(Init *)
Create and initialize View structure.
Definition mem.c:310
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:236
unsigned int menu_engine(Init *)
The main loop of the menu system.
Definition menu_engine.c:38
int init_pick(Init *, int, char **, int, int)
Initializes pick structure and opens pick input file or pipe.
Definition pick_engine.c:66
int view_file(Init *)
Start view.
int begx
Definition common.h:118
Form * form
Definition common.h:184
int argc
Definition common.h:130
int cols
Definition common.h:116
int begy
Definition common.h:117
View * view
Definition common.h:188
Menu * menu
Definition common.h:182
char ** argv
Definition common.h:131
int lines
Definition common.h:115
Pick * pick
Definition common.h:186
int cols
Definition view.h:54
bool f_full_screen
Definition view.h:104
int lines
Definition view.h:53
int begy
Definition view.h:55
int begx
Definition view.h:56