]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Dekels tabular/textinset patches
[lyx.git] / src / lyxfunc.C
index c08c037b3169f6ae3aefe9996796e5c402e2b177..c0af8bd4cf160d98b097295e4daa1054c8af63cc 100644 (file)
@@ -91,8 +91,8 @@ using std::pair;
 using std::endl;
 using std::find_if;
 
-extern void math_insert_symbol(string const &);
-extern bool math_insert_greek(char);
+extern void math_insert_symbol(BufferView *, string const &);
+extern bool math_insert_greek(BufferView *, char);
 extern BufferList bufferlist;
 extern LyXServer * lyxserver;
 extern int greek_kb_flag;
@@ -156,11 +156,12 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        
        if (lyxerr.debugging(Debug::KEY)) {
                char * tmp = XKeysymToString(keysym);
-               string stm = (tmp ? tmp : "");
+               string const stm = (tmp ? tmp : "");
                lyxerr << "KeySym is "
                       << stm
                       << "["
-                      << keysym << "]"
+                      << keysym << "] State is ["
+                      << state << "]"
                       << endl;
        }
        // Do nothing if we have nothing (JMarc)
@@ -204,17 +205,25 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        int action = cancel_meta_seq.addkey(keysym, state
                                            &(ShiftMask|ControlMask
                                              |Mod1Mask)); 
-
+       if (lyxerr.debugging(Debug::KEY)) {
+               lyxerr << "action first set to [" << action << "]" << endl;
+       }
+       
        // When not cancel or meta-fake, do the normal lookup. 
        // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
        // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
        if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
-
+               if (lyxerr.debugging(Debug::KEY)) {
+                       lyxerr << "meta_fake_bit is [" << meta_fake_bit << "]" << endl;
+               }
                // remove Caps Lock and Mod2 as a modifiers
                action = keyseq.addkey(keysym,
                                       (state | meta_fake_bit)
                                       &(ShiftMask|ControlMask
-                                        |Mod1Mask));      
+                                        |Mod1Mask));
+               if (lyxerr.debugging(Debug::KEY)) {
+                       lyxerr << "action now set to [" << action << "]" << endl;
+               }
        }
        // Dont remove this unless you know what you are doing.
        meta_fake_bit = 0;
@@ -249,7 +258,7 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                        return 0;
                }
        
-               char isochar = keyseq.getiso();
+               char const isochar = keyseq.getiso();
                if (!(state & ControlMask) &&
                    !(state & Mod1Mask) &&
                    (isochar && keysym < 0xF000)) {
@@ -261,7 +270,38 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                        // so we`ll skip the dispatch.
                        return 0;
                }
+       } else if (action == LFUN_SELFINSERT) {
+               // We must set the argument to the char looked up by
+               // XKeysymToString
+               XKeyEvent xke;
+               xke.type = KeyPress;
+               xke.serial = 0;
+               xke.send_event = False;
+               xke.display = fl_get_display();
+               xke.window = 0;
+               xke.root = 0;
+               xke.subwindow = 0;
+               xke.time = 0;
+               xke.x = 0;
+               xke.y = 0;
+               xke.x_root = 0;
+               xke.y_root = 0;
+               xke.state = state;
+               xke.keycode = XKeysymToKeycode(fl_get_display(), keysym);
+               xke.same_screen = True;
+               char ret[10];
+               KeySym tmpkeysym;
+               int res = XLookupString(&xke, ret, 10, &tmpkeysym, 0);
+               //Assert(keysym == tmpkeysym);
+               lyxerr[Debug::KEY] << "TmpKeysym ["
+                                  << tmpkeysym << "]" << endl;
+               
+               if (res > 0)
+                       argument = string(ret, res);
+               lyxerr[Debug::KEY] << "SelfInsert arg["
+                                  << argument << "]" << endl;
        }
+       
 
         bool tmp_sc = show_sc;
        show_sc = false;
