C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Chyron Management

Create and manage the Chyron. More...

Functions

Chyronnew_chyron ()
 Create and initialize Chyron structure.
Chyrondestroy_chyron (Chyron *chyron)
 Destroy Chyron structure.
bool is_set_chyron_key (Chyron *chyron, int k)
 Check if function key label is set.
void set_chyron_key_cp (Chyron *chyron, int k, char *s, int kc, int cp)
 Set chyron key.
void unset_chyron_key (Chyron *chyron, int k)
 Unset chyron key.
void compile_chyron (Chyron *chyron)
 construct the chyron string from the chyron structure
int mb_to_cc (cchar_t *cmplx_buf, char *str, attr_t attr, int cpx, int *pos, int maxlen)
 Convert multibyte string to complex character array.
int get_chyron_key (Chyron *chyron, int x)
 Get keycode from chyron.
cchar_t * mk_cmplx_buf (const char *s)
 Create complex character buffer from multibyte string.

Detailed Description

Create and manage the Chyron.

Function Documentation

◆ compile_chyron()

void compile_chyron ( Chyron * chyron)

construct the chyron string from the chyron structure

Parameters
chyron

The chyron string is constructed by concatenating the labels of the set keys, separated by " | ". The end_pos values for each key are set to determine the zones for mouse clicks. When a mouse click occurs, the get_chyron_key function uses the end_pos values to determine which key was clicked based on the X position of the click.

Definition at line 268 of file dwin.c.

268 {
269 int end_pos = 0;
270 int k = 0;
271 int pos = 0;
272 int cp = cp_reverse;
273 cchar_t *cx;
274 while (k < CHYRON_KEYS) {
275 if (chyron->key[k]->text[0] == '\0') {
276 k++;
277 continue;
278 }
279 if (end_pos == 0) {
280 cx = chyron->cmplx_buf;
281 mb_to_cc(cx, " ", WA_NORMAL, cp_reverse, &pos, MAXLEN - 1);
282 } else {
283 mb_to_cc(chyron->cmplx_buf, "|", WA_NORMAL, cp_reverse, &pos,
284 MAXLEN - 1);
285 }
286 cx = chyron->cmplx_buf;
287 cp = chyron->key[k]->cp;
288 mb_to_cc(cx, chyron->key[k]->text, WA_NORMAL, cp, &pos, MAXLEN - 1);
289 end_pos = pos;
290 chyron->l = end_pos;
291 chyron->key[k]->end_pos = end_pos;
292 k++;
293 }
294 mb_to_cc(chyron->cmplx_buf, " ", WA_NORMAL, cp, &pos, MAXLEN - 1);
295 chyron->l = end_pos;
296}
#define CHYRON_KEYS
Definition cm.h:230
#define MAXLEN
Definition curskeys.c:15
int cp_reverse
Definition dwin.c:139
int mb_to_cc(cchar_t *, char *, attr_t, int, int *, int)
Convert multibyte string to complex character array.
Definition dwin.c:321
char text[CHYRON_KEY_MAXLEN]
Definition cm.h:233
int end_pos
Definition cm.h:236
int cp
Definition cm.h:237
int l
Definition cm.h:244
cchar_t cmplx_buf[MAXLEN]
Definition cm.h:243
ChyronKey * key[CHYRON_KEYS]
Definition cm.h:241

References Chyron::cmplx_buf, ChyronKey::cp, cp_reverse, ChyronKey::end_pos, Chyron::key, Chyron::l, mb_to_cc(), and ChyronKey::text.

Referenced by action_disposition(), answer_yn(), display_error(), display_page(), field_editor(), form_display_fields(), form_post(), form_process(), Perror(), pick_engine(), and wait_mk_chyron().

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

◆ destroy_chyron()

Chyron * destroy_chyron ( Chyron * chyron)

Destroy Chyron structure.

Parameters
chyronpointer to Chyron structure
Returns
nullptr

Definition at line 198 of file dwin.c.

198 {
199 int i;
200
201 if (!chyron)
202 return nullptr;
203 for (i = 0; i < CHYRON_KEYS; i++) {
204 if (chyron->key[i])
205 free(chyron->key[i]);
206 chyron->key[i] = nullptr;
207 }
208 free(chyron);
209 chyron = nullptr;
210 return chyron;
211}

