]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Various updates for insets mostly regarding fixes for text-insets.
[lyx.git] / src / lyxfunc.C
index d5a806f837be69ff98f2c61cfd82bd4ee42b1fcd..e2db2999383b0730e929468f55436455fe20f7ac 100644 (file)
 #include "insets/insetindex.h"
 #include "insets/insetinclude.h"
 #include "insets/insetbib.h"
+#include "insets/insettext.h"
+#include "insets/insetert.h"
+#include "insets/insetgraphics.h"
+#include "insets/insetfoot.h"
 #include "mathed/formulamacro.h"
 #include "toolbar.h"
 #include "spellchecker.h" // RVDK_PATCH_5
@@ -54,7 +58,6 @@
 #include "support/syscall.h"
 #include "support/lstrings.h"
 #include "support/path.h"
-#include "lyxscreen.h"
 #include "debug.h"
 #include "lyxrc.h"
 #include "lyxtext.h"
@@ -64,6 +67,7 @@
 #include "ImportNoweb.h"
 #include "layout.h"
 #include "WorkArea.h"
+#include "lyxfr1.h"
 
 extern bool cursor_follows_scrollbar;
 
@@ -95,7 +99,6 @@ extern LyXAction lyxaction;
 extern tex_accent_struct get_accent(kb_action action);
 
 extern void AutoSave();
-extern void MenuSearch();
 extern void SetUpdateTimer(float timer = 0.3);
 extern void FreeUpdateTimer();
 extern bool PreviewDVI(Buffer *);
@@ -116,13 +119,11 @@ extern Buffer * NewLyxFile(string const &);
 extern void LoadLyXFile(string const &);
 extern void Reconfigure(BufferView *);
 
-extern int current_layout;
+extern LyXTextClass::size_type current_layout;
 extern int getISOCodeFromLaTeX(char *);
 
 extern void ShowLatexLog();
 
-extern void UpdateInset(BufferView *, Inset * inset, bool mark_dirty = true);
-
 /* === globals =========================================================== */
 
 bool LyXFunc::show_sc = true;
@@ -148,19 +149,19 @@ void LyXFunc::moveCursorUpdate(bool selecting)
 {
        if (selecting || owner->view()->text->mark_set) {
                owner->view()->text->SetSelection();
-               owner->view()->getScreen()->ToggleToggle();
+               owner->view()->toggleToggle();
                owner->view()->update(0);
        } else {
                owner->view()->update(-2); // this IS necessary
                // (Matthias) 
        }
 
-       owner->view()->getScreen()->ShowCursor();
+       owner->view()->showCursor();
        
        /* ---> Everytime the cursor is moved, show the current font state. */
        // should this too me moved out of this func?
        //owner->getMiniBuffer()->Set(CurrentState());
-       owner->view()->SetState();
+       owner->view()->setState();
 }
 
 
