entry.c (1900B)
1 /* 2 * Copyright (c) 2022-2024 lumidify <nobody@lumidify.org> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include <stddef.h> 18 19 #include "err.h" 20 #include "ltkd.h" 21 #include "widget.h" 22 #include "cmd.h" 23 24 #include <ltk/ltk.h> 25 #include <ltk/util.h> 26 #include <ltk/entry.h> 27 28 /* FIXME: make text optional, command set-text */ 29 /* entry <entry id> create <text> */ 30 static int 31 ltkd_entry_cmd_create( 32 ltk_window *window, 33 ltkd_widget *widget_unneeded, 34 ltkd_cmd_token *tokens, 35 size_t num_tokens, 36 ltkd_error *err) { 37 (void)widget_unneeded; 38 ltkd_cmdarg_parseinfo cmd[] = { 39 {.type = CMDARG_IGNORE, .optional = 0}, 40 {.type = CMDARG_STRING, .optional = 0}, 41 {.type = CMDARG_IGNORE, .optional = 0}, 42 {.type = CMDARG_STRING, .optional = 0}, 43 }; 44 if (ltkd_parse_cmd(tokens, num_tokens, cmd, LENGTH(cmd), err)) 45 return 1; 46 ltk_entry *entry = ltk_entry_create(window, cmd[3].val.str); 47 if (!ltkd_widget_create(LTK_CAST_WIDGET(entry), cmd[1].val.str, NULL, 0, err)) { 48 ltk_widget_destroy(LTK_CAST_WIDGET(entry), 1); 49 err->arg = 1; 50 return 1; 51 } 52 53 return 0; 54 } 55 56 static ltkd_cmd_info entry_cmds[] = { 57 {"create", <kd_entry_cmd_create, 1}, 58 }; 59 60 GEN_CMD_HELPERS(ltkd_entry_cmd, LTK_WIDGET_ENTRY, entry_cmds)