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 **, uint, uint);
31int popup_form(Init *, int, char **, uint, uint);
32int popup_pick(Init *, int, char **, uint, uint);
33int popup_view(Init *, int, char **, uint, uint, uint, uint);
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, uint by, uint 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, uint by, uint bx) {
84 int rc;
86 parse_opt_args(init, argc, argv);
87 Pick *sav_pick = init->pick;
88 init->pick = nullptr;
89
90 rc = init_pick(init, init->argc, init->argv, by, bx);
92 init->pick = sav_pick;
93 return rc;
94}
95/** @brief instantiate a form popup window
96 @param init the Init struct pointer
97 @param argc the number of command line arguments
98 @param argv the command line arguments
99 @param by the y coordinate for the form window
100 @param bx the x coordinate for the form window
101 @details by and bx may be set as command line option arguments, in which
102 case, they will take precedence over arguments passed in the function
103 arguments.
104 @verbatim
105 by, and bx may be set by
106 1. the calling function
107 or
108 2. command line arguments
109 Non-zero command line arguments will override the calling function's
110 arguments.
111 @endverbatim
112*/
113int popup_form(Init *init, int argc, char **argv, uint by, uint bx) {
114 int rc;
115 zero_opt_args(init);
116 parse_opt_args(init, argc, argv);
117 Form *sav_form = init->form;
118 init->form = nullptr;
119 rc = init_form(init, init->argc, init->argv, by, bx);
120 destroy_form(init);
121 init->form = sav_form;
122 return rc;
123}
124
125/** @brief instantiate a view popup window
126 @param init the Init struct pointer
127 @param argc the number of command line arguments
128 @param argv the command line arguments
129 @param ilines the number of lines for the view window
130 @param icols the number of columns for the view window
131 @param by the y coordinate for the view window
132 @param bx the x coordinate for the view window
133 @details ilines, cols, by, and bx may also be set as command line option
134 arguments, in which case, they will take precedence over arguments passed in
135 the function arguments.
136 @verbatim
137 ilines, cols, by, and bx may be set by
138 1. the calling function
139 or
140 2. command line arguments
141 Non-zero command line arguments will override the calling function's
142 arguments.
143 @endverbatim
144*/
145int popup_view(Init *init, int argc, char **argv, uint ilines, uint icols, uint by,
146 uint bx) {
147 int rc = 0;
148 zero_opt_args(init);
149 parse_opt_args(init, argc, argv);
150 // view_stack_push(&view_stack, *init->view);
151 View *view_sav = init->view;
152 init->view = nullptr;
153 View *view = nullptr;
154 view = nullptr;
155 view = new_view(init);
156
157 if (init->lines > 0 && init->cols > 0) {
158 ilines = init->lines;
159 icols = init->cols;
160 }
161 if (init->begy > 0 || init->begx > 0) {
162 by = init->begy;
163 bx = init->begx;
164 }
165 view->begy = by;
166 view->begx = bx;
167 view->lines = ilines;
168 view->cols = icols;
169 view->f_full_screen = false;
170 if (!init_view_boxwin(init))
171 rc = view_file(init);
172 destroy_view(init);
173 init->view = view_sav;
174 // view_stack_pop(&view_stack, init->view);
175 return rc;
176}
int popup_form(Init *, int, char **, uint, uint)
instantiate a form popup window
Definition popups.c:113
int popup_menu(Init *, int, char **, uint, uint)
instantiate a menu popup window
Definition popups.c:53
int popup_pick(Init *, int, char **, uint, uint)
instantiate a pick popup window
Definition popups.c:83
int popup_view(Init *, int, char **, uint, uint, uint, uint)
instantiate a view popup window
Definition popups.c:145
int init_form(Init *, int, char **, uint, uint)
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:591
void zero_opt_args(Init *)
Initialize optional arguments in the Init struct to default values.
Definition init.c:606
int init_view_boxwin(Init *init)
Initialize the C-Menu View in box window mode.
Definition init_view.c:147
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:345
Menu * new_menu(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Menu structure.
Definition mem.c:134
Menu * destroy_menu(Init *init)
Destroy Menu structure.
Definition mem.c:155
Form * destroy_form(Init *init)
Destroy Form structure.
Definition mem.c:275
View * new_view(Init *init)
Create and initialize View structure.
Definition mem.c:299
Pick * destroy_pick(Init *init)
Destroy Pick structure.
Definition mem.c:225
unsigned int menu_engine(Init *)
The main loop of the menu system.
Definition menu_engine.c:36
int init_pick(Init *, int, char **, uint, uint)
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:185
int argc
Definition common.h:130
int cols
Definition common.h:116
int begy
Definition common.h:117
View * view
Definition common.h:189
Menu * menu
Definition common.h:183
char ** argv
Definition common.h:131
int lines
Definition common.h:115
Pick * pick
Definition common.h:187
uint lines
Definition view.h:72
uint begx
Definition view.h:75
bool f_full_screen
Definition view.h:120
uint cols
Definition view.h:73
uint begy
Definition view.h:74