summaryrefslogtreecommitdiff
path: root/client/luawidget.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/luawidget.cc')
-rw-r--r--client/luawidget.cc89
1 files changed, 88 insertions, 1 deletions
diff --git a/client/luawidget.cc b/client/luawidget.cc
index 86dc2bb..944120d 100644
--- a/client/luawidget.cc
+++ b/client/luawidget.cc
@@ -66,6 +66,7 @@ static int wdg_name(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
lua_pushstring(L, wdgu->widget->name().toStdString().c_str());
@@ -80,6 +81,7 @@ static int wdg_type(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
// return error code
@@ -95,6 +97,7 @@ static int wdg_value(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
lua_pushstring(L, wdgu->widget->value().toStdString().c_str());
@@ -109,6 +112,7 @@ static int wdg_set_value(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
const char *val = luaL_checkstring(L, 2);
@@ -125,6 +129,7 @@ static int wdg_enabled(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
lua_pushboolean(L, wdgu->widget->enabled());
@@ -139,6 +144,7 @@ static int wdg_set_enabled(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
bool val = luaL_checkbool(L, 2);
@@ -155,6 +161,7 @@ static int wdg_visible(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
lua_pushboolean(L, wdgu->widget->visible());
@@ -169,6 +176,7 @@ static int wdg_set_visible(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
bool val = luaL_checkbool(L, 2);
@@ -185,6 +193,7 @@ static int wdg_valid(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
lua_pushboolean(L, wdgu->widget->valid());
@@ -199,6 +208,7 @@ static int wdg_set_valid(lua_State *L)
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
luaL_argcheck(L, wdgu, 1, "widget expected");
bool val = luaL_checkbool(L, 2);
@@ -288,7 +298,7 @@ static int cmb_le_value(lua_State *L)
luaL_argcheck(L, wdgu, 1, "combobox expected");
ComboBox *cmb = (ComboBox*)wdgu->widget;
- lua_pushstring(L, cmb->lineEditValue().toStdString().c_str());
+ lua_pushstring(L, cmb->lineEditValue().toStdString().c_str());
return 1;
}
@@ -314,6 +324,71 @@ static int cmb_le_set_value(lua_State *L)
{"lineEditValue", cmb_le_value},\
{"setLineEditValue", cmb_le_set_value}
+static int lin_clear_suggestions(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "lineedit expected");
+
+ LineEdit *led = (LineEdit*)wdgu->widget;
+ led->clearSuggestions();
+
+ return 0;
+}
+
+static int lin_show_suggestions(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "lineedit expected");
+
+ LineEdit *led = (LineEdit*)wdgu->widget;
+ led->showSuggestions();
+
+ return 0;
+}
+
+static int lin_is_suggested(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "lineedit expected");
+
+ const char *val = luaL_checkstring(L, 2);
+
+ LineEdit *led = (LineEdit*)wdgu->widget;
+
+ lua_pushboolean(L, led->isSuggested(val));
+
+ return 1;
+}
+
+static int lin_add_suggestion(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "lineedit expected");
+
+ const char *val = luaL_checkstring(L, 2);
+
+ LineEdit *led = (LineEdit*)wdgu->widget;
+ led->addSuggestion(val);
+
+ return 0;
+}
+
+
+#define LINEDT_METHS \
+ {"clearSuggestions", lin_clear_suggestions},\
+ {"showSuggestions", lin_show_suggestions},\
+ {"isSuggested", lin_is_suggested},\
+ {"addSuggestion", lin_add_suggestion}
+
+
static const struct luaL_Reg wdg_meths[] =
{ WDG_METHS, {NULL, NULL} };
@@ -323,6 +398,9 @@ static const struct luaL_Reg chkbox_meths[] =
static const struct luaL_Reg cmbbox_meths[] =
{ WDG_METHS, CMBBOX_METHS, {NULL, NULL} };
+static const struct luaL_Reg linedt_meths[] =
+ { WDG_METHS, LINEDT_METHS, {NULL, NULL} };
+
int wdg_make_widget(lua_State *L, Widget *widget)
{
wdg_userdata *wdgu;
@@ -330,6 +408,7 @@ int wdg_make_widget(lua_State *L, Widget *widget)
if(widget->type() == "combobox") luaL_getmetatable(L, "ComboBox");
else if(widget->type() == "checkbox") luaL_getmetatable(L, "CheckBox");
+ else if(widget->type() == "lineedit") luaL_getmetatable(L, "LineEdit");
else luaL_getmetatable(L, "Widget");
lua_setmetatable(L, -2);
@@ -364,5 +443,13 @@ void register_widget(lua_State *L)
luaL_register(L, NULL, cmbbox_meths);
// lua_pop(L, 2);
+
+ luaL_newmetatable(L, "LineEdit");
+ lua_pushliteral(L, "__index");
+ lua_pushvalue(L, -2);
+ lua_rawset(L, -3);
+ luaL_register(L, NULL, linedt_meths);
+
+ // lua_pop(L, 2);
}