@@ -418,13 +458,8 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
 
        if (buf) {
                func_status box = LyXFunc::ToggleOff;
-               LyXFont font;
-               if (owner->view()->theLockingInset() &&
-                   owner->view()->theLockingInset()->getLyXText(owner->view()))
-                   font = owner->view()->theLockingInset()->
-                       getLyXText(owner->view())->real_current_font;
-               else
-                   font = owner->view()->text->real_current_font;
+               LyXFont const & font =
+                       owner->view()->getLyXText()->real_current_font;
                switch (action) {
                case LFUN_EMPH:
                        if (font.emph() == LyXFont::ON)
@@ -472,7 +507,6 @@ string const LyXFunc::Dispatch(int ac,
        
        string argument;
        kb_action action;
-       LyXText * text = 0;
         
         // we have not done anything wrong yet.
         errorstat = false;
@@ -496,6 +530,9 @@ string const LyXFunc::Dispatch(int ac,
        if (owner->view()->available())
                owner->view()->hideCursor();
 
+       // We have to do this heare because of te goto below. (Lgb)
+       LyXText * text = owner->view()->getLyXText();
+
        // We cannot use this function here
        if (getStatus(ac) & Disabled)
                goto exit_with_message;
@@ -526,7 +563,8 @@ string const LyXFunc::Dispatch(int ac,
                                }
                        }
 
-                       string shortcuts = toplevel_keymap->findbinding(pseudoaction);
+                       string const shortcuts =
+                               toplevel_keymap->findbinding(pseudoaction);
 
                        if (!shortcuts.empty()) {
                                comname += ": " + shortcuts;
@@ -599,7 +637,7 @@ string const LyXFunc::Dispatch(int ac,
                                   (result == UpdatableInset::DISPATCHED_NOUPDATE))
                                return string();
                        else {
-                               setMessage(N_("Text mode"));
+                               //setMessage(N_("Text mode"));
                                switch (action) {
                                case LFUN_UNKNOWN_ACTION:
                                case LFUN_BREAKPARAGRAPH:
@@ -632,14 +670,8 @@ string const LyXFunc::Dispatch(int ac,
                                }
                        }
                }
-               if (owner->view()->theLockingInset())
-                       text = owner->view()->theLockingInset()->
-                               getLyXText(owner->view());
        }
 
-       if (!text)
-           text = owner->view()->text;
-
        switch (action) {
                // --- Misc -------------------------------------------
        case LFUN_WORDFINDFORWARD  : 
@@ -985,15 +1017,15 @@ string const LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_DEPTH:
-               changeDepth(owner->view(), 0);
+               changeDepth(owner->view(), text, 0);
                break;
                
        case LFUN_DEPTH_MIN:
-               changeDepth(owner->view(), -1);
+               changeDepth(owner->view(), text, -1);
                break;
                
        case LFUN_DEPTH_PLUS:
-               changeDepth(owner->view(), 1);
+               changeDepth(owner->view(), text, 1);
                break;
                
        case LFUN_FREE:
@@ -1436,7 +1468,15 @@ string const LyXFunc::Dispatch(int ac,
                    && tmptext->cursor.par()->GetInset(tmptext->cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE){
                        Inset * tmpinset = tmptext->cursor.par()->GetInset(tmptext->cursor.pos());
                        setMessage(tmpinset->EditMessage());
-                       tmpinset->Edit(owner->view(), 0, 0, 0);
+                       int y = 0;
+                       if (is_rtl) {
+                               LyXFont font = 
+                                       tmptext->GetFont(owner->view()->buffer(),
+                                                        tmptext->cursor.par(),
+                                                        tmptext->cursor.pos());        
+                               y = tmpinset->descent(owner->view(),font);
+                       }
+                       tmpinset->Edit(owner->view(), 0, y, 0);
                        break;
                }
                if (!is_rtl)
@@ -1458,7 +1498,7 @@ string const LyXFunc::Dispatch(int ac,
                LyXCursor cur = txt->cursor;
                if (!is_rtl)
                        txt->CursorLeft(owner->view(), false);
-               if ((cur != txt->cursor) && // only if really moved!
+               if ((is_rtl || cur != txt->cursor) && // only if really moved!
                    txt->cursor.pos() < txt->cursor.par()->Last() &&
                    (txt->cursor.par()->GetChar(txt->cursor.pos()) ==
                     LyXParagraph::META_INSET) &&
@@ -1471,11 +1511,12 @@ string const LyXFunc::Dispatch(int ac,
                        LyXFont font = txt->GetFont(owner->view()->buffer(),
                                                    txt->cursor.par(),
                                                    txt->cursor.pos());
+                       int y = is_rtl ? 0 
+                               : tmpinset->descent(owner->view(),font);
                        tmpinset->Edit(owner->view(),
                                       tmpinset->x() +
                                       tmpinset->width(owner->view(),font),
-                                      tmpinset->descent(owner->view(),font),
-                                      0);
+                                      y, 0);
                        break;
                }
                if  (is_rtl)
@@ -1812,7 +1853,7 @@ string const LyXFunc::Dispatch(int ac,
                                owner->view()->text->cursor;
                        owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                        // It is possible to make it a lot faster still
-                       // just comment out the lone below...
+                       // just comment out the line below...
                        owner->view()->showCursor();
                } else {
                        owner->view()->cut();
@@ -1922,13 +1963,17 @@ string const LyXFunc::Dispatch(int ac,
        case LFUN_BACKSPACE:
        {
                if (!owner->view()->text->selection) {
+#if 0
                        if (owner->getIntl()->getTrans()->backspace()) {
+#else
+                       if (owner->getIntl()->getTrans().backspace()) {
+#endif
                                owner->view()->text->Backspace(owner->view());
                                owner->view()->text->sel_cursor = 
                                        owner->view()->text->cursor;
                                owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                                // It is possible to make it a lot faster still
-                               // just comment out the lone below...
+                               // just comment out the line below...
                                owner->view()->showCursor();
                        }
                } else {
@@ -2229,9 +2274,9 @@ string const LyXFunc::Dispatch(int ac,
                        ::sscanf(argument.c_str(),"%d%d", &r, &c);
                InsetTabular * new_inset =
                        new InsetTabular(*owner->buffer(), r, c);
-               if (owner->view()->insertInset(new_inset))
-                       new_inset->Edit(owner->view(), 0, 0, 0);
-               else
+               bool rtl =
+                       owner->view()->getLyXText()->real_current_font.isRightToLeft();
+               if (!owner->view()->open_new_inset(new_inset, rtl))
                        delete new_inset;
        }
        break;
@@ -2385,10 +2430,16 @@ string const LyXFunc::Dispatch(int ac,
                
                if (keyseq.length == -1 && keyseq.getiso() != 0) 
                        c = keyseq.getiso();
-               
+
+#if 0
                owner->getIntl()->getTrans()->
                        deadkey(c, get_accent(action).accent, 
                                owner->view()->text);
+#else
+               owner->getIntl()->getTrans()
+                       .deadkey(c, get_accent(action).accent, 
+                               owner->view()->text);
+#endif
                
                // Need to reset, in case the minibuffer calls these
                // actions
@@ -2478,7 +2529,7 @@ string const LyXFunc::Dispatch(int ac,
               
        case LFUN_INSERT_MATH:
        {
-               math_insert_symbol(argument);
+               math_insert_symbol(owner->view(), argument);
        }
        break;
        
@@ -2909,10 +2960,19 @@ string const LyXFunc::Dispatch(int ac,
                        for (string::size_type i = 0;
                             i < argument.length(); ++i) {
                                if (greek_kb_flag) {
-                                       if (!math_insert_greek(argument[i]))
+                                       if (!math_insert_greek(owner->view(),
+                                                              argument[i]))
+#if 0
                                                owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
+#else
+                                               owner->getIntl()->getTrans().TranslateAndInsert(argument[i], owner->view()->text);
+#endif
                                } else
+#if 0
                                        owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
+#else
+                                       owner->getIntl()->getTrans().TranslateAndInsert(argument[i], owner->view()->text);
+#endif
                        }
 
                        owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);