]> git.lyx.org Git - lyx.git/commitdiff
LFUN_UNICODE_INSERT - unicode-insert
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 22 Oct 2006 18:47:19 +0000 (18:47 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 22 Oct 2006 18:47:19 +0000 (18:47 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15490 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXAction.C
src/lfuns.h
src/support/lstrings.C
src/support/lstrings.h
src/text3.C

index 8b5eca670e193dc190469772098b470912aa8d7e..c638afc7aa62604c595a9694657ce535de9c5be9 100644 (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 }
        };
 
index 58b990b7eb0a703fe5caa46b5783af55b691e57e..cda5a2d0f8894713b0a942fc9f820044926b5cee 100644 (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
 };
 
index a844f2214bcac5749cd0dad0cfe826b9ec74b061..d68b75f3fff10f990817a5d84cd68186ab4bb3c5 100644 (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));
index 74622aeacdb2f5eff77a3992c3a9b948127ffa0b..b0016bf8469941be67ba757c8d267c41f2181bd1 100644 (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);
 
index 221b297d9a9ca563199614e57b15435f28d3290f..015a83f03fe2e8b394c6ac0988907a5493768b19 100644 (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;