(hotkey_get_text): new hotkey API.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2019-12-14 16:32:26 +03:00
parent 851d2022a9
commit 53314c58b5
3 changed files with 24 additions and 3 deletions

View File

@ -228,9 +228,7 @@ button_new (int y, int x, int action, button_flags_t flags, const char *text, bc
char *
button_get_text (const WButton * b)
{
if (b->text.hotkey != NULL)
return g_strconcat (b->text.start, "&", b->text.hotkey, b->text.end, (char *) NULL);
return g_strdup (b->text.start);
return hotkey_get_text (b->text);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -222,6 +222,27 @@ hotkey_draw (Widget * w, const hotkey_t hotkey, gboolean focused)
/* --------------------------------------------------------------------------------------------- */
char *
hotkey_get_text (const hotkey_t hotkey)
{
GString *text;
text = g_string_new (hotkey.start);
if (hotkey.hotkey != NULL)
{
g_string_append_c (text, '&');
g_string_append (text, hotkey.hotkey);
}
if (hotkey.end != NULL)
g_string_append (text, hotkey.end);
return g_string_free (text, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
void
widget_init (Widget * w, int y, int x, int lines, int cols,
widget_cb_fn callback, widget_mouse_cb_fn mouse_callback)

View File

@ -173,6 +173,8 @@ int hotkey_width (const hotkey_t hotkey);
gboolean hotkey_equal (const hotkey_t hotkey1, const hotkey_t hotkey2);
/* draw hotkey of widget */
void hotkey_draw (Widget * w, const hotkey_t hotkey, gboolean focused);
/* get text of hotkey */
char *hotkey_get_text (const hotkey_t hotkey);
/* widget initialization */
void widget_init (Widget * w, int y, int x, int lines, int cols,