@@ -453,9 +454,8 @@ string LyXFunc::Dispatch(int ac,
     
        selection_possible = false;
        
-       if (owner->view()->available() 
-           && owner->view()->getScreen())
-               owner->view()->getScreen()->HideCursor();
+       if (owner->view()->available())
+               owner->view()->hideCursor();
 
        // We cannot use this function here
        if (getStatus(action) & Disabled)
@@ -528,43 +528,55 @@ string LyXFunc::Dispatch(int ac,
                                inset->GetCursorPos(slx, sly);
                                owner->view()->unlockInset(inset);
                                owner->view()->menuUndo();
-                               inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
-                               if (inset) 
-                                       inset->Edit(slx, sly);
+                               inset = static_cast<UpdatableInset*>(
+                                       owner->view()->text->cursor.par->
+                                       GetInset(owner->view()->text->
+                                                cursor.pos));
+                               if (inset)
+                                       inset->Edit(owner->view(),slx,sly,0);
+                               return string();
+                       } else if (action == LFUN_REDO) {
+                               int slx, sly;
+                               UpdatableInset * inset = owner->view()->
+                                       the_locking_inset;
+                               inset->GetCursorPos(slx, sly);
+                               owner->view()->unlockInset(inset);
+                               owner->view()->menuRedo();
+                               inset = static_cast<UpdatableInset*>(
+                                       owner->view()->text->cursor.par->
+                                       GetInset(owner->view()->text->
+                                                cursor.pos));
+                               if (inset)
+                                       inset->Edit(owner->view(),slx,sly,0); 
                                return string();
-                       } else 
-                               if (action == LFUN_REDO) {
-                                       int slx, sly;
-                                       UpdatableInset * inset = owner->view()->the_locking_inset;
-                                       inset->GetCursorPos(slx, sly);
-                                       owner->view()->unlockInset(inset);
-                                       owner->view()->menuRedo();
-                                       inset = static_cast<UpdatableInset*>(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos));
-                                       if (inset)
-                                               inset->Edit(slx, sly);
+                       } else if (owner->view()->the_locking_inset->
+                                  LocalDispatch(owner->view(), action,
+                                                argument) ==
+                                  UpdatableInset::DISPATCHED)
+                               return string();
+                       else {
+                               setMessage(N_("Text mode"));
+                               LyXDirection direction = owner->view()->text->
+                                       cursor.par->getParDirection();
+                               if ((action == -1) ||
+                                   ((action == LFUN_RIGHT) &&
+                                    (direction == LYX_DIR_LEFT_TO_RIGHT))) {
+                                       owner->view()->text->CursorRight();
+                                       moveCursorUpdate(false);
+                                       owner->getMiniBuffer()->
+                                               Set(CurrentState());
+                               }
+                               if ((action == LFUN_LEFT) &&
+                                   (direction == LYX_DIR_RIGHT_TO_LEFT)) {
+                                       owner->view()->text->CursorRight();
+                                       moveCursorUpdate(false);
+                                       owner->getMiniBuffer()->
+                                               Set(CurrentState());
+                               }
+                               if ((action == LFUN_LEFT) ||
+                                   (action == LFUN_RIGHT))
                                        return string();
-                               } else
-                                       if (owner->view()->the_locking_inset->LocalDispatch(action, argument.c_str()))
-                                               return string();
-                                       else {
-                                               setMessage(N_("Text mode"));
-                                               LyXDirection direction = owner->view()->text->cursor.par->getParDirection();
-                                               if ( action == -1 ||
-                                                    (action == LFUN_RIGHT
-                                                     && direction == LYX_DIR_LEFT_TO_RIGHT)) {
-                                                       owner->view()->text->CursorRight();
-                                                       moveCursorUpdate(false);
-                                                       owner->getMiniBuffer()->Set(CurrentState());
-                                               }
-                                               if ( action == LFUN_LEFT 
-                                                    && direction == LYX_DIR_RIGHT_TO_LEFT) {
-                                                       owner->view()->text->CursorRight();
-                                                       moveCursorUpdate(false);
-                                                       owner->getMiniBuffer()->Set(CurrentState());
-                                               }
-                                               if (action == LFUN_LEFT || action == LFUN_RIGHT)
-                                                       return string();
-                                       }
+                       }
                }
        }
 
