static int TextConvertLinColToPos(lua_State *L) { int pos; IupTextConvertLinColToPos(iuplua_checkihandle(L,1), luaL_checkint(L, 2), luaL_checkint(L, 3), &pos); lua_pushinteger(L, pos); return 1; }
int item_goto_action_cb(Ihandle* item_goto) { Ihandle* multitext = IupGetDialogChild(item_goto, "MULTITEXT"); Ihandle *dlg, *box, *bt_ok, *bt_cancel, *txt, *lbl; int line_count = IupGetInt(multitext, "LINECOUNT"); lbl = IupLabel(NULL); IupSetfAttribute(lbl, "TITLE", "Line Number [1-%d]:", line_count); txt = IupText(NULL); IupSetAttribute(txt, "MASK", IUP_MASK_UINT); /* unsigned integer numbers only */ IupSetAttribute(txt, "NAME", "LINE_TEXT"); IupSetAttribute(txt, "VISIBLECOLUMNS", "20"); bt_ok = IupButton("OK", NULL); IupSetInt(bt_ok, "TEXT_LINECOUNT", line_count); IupSetAttribute(bt_ok, "PADDING", "10x2"); IupSetCallback(bt_ok, "ACTION", (Icallback)goto_ok_action_cb); bt_cancel = IupButton("Cancel", NULL); IupSetCallback(bt_cancel, "ACTION", (Icallback)goto_cancel_action_cb); IupSetAttribute(bt_cancel, "PADDING", "10x2"); box = IupVbox( lbl, txt, IupSetAttributes(IupHbox( IupFill(), bt_ok, bt_cancel, NULL), "NORMALIZESIZE=HORIZONTAL"), NULL); IupSetAttribute(box, "MARGIN", "10x10"); IupSetAttribute(box, "GAP", "5"); dlg = IupDialog(box); IupSetAttribute(dlg, "TITLE", "Go To Line"); IupSetAttribute(dlg, "DIALOGFRAME", "Yes"); IupSetAttributeHandle(dlg, "DEFAULTENTER", bt_ok); IupSetAttributeHandle(dlg, "DEFAULTESC", bt_cancel); IupSetAttributeHandle(dlg, "PARENTDIALOG", IupGetDialog(item_goto)); IupPopup(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(dlg, "STATUS") == 1) { int line = IupGetInt(txt, "VALUE"); int pos; IupTextConvertLinColToPos(multitext, line, 0, &pos); IupSetInt(multitext, "CARETPOS", pos); IupSetInt(multitext, "SCROLLTOPOS", pos); } IupDestroy(dlg); return IUP_DEFAULT; }
int find_next_action_cb(Ihandle* bt_next) { Ihandle* multitext = (Ihandle*)IupGetAttribute(bt_next, "MULTITEXT"); char* str = IupGetAttribute(multitext, "VALUE"); int find_pos = IupGetInt(multitext, "FIND_POS"); Ihandle* txt = IupGetDialogChild(bt_next, "FIND_TEXT"); char* str_to_find = IupGetAttribute(txt, "VALUE"); Ihandle* find_case = IupGetDialogChild(bt_next, "FIND_CASE"); int casesensitive = IupGetInt(find_case, "VALUE"); int pos = str_find(str + find_pos, str_to_find, casesensitive); if (pos >= 0) pos += find_pos; else if (find_pos > 0) pos = str_find(str, str_to_find, casesensitive); /* try again from the start */ if (pos >= 0) { int lin, col, end_pos = pos + (int)strlen(str_to_find); IupSetInt(multitext, "FIND_POS", end_pos); IupSetFocus(multitext); IupSetfAttribute(multitext, "SELECTIONPOS", "%d:%d", pos, end_pos); IupTextConvertPosToLinCol(multitext, pos, &lin, &col); IupTextConvertLinColToPos(multitext, lin, 0, &pos); /* position at col=0, just scroll lines */ IupSetInt(multitext, "SCROLLTOPOS", pos); } else IupMessage("Warning", "Text not found."); return IUP_DEFAULT; }
static void TextConvertLinColToPos(void) { int pos; IupTextConvertLinColToPos(iuplua_checkihandle(1), luaL_check_int(2), luaL_check_int(3), &pos); lua_pushnumber(pos); }