References Chyron::key.

Referenced by action_disposition(), answer_yn(), display_error(), init_form(), Perror(), pick_engine(), and wait_destroy().

Here is the caller graph for this function:

◆ get_chyron_key()

int get_chyron_key ( Chyron * chyron,
int x )

Get keycode from chyron.

Parameters
chyronstructure
xMouse X position
Returns
Keycode
Note
This function uses the end_pos values set in compile_chyron to determine which key was clicked
The chyron functions provide xwgetch() with a mechanism to translate mouse click positions into key codes based on the labels set in the chyron structure. When a mouse click occurs, xwgetch() can call get_chyron_key() with the X position of the click to determine which function key was clicked, allowing for dynamic and customizable function key behavior in the chyron area of the interface.

Definition at line 369 of file dwin.c.

369 {
370 int i;
371 for (i = 0; chyron->key[i]->end_pos != -1; i++)
372 if (x < chyron->key[i]->end_pos)
373 break;
374 return chyron->key[i]->keycode;
375}
int keycode
Definition cm.h:235

References ChyronKey::end_pos, Chyron::key, and ChyronKey::keycode.

Referenced by xwgetch().

Here is the caller graph for this function:

◆ is_set_chyron_key()

bool is_set_chyron_key ( Chyron * chyron,
int k )

Check if function key label is set.

Parameters
chyronstructure
kFunction key index (0-19)
Returns
true if set, false if not set

Definition at line 217 of file dwin.c.

217 {
218 if (chyron->key[k]->text[0] != '\0')
219 return true;
220 else
221 return false;
222}

References Chyron::key, and ChyronKey::text.

Referenced by form_post(), and form_process().

Here is the caller graph for this function:

◆ mb_to_cc()

int mb_to_cc ( cchar_t * cmplx_buf,
char * str,
attr_t attr,
int cpx,
int * pos,
int maxlen )

Convert multibyte string to complex character array.

Parameters
cmplx_bufOutput buffer for complex characters
strInput multibyte string
attrAttributes to apply to the complex characters
cpxColor pair index for the complex characters
posPointer to current position in the output buffer, updated as characters are added
maxlenMaximum length of the output buffer
Returns
Number of bytes processed from the input string

This function converts a multibyte string to an array of complex characters (cchar_t) that can be used with NCurses functions. It handles multibyte characters and applies the specified color pair to each character. The pos parameter is updated to reflect the current position in the output buffer, and the function ensures that it does not exceed the maximum length.

Definition at line 321 of file dwin.c.

322 {
323 int i = 0, len = 0;
324 const char *s;
325 cchar_t cc = {0};
326 wchar_t wstr[2] = {L'\0', L'\0'};
327 mbstate_t mbstate;
328 memset(&mbstate, 0, sizeof(mbstate));
329 attr = WA_NORMAL;
330 if (*pos >= maxlen - 1)
331 return 0;
332 while (str[i] != '\0') {
333 s = &str[i];
334 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
335 if (len <= 0) {
336 wstr[0] = L'?';
337 wstr[1] = L'\0';
338 len = 1;
339 }
340 wstr[1] = L'\0';
341 if (*pos >= maxlen - 1)
342 break;
343 if (setcchar(&cc, wstr, attr, cpx, nullptr) != ERR) {
344 if (len > 0 && (*pos + len) < MAXLEN - 1)
345 cmplx_buf[(*pos)++] = cc;
346 }
347 i += len;
348 }
349 wstr[0] = L'\0';
350 wstr[1] = L'\0';
351 setcchar(&cc, wstr, attr, cpx, nullptr);
352 cmplx_buf[*pos] = cc;
353 return *pos;
354}

Referenced by compile_chyron().

Here is the caller graph for this function:

◆ mk_cmplx_buf()

cchar_t * mk_cmplx_buf ( const char * s)

Create complex character buffer from multibyte string.

Parameters
sInput multibyte string
Returns
Pointer to complex character buffer