@@ -594,7 +606,7 @@ string LyXFunc::Dispatch(int ac,
 
                        // ??? Needed ???
                        // clear the selection (if there is any) 
-                       owner->view()->getScreen()->ToggleSelection();
+                       owner->view()->toggleSelection();
                        owner->view()->text->ClearSelection();
 
                        // Move cursor so that successive C-s 's will not stand in place. 
@@ -606,19 +618,18 @@ string LyXFunc::Dispatch(int ac,
                        // ??? Needed ???
                        // set the new selection 
                        // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
-                       owner->view()->getScreen()->ToggleSelection(false);
+                       owner->view()->toggleSelection(false);
                } else 
                        LyXBell();      
         
                // REMOVED : if (owner->view()->getWorkArea()->focus)
-               owner->view()->getScreen()->ShowCursor();
+               owner->view()->showCursor();
        }
        break;
 
        case LFUN_PREFIX:
        {
-               if (owner->view()->available()
-                   && owner->view()->getScreen()) {
+               if (owner->view()->available()) {
                        owner->view()->update(-2);
                }
                string buf;
@@ -661,28 +672,7 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_CENTER: // this is center and redraw.
-               owner->view()->beforeChange();
-               if (owner->view()->text->cursor.y >
-#ifdef NEW_WA
-                   owner->view()->getWorkArea()->height() / 2)
-#else
-                   owner->view()->getWorkArea()->h / 2)
-#endif
-                       {
-                       owner->view()->getScreen()->
-                               Draw(owner->view()->text->cursor.y -
-#ifdef NEW_WA
-                                    owner->view()->getWorkArea()->height() / 2
-#else
-                                    owner->view()->getWorkArea()->h / 2
-#endif
-                                       );
-               } else { // <= 
-                       owner->view()->getScreen()->
-                               Draw(0);
-               }
-               owner->view()->update(0);
-               owner->view()->redraw();
+               owner->view()->center();
                break;
                
        case LFUN_APPENDIX:
@@ -710,7 +700,16 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_MENUWRITE:
+               owner->getMiniBuffer()->Set(_("Saving document"),
+                                           MakeDisplayPath(owner->buffer()->fileName()),
+                                           "...");
                MenuWrite(owner->buffer());
+               //owner->getMiniBuffer()->
+               //      Set(_("Document saved as"),
+               //          MakeDisplayPath(owner->buffer()->fileName()));
+               //} else {
+               //owner->getMiniBuffer()->Set(_("Save failed!"));
+               //}
                break;
                
        case LFUN_MENUWRITEAS:
@@ -838,7 +837,14 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_FIGURE:
                Figure();
                break;
-               
+
+       case LFUN_INSERT_GRAPHICS:
+       {
+               Inset * new_inset = new InsetGraphics;
+               owner->view()->insertInset(new_inset);
+               break;
+       }
+       
        case LFUN_AUTOSAVE:
                AutoSave();
                break;
@@ -852,7 +858,14 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_MENUSEARCH:
-               MenuSearch();
+       {
+               // Ok this is one _very_ bad solution, but I think that some
+               // of this will be rewritten as part of GUI indep anyway.
+               // Lgb
+               static LyXFindReplace FR_;
+               FR_.StartSearch(owner->view());
+       }
+       
                break;
                
        case LFUN_PASTE:
@@ -941,7 +954,7 @@ string LyXFunc::Dispatch(int ac,
                
        case LFUN_TEX:
                Tex();
-               owner->view()->SetState();
+               owner->view()->setState();
                owner->getMiniBuffer()->Set(CurrentState());
                break;
                
@@ -964,7 +977,7 @@ string LyXFunc::Dispatch(int ac,
                        }
                else
                        Foot(owner->view()); 
-               owner->view()->SetState();
+               owner->view()->setState();
                break;
 
        case LFUN_MARGINMELT:
@@ -977,7 +990,7 @@ string LyXFunc::Dispatch(int ac,
                                Melt(owner->view());
                } else
                        Margin(owner->view()); 
-               owner->view()->SetState();
+               owner->view()->setState();
                break;
                
                // --- version control -------------------------------
@@ -1084,7 +1097,7 @@ string LyXFunc::Dispatch(int ac,
                // and current buffer's textclass (number). */    
                LyXTextClassList::ClassList::size_type tclass =
                        owner->view()->text->parameters->textclass;
-               pair <bool, int> layout = 
+               pair <bool, LyXTextClass::size_type> layout = 
                        textclasslist.NumberOfLayout(tclass, argument);
 
                // If the entry is obsolete, use the new one instead.
@@ -1104,7 +1117,7 @@ string LyXFunc::Dispatch(int ac,
                }
 
                if (current_layout != layout.second) {
-                       owner->view()->getScreen()->HideCursor();
+                       owner->view()->hideCursor();
                        current_layout = layout.second;
                        owner->view()->update(-2);
                        owner->view()->text->
@@ -1161,7 +1174,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_RTL:
        {
                RTLCB();
-               owner->view()->SetState();
+               owner->view()->setState();
                owner->getMiniBuffer()->Set(CurrentState());
        }
                break;
@@ -1247,7 +1260,7 @@ string LyXFunc::Dispatch(int ac,
                                inset->setFlag(InsetRef::PAGE_REF);
                        else
                                inset->setFlag(InsetRef::REF);
-                       UpdateInset(owner->view(), inset);
+                       owner->view()->updateInset(inset, true);
                } else {
                        setErrorMessage(N_("No cross-reference to toggle"));
                }
@@ -1283,7 +1296,7 @@ string LyXFunc::Dispatch(int ac,
                
        case LFUN_SPELLCHECK:
                if (lyxrc->isp_command != "none")
-                       ShowSpellChecker();
+                       ShowSpellChecker(owner->view());
                break; // RVDK_PATCH_5
                
                // --- Cursor Movements -----------------------------
@@ -1301,10 +1314,10 @@ string LyXFunc::Dispatch(int ac,
                    && tmptext->cursor.par->GetChar(tmptext->cursor.pos)
                    == LyXParagraph::META_INSET
                    && tmptext->cursor.par->GetInset(tmptext->cursor.pos)
-                   && tmptext->cursor.par->GetInset(tmptext->cursor.pos)->Editable() == 2){
+                   && 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(0, 0);
+                       tmpinset->Edit(owner->view(), 0, 0, 0);
                        break;
                }
                if (direction == LYX_DIR_LEFT_TO_RIGHT)
@@ -1317,7 +1330,6 @@ string LyXFunc::Dispatch(int ac,
                
        case LFUN_LEFT:
        {
-#ifdef USE_PAINTER
                // This is soooo ugly. Isn`t it possible to make
                // it simpler? (Lgb)
                LyXText * txt = owner->view()->text;
@@ -1330,12 +1342,14 @@ string LyXFunc::Dispatch(int ac,
                    && txt->cursor.par->GetChar(txt->cursor.pos)
                    == LyXParagraph::META_INSET
                    && txt->cursor.par->GetInset(txt->cursor.pos)
-                   && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
+                   && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == Inset::HIGHLY_EDITABLE) {
                        Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
                        setMessage(tmpinset->EditMessage());
-                       tmpinset->Edit(tmpinset->width(owner->view()->painter(),
+                       tmpinset->Edit(owner->view(),
+                                      tmpinset->width(owner->view()->painter(),
                                                       txt->GetFont(txt->cursor.par,
-                                                                   txt->cursor.pos)), 0);
+                                                                   txt->cursor.pos)),
+                                      0, 0);
                        break;
                }
                if  (direction == LYX_DIR_RIGHT_TO_LEFT)
@@ -1344,33 +1358,6 @@ string LyXFunc::Dispatch(int ac,
                owner->view()->text->FinishUndo();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
-#else
-               // This is soooo ugly. Isn`t it possible to make
-               // it simpler? (Lgb)
-               LyXText * txt = owner->view()->text;
-               LyXDirection direction = txt->cursor.par->getParDirection();
-               if(!txt->mark_set) owner->view()->beforeChange();
-               owner->view()->update(-2);
-               if (direction == LYX_DIR_LEFT_TO_RIGHT)
-                       txt->CursorLeft();
-               if (txt->cursor.pos < txt->cursor.par->Last()
-                   && txt->cursor.par->GetChar(txt->cursor.pos)
-                   == LyXParagraph::META_INSET
-                   && txt->cursor.par->GetInset(txt->cursor.pos)
-                   && txt->cursor.par->GetInset(txt->cursor.pos)->Editable() == 2) {
-                       Inset * tmpinset = txt->cursor.par->GetInset(txt->cursor.pos);
-                       setMessage(tmpinset->EditMessage());
-                       tmpinset->Edit(tmpinset->Width(txt->GetFont(txt->cursor.par,
-                                                                   txt->cursor.pos)), 0);
-                       break;
-               }
-               if  (direction == LYX_DIR_RIGHT_TO_LEFT)
-                       txt->CursorRight();
-
-               owner->view()->text->FinishUndo();
-               moveCursorUpdate(false);
-               owner->getMiniBuffer()->Set(CurrentState());
-#endif
        }
        break;
                
@@ -1643,20 +1630,28 @@ string LyXFunc::Dispatch(int ac,
 
                // --- text changing commands ------------------------
        case LFUN_BREAKLINE:
+#if 1
                owner->view()->beforeChange();
                owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
                owner->view()->smallUpdate(1);
                SetUpdateTimer(0.01);
                moveCursorUpdate(false);
+#else
+               owner->view()->newline();
+#endif
                break;
                
        case LFUN_PROTECTEDSPACE:
+#if 1
+               owner->view()->protectedBlank();
+#else
                owner->view()->beforeChange();
                owner->view()->text->
                        InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
                owner->view()->smallUpdate(1);
                SetUpdateTimer();
                 moveCursorUpdate(false);
+#endif
                break;
                
        case LFUN_SETMARK:
@@ -1683,14 +1678,14 @@ string LyXFunc::Dispatch(int ac,
                        owner->view()->smallUpdate(1);
                        // It is possible to make it a lot faster still
                        // just comment out the lone below...
-                       owner->view()->getScreen()->ShowCursor();
+                       owner->view()->showCursor();
                } else {
                        owner->view()->cut();
                }
                SetUpdateTimer();
                moveCursorUpdate(false);
                owner->getMiniBuffer()->Set(CurrentState());
-               owner->view()->SetState();
+               owner->view()->setState();
                break;
 
        case LFUN_DELETE_SKIP:
@@ -1800,14 +1795,14 @@ string LyXFunc::Dispatch(int ac,
                                owner->view()->smallUpdate(1);
                                // It is possible to make it a lot faster still
                                // just comment out the lone below...
-                               owner->view()->getScreen()->ShowCursor();
+                               owner->view()->showCursor();
                        }
                } else {
                        owner->view()->cut();
                }
                SetUpdateTimer();
                owner->getMiniBuffer()->Set(CurrentState());
-               owner->view()->SetState();
+               owner->view()->setState();
        }
        break;
 
@@ -1851,7 +1846,7 @@ string LyXFunc::Dispatch(int ac,
                SetUpdateTimer(0.01);
                owner->view()->text->sel_cursor = 
                        owner->view()->text->cursor;
-               owner->view()->SetState();
+               owner->view()->setState();
                owner->getMiniBuffer()->Set(CurrentState());
                break;
        }
@@ -1864,7 +1859,7 @@ string LyXFunc::Dispatch(int ac,
                SetUpdateTimer(0.01);
                owner->view()->text->sel_cursor = 
                        owner->view()->text->cursor;
-               owner->view()->SetState();
+               owner->view()->setState();
                owner->getMiniBuffer()->Set(CurrentState());
                break;
        }
@@ -1897,7 +1892,7 @@ string LyXFunc::Dispatch(int ac,
                }
                SetUpdateTimer(0.01);
                owner->view()->text->sel_cursor = cursor;
-               owner->view()->SetState();
+               owner->view()->setState();
                owner->getMiniBuffer()->Set(CurrentState());
        }
        break;
@@ -1919,7 +1914,27 @@ string LyXFunc::Dispatch(int ac,
                else
                        new_inset = new InsetUrl("url", "", "");
                owner->view()->insertInset(new_inset);
-               new_inset->Edit(0, 0);
+               new_inset->Edit(owner->view(), 0, 0, 0);
+       }
+       break;
+       case LFUN_INSET_TEXT:
+       {
+               InsetText * new_inset = new InsetText(owner->buffer());
+               owner->view()->insertInset(new_inset);
+               new_inset->Edit(owner->view(), 0, 0, 0);
+       }
+       break;
+       case LFUN_INSET_ERT:
+       {
+               InsetERT * new_inset = new InsetERT(owner->buffer());
+               owner->view()->insertInset(new_inset);
+               new_inset->Edit(owner->view(), 0, 0, 0);
+       }
+       case LFUN_INSET_FOOTNOTE:
+       {
+               InsetFoot * new_inset = new InsetFoot(owner->buffer());
+               owner->view()->insertInset(new_inset);
+               new_inset->Edit(owner->view(), 0, 0, 0);
        }
        break;
 
@@ -2015,28 +2030,7 @@ string LyXFunc::Dispatch(int ac,
                owner->view()->setCursorFromRow(row);
 
                // Recenter screen
-               owner->view()->beforeChange();
-               if (owner->view()->text->cursor.y >
-#ifdef NEW_WA
-                   owner->view()->getWorkArea()->height() / 2
-#else
-                   owner->view()->getWorkArea()->h / 2
-#endif
-                       ) {
-                       owner->view()->getScreen()->
-                               Draw(owner->view()->text->cursor.y -
-#ifdef NEW_WA
-                                    owner->view()->getWorkArea()->height() / 2
-#else
-                                    owner->view()->getWorkArea()->h / 2
-#endif
-                                       );
-               } else { // <= 
-                       owner->view()->getScreen()->
-                               Draw(0);
-               }
-               owner->view()->update(0);
-               owner->view()->redraw();
+               owner->view()->center();
        }
        break;
 
@@ -2164,8 +2158,11 @@ string LyXFunc::Dispatch(int ac,
                if (owner->view()->available()) { 
                        owner->view()->
                                open_new_inset(new InsetFormula(false));
-                       owner->view()->
-                               the_locking_inset->LocalDispatch(action, argument.c_str());
+                       owner->view()
+                               ->the_locking_inset
+                               ->LocalDispatch(owner->view(),
+                                               action,
+                                               argument);
                }
        }          
        break;
@@ -2231,7 +2228,7 @@ string LyXFunc::Dispatch(int ac,
                        owner->view()->insertInset(new_inset);
                } else {
                        owner->view()->insertInset(new_inset);
-                       new_inset->Edit(0, 0);
+                       new_inset->Edit(owner->view(), 0, 0, 0);
                }
        }
        break;
@@ -2252,7 +2249,7 @@ string LyXFunc::Dispatch(int ac,
                
                owner->view()->insertInset(new_inset);
                if (lsarg.empty()) {
-                       new_inset->Edit(0, 0);
+                       new_inset->Edit(owner->view(), 0, 0, 0);
                }
        }
        break;
@@ -2318,7 +2315,7 @@ string LyXFunc::Dispatch(int ac,
 
                        //don't edit it if the call was to INSERT_LAST
                        if(action != LFUN_INDEX_INSERT_LAST) {
-                               new_inset->Edit(0, 0);
+                               new_inset->Edit(owner->view(), 0, 0, 0);
                        } else {
                                //it looks blank on the screen unless
                                //we do  something.  put it here.
@@ -2356,7 +2353,7 @@ string LyXFunc::Dispatch(int ac,
                Inset * new_inset = new InsetInclude(argument,
                                                     owner->buffer());
                owner->view()->insertInset(new_inset, "Standard", true);
-               new_inset->Edit(0, 0);
+               new_inset->Edit(owner->view(), 0, 0, 0);
        }
        break;
 
@@ -2402,7 +2399,7 @@ string LyXFunc::Dispatch(int ac,
                }
                owner->view()->text->InsertFootnoteEnvironment(kind);
                owner->view()->update(1);
-               owner->view()->SetState();
+               owner->view()->setState();
        }
        break;