LFUN_UNICODE_INSERT - unicode-insert

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15490 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2006-10-22 18:47:19 +00:00
parent 91d244160d
commit 3674a8c003
5 changed files with 78 additions and 2 deletions

View File

@ -363,6 +363,8 @@ void LyXAction::init()
{ LFUN_PARAGRAPH_MOVE_DOWN, "paragraph-move-down", Noop },
{ LFUN_PARAGRAPH_MOVE_UP, "paragraph-move-up", Noop },
{ LFUN_WINDOW_NEW, "window-new", NoBuffer },
{ LFUN_UNICODE_INSERT, "unicode-insert", Noop },
{ LFUN_NOACTION, "", Noop }
};

View File

@ -369,8 +369,9 @@ enum kb_action {
// 280
LFUN_INSET_DISSOLVE, // jspitzm 20060807
LFUN_CHANGE_NEXT,
LFUN_WINDOW_NEW, // Abdel 20062110
LFUN_WINDOW_NEW, // Abdel 20061021
LFUN_UNICODE_INSERT, // Lgb 20061022
LFUN_LASTACTION // end of the table
};

View File

@ -226,6 +226,59 @@ bool isStrDbl(string const & str)
}
namespace {
inline
bool isHexChar(char_type c)
{
return c == '0' ||
c == '1' ||
c == '2' ||
c == '3' ||
c == '4' ||
c == '5' ||
c == '6' ||
c == '7' ||
c == '8' ||
c == '9' ||
c == 'a' || c == 'A' ||
c == 'b' || c == 'B' ||
c == 'c' || c == 'C' ||
c == 'd' || c == 'D' ||
c == 'e' || c == 'E' ||
c == 'f' || c == 'F';
}
} // anon namespace
bool isHex(docstring const & str)
{
int index = 0;
if (str.length() > 2 and str[0] == '0' &&
(str[1] == 'x' || str[1] == 'X'))
index = 2;
int const len = str.length();
for (; index < len; ++index) {
if (!isHexChar(str[index]))
return false;
}
return true;
}
int hexToInt(docstring const & str)
{
string s = to_ascii(str);
int h;
sscanf(s.c_str(), "%x", &h);
return h;
}
char lowercase(char c)
{
return char(tolower(c));

View File

@ -68,6 +68,10 @@ bool isStrUnsignedInt(std::string const & str);
///
bool isStrDbl(std::string const & str);
bool isHex(lyx::docstring const & str);
int hexToInt(lyx::docstring const & str);
///
char lowercase(char c);

View File

@ -893,6 +893,21 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
break;
}
case LFUN_UNICODE_INSERT: {
if (cmd.argument().empty())
break;
docstring hexstring = cmd.argument();
if (lyx::support::isHex(hexstring)) {
char_type c = lyx::support::hexToInt(hexstring);
if (c > 32 && c < 0x10ffff) {
lyxerr << "Inserting c: " << c << endl;
docstring s = docstring(1, c);
lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, s));
}
}
break;
}
case LFUN_QUOTE_INSERT: {
cap::replaceSelection(cur);
Paragraph & par = cur.paragraph();
@ -1794,6 +1809,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
case LFUN_BUFFER_BEGIN:
case LFUN_BUFFER_BEGIN_SELECT:
case LFUN_BUFFER_END_SELECT:
case LFUN_UNICODE_INSERT:
// these are handled in our dispatch()
enable = true;
break;