This function creates a complex character buffer from a multibyte string. It allocates memory for the buffer and converts the multibyte string to complex characters using the mb_to_cc function. The color pair used for the complex characters is cp_norm. The caller is responsible for freeing the allocated buffer when it is no longer needed.

Definition at line 386 of file dwin.c.

386 {
387 cchar_t *cmplx_buf = (cchar_t *)calloc(MAXLEN, sizeof(cchar_t));
388 int j = 0;
389 int len;
390 attr_t attr = WA_NORMAL;
391 int cpx = cp_win;
392 wchar_t wc = L'\0';
393 cchar_t cc = {0};
394 mbstate_t mbstate;
395 memset(&mbstate, 0, sizeof(mbstate));
396 len = mbrtowc(&wc, s, MB_CUR_MAX, &mbstate);
397 if (len <= 0) {
398 wc = L'?';
399 len = 1;
400 }
401 if (setcchar(&cc, &wc, attr, cpx, nullptr) != ERR) {
402 if (len > 0 && (j + len) < MAXLEN - 1) {
403 cmplx_buf[j++] = cc;
404 }
405 }
406 return cmplx_buf;
407}
int cp_win
Definition dwin.c:137

References cp_win.

◆ new_chyron()

Chyron * new_chyron ( )

Create and initialize Chyron structure.

Returns
pointer to new Chyron structure

This function allocates memory for a new Chyron structure and initializes the key pointers. Each key pointer is allocated memory for a ChyronKey structure. The Chyron structure is used to manage function key labels and their associated keycodes for mouse click handling in the chyron area of the interface.

Note
The use of calloc ensures that the allocated memory is initialized to zero, which means that the text for each key will be initialized to an empty string and the keycodes will be initialized to zero. This allows the is_set_chyron_key function to check if a key is set by checking if the first character of the text is not '\0'. If any memory allocation fails, the function will call abend to handle the error and return nullptr.

Definition at line 183 of file dwin.c.

183 {
184 Chyron *chyron = (Chyron *)calloc(1, sizeof(Chyron));
185 if (!chyron) {
186 abend(-1, "calloc chyron failed");
187 return nullptr;
188 }
189 for (int i = 0; i < CHYRON_KEYS; i++)
190 chyron->key[i] = (ChyronKey *)calloc(1, sizeof(ChyronKey));
191 return chyron;
192}
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:1331
Definition cm.h:240

References abend(), and Chyron::key.

Referenced by action_disposition(), answer_yn(), display_error(), form_display_fields(), Perror(), pick_engine(), and wait_mk_chyron().

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

◆ set_chyron_key_cp()

void set_chyron_key_cp ( Chyron * chyron,
int k,
char * s,
int kc,
int cp )

Set chyron key.

Parameters
chyronstructure
kchyron key index (0-19)
schyron key label
kcchyron key code
cpcolor pair index for the key label

This function sets the label and keycode for a chyron key. The label is copied into the chyron structure, and the keycode is stored for later retrieval when theire is a mouse click. The compile_chyron function uses the keycode values to determine which key was clicked based on the mouse X position. If the label string is empty, the key is unset by setting the first character of the text to '\0'.

Definition at line 237 of file dwin.c.

237 {
238 if (*s != '\0')
239 ssnprintf(chyron->key[k]->text, CHYRON_KEY_MAXLEN - 1, "%s", s);
240 else
241 chyron->key[k]->text[0] = '\0';
242 chyron->key[k]->keycode = kc;
243 chyron->key[k]->cp = cp;
244}
#define CHYRON_KEY_MAXLEN
Definition cm.h:227
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:147

References ChyronKey::cp, Chyron::key, ChyronKey::keycode, ssnprintf(), and ChyronKey::text.

Referenced by field_editor(), and form_process().

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

◆ unset_chyron_key()

void unset_chyron_key ( Chyron * chyron,
int k )

Unset chyron key.

Parameters
chyronstructure
kchyron_key index

Definition at line 258 of file dwin.c.

258{ chyron->key[k]->text[0] = '\0'; }

References Chyron::key, and ChyronKey::text.

Referenced by form_post(), and form_process().

Here is the caller graph for this function: