From: Lars Gullik Bjønnes Date: Sun, 22 Oct 2006 18:47:19 +0000 (+0000) Subject: LFUN_UNICODE_INSERT - unicode-insert X-Git-Tag: 1.6.10~12235 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3674a8c003a5d4f6e890b47062b164395e17e0f8;p=lyx.git LFUN_UNICODE_INSERT - unicode-insert git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15490 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/LyXAction.C b/src/LyXAction.C index 8b5eca670e..c638afc7aa 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -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 } }; diff --git a/src/lfuns.h b/src/lfuns.h index 58b990b7eb..cda5a2d0f8 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -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 }; diff --git a/src/support/lstrings.C b/src/support/lstrings.C index a844f2214b..d68b75f3ff 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -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)); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 74622aeacd..b0016bf846 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -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); diff --git a/src/text3.C b/src/text3.C index 221b297d9a..015a83f03f 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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;