]> git.lyx.org Git - features.git/blobdiff - src/BufferView_pimpl.C
move floatlist to textclass
[features.git] / src / BufferView_pimpl.C
index 40c4069c47a8f13e10254ee72972bcb5a80d2b5a..737d6aaea2483700f2a6ef8aecab3dde69d1350c 100644 (file)
@@ -40,7 +40,6 @@
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
 #include "funcrequest.h"
-#include "language.h"
 
 #include "insets/insetbib.h"
 #include "insets/insettext.h"
 #include "insets/insetref.h"
 #include "insets/insetparent.h"
 #include "insets/insetindex.h"
-#include "insets/insetnote.h"
 #include "insets/insetinclude.h"
 #include "insets/insetcite.h"
-#include "insets/insetert.h"
-#include "insets/insetexternal.h"
 #include "insets/insetgraphics.h"
-#include "insets/insetfoot.h"
 #include "insets/insetmarginal.h"
-#include "insets/insetminipage.h"
-#include "insets/insetfloat.h"
-#include "insets/insettabular.h"
-#include "insets/insetoptarg.h"
-#if 0
-#include "insets/insettheorem.h"
-#include "insets/insetlist.h"
-#endif
 #include "insets/insetcaption.h"
 #include "insets/insetfloatlist.h"
 
 #include "support/LAssert.h"
 #include "support/lstrings.h"
 #include "support/filetools.h"
-#include "support/lyxfunctional.h"
 
 #include <boost/bind.hpp>
 #include <boost/signals/connection.hpp>
 
-#include <cstdio>
-#include <ctime>
 #include <unistd.h>
 #include <sys/wait.h>
-#include <clocale>
 
 
-#ifndef CXX_GLOBAL_CSTD
-using std::tm;
-using std::localtime;
-using std::time;
-using std::setlocale;
-using std::strftime;
-#endif
-
 using std::vector;
 using std::find_if;
 using std::find;
@@ -105,15 +80,12 @@ using std::make_pair;
 using std::min;
 
 using lyx::pos_type;
-using lyx::textclass_type;
 
 /* the selection possible is needed, that only motion events are
  * used, where the bottom press event was on the drawing area too */
 bool selection_possible = false;
 
 extern BufferList bufferlist;
-extern char ascii_type;
-
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 
@@ -895,7 +867,7 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
        LyXCursor cursor;
        text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
 
-       Inset * inset(checkInset(*text, cursor, x, y_tmp));
+       Inset * inset = checkInset(*text, cursor, x, y_tmp);
 
        if (inset) {
                y = y_tmp;
@@ -903,7 +875,6 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
        }
 
        // look at previous position
-
        if (cursor.pos() == 0) {
                return 0;
        }
@@ -945,7 +916,7 @@ void BufferView::Pimpl::workAreaResize()
                        if (lyxerr.debugging())
                                textcache.show(lyxerr, "Expose delete all");
                        textcache.clear();
-                       // FIXME: this is aalready done in resizeCurrentBuffer() ??
+                       // FIXME: this is already done in resizeCurrentBuffer() ??
                        buffer_->resizeInsets(bv_);
                } else if (heightChange) {
                        // fitCursor() ensures we don't jump back
@@ -1099,14 +1070,6 @@ void BufferView::Pimpl::beforeChange(LyXText * text)
 }
 
 
-void BufferView::Pimpl::finishChange(bool fitcur)
-{
-       finishUndo();
-       moveCursorUpdate(fitcur);
-       bv_->owner()->view_state_changed();
-}
-
-
 void BufferView::Pimpl::savePosition(unsigned int i)
 {
        if (i >= saved_positions_num)
@@ -1261,36 +1224,6 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const
  */
 
 
-void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
-{
-       LyXText * lt = bv_->getLyXText();
-
-       if (selecting || lt->selection.mark()) {
-               lt->setSelection(bv_);
-               if (lt->bv_owner)
-                       toggleToggle();
-               else
-                       updateInset(lt->inset_owner, false);
-       }
-       if (lt->bv_owner) {
-               if (fitcur)
-                       update(lt, BufferView::SELECT|BufferView::FITCUR);
-               else
-                       update(lt, BufferView::SELECT);
-               showCursor();
-       } else if (bv_->text->status() != LyXText::UNCHANGED) {
-               bv_->theLockingInset()->hideInsetCursor(bv_);
-               update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
-               showCursor();
-       }
-
-       if (!lt->selection.set())
-               workarea().haveSelection(false);
-
-       switchKeyMap();
-}
-
-
 Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
 {
 #if 0
@@ -1442,19 +1375,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                break;
        }
 
-       case LFUN_PASTE:
-               bv_->paste();
-               switchKeyMap();
-               break;
-
-       case LFUN_CUT:
-               bv_->cut();
-               break;
-
-       case LFUN_COPY:
-               bv_->copy();
-               break;
-
        case LFUN_LAYOUT_COPY:
                bv_->copyEnvironment();
                break;
@@ -1464,23 +1384,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                switchKeyMap();
                break;
 
-       case LFUN_GOTOERROR:
-               gotoInset(Inset::ERROR_CODE, false);
-               break;
-
-       case LFUN_GOTONOTE:
-               gotoInset(Inset::NOTE_CODE, false);
-               break;
-
-       case LFUN_REFERENCE_GOTO:
-       {
-               vector<Inset::Code> tmp;
-               tmp.push_back(Inset::LABEL_CODE);
-               tmp.push_back(Inset::REF_CODE);
-               gotoInset(tmp, true);
-               break;
-       }
-
        case LFUN_DEPTH_MIN:
                changeDepth(bv_, bv_->getLyXText(), -1);
                break;
@@ -1610,10 +1513,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        }
        break;
 
-       case LFUN_QUOTE:
-               smartQuote();
-               break;
-
        case LFUN_HTMLURL:
        case LFUN_URL:
        {
@@ -1639,68 +1538,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        }
        break;
 
-       case LFUN_INSET_ERT:
-               insertAndEditInset(new InsetERT(buffer_->params));
-               break;
-
-       case LFUN_INSET_EXTERNAL:
-               insertAndEditInset(new InsetExternal);
-               break;
-
-       case LFUN_INSET_FOOTNOTE:
-               insertAndEditInset(new InsetFoot(buffer_->params));
-               break;
-
-       case LFUN_INSET_MARGINAL:
-               insertAndEditInset(new InsetMarginal(buffer_->params));
-               break;
-
-       case LFUN_INSET_MINIPAGE:
-               insertAndEditInset(new InsetMinipage(buffer_->params));
-               break;
-
-       case LFUN_INSERT_NOTE:
-               insertAndEditInset(new InsetNote(buffer_->params));
-               break;
-
-       case LFUN_INSET_OPTARG:
-               insertAndEditInset(new InsetOptArg(buffer_->params));
-               break;
-
-       case LFUN_INSET_FLOAT:
-               // check if the float type exist
-               if (floatList.typeExist(ev.argument)) {
-                       insertAndEditInset(new InsetFloat(buffer_->params,
-                                                         ev.argument));
-               } else {
-                       lyxerr << "Non-existent float type: "
-                              << ev.argument << endl;
-               }
-               break;
-
-       case LFUN_INSET_WIDE_FLOAT:
-               // check if the float type exist
-               if (floatList.typeExist(ev.argument)) {
-                       InsetFloat * new_inset =
-                               new InsetFloat(buffer_->params, ev.argument);
-                       new_inset->wide(true);
-                       insertAndEditInset(new_inset);
-               } else {
-                       lyxerr << "Non-existent float type: "
-                              << ev.argument << endl;
-               }
-               break;
-
-#if 0
-       case LFUN_INSET_LIST:
-               insertAndEditInset(new InsetList);
-               break;
-
-       case LFUN_INSET_THEOREM:
-               insertAndEditInset(new InsetTheorem);
-               break;
-#endif
-
        case LFUN_INSET_CAPTION:
        {
                // Do we have a locking inset...
@@ -1721,25 +1558,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        }
        break;
 
-       case LFUN_TABULAR_INSERT:
-       {
-               if (ev.argument.empty()) {
-                       owner_->getDialogs().showTabularCreate();
-                       break;
-               }
-
-               int r = 2;
-               int c = 2;
-               ::sscanf(ev.argument.c_str(),"%d%d", &r, &c);
-               InsetTabular * new_inset =
-                       new InsetTabular(*buffer_, r, c);
-               bool const rtl =
-                       bv_->getLyXText()->real_current_font.isRightToLeft();
-               if (!open_new_inset(new_inset, rtl))
-                       delete new_inset;
-       }
-       break;
-
 
        // --- accented characters ---------------------------
 
@@ -1907,7 +1725,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        break;
 
        case LFUN_FLOAT_LIST:
-               if (floatList.typeExist(ev.argument)) {
+               if (tclass.floats().typeExist(ev.argument)) {
                        Inset * inset = new InsetFloatList(ev.argument);
                        if (!insertInset(inset, tclass.defaultLayoutName()))
                                delete inset;
@@ -1938,35 +1756,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        }
                break;
 
-       case LFUN_DATE_INSERT:  // jdblair: date-insert cmd
-       {
-               time_t now_time_t = time(NULL);
-               struct tm * now_tm = localtime(&now_time_t);
-               setlocale(LC_TIME, "");
-               string arg;
-               if (!ev.argument.empty())
-                       arg = ev.argument;
-               else
-                       arg = lyxrc.date_insert_format;
-               char datetmp[32];
-               int const datetmp_len =
-                       ::strftime(datetmp, 32, arg.c_str(), now_tm);
-
-               LyXText * lt = bv_->getLyXText();
-
-               for (int i = 0; i < datetmp_len; i++) {
-                       lt->insertChar(bv_, datetmp[i]);
-                       update(lt,
-                              BufferView::SELECT
-                              | BufferView::FITCUR
-                              | BufferView::CHANGE);
-               }
-
-               lt->selection.cursor = lt->cursor;
-               moveCursorUpdate(false);
-       }
-       break;
-
        case LFUN_UNKNOWN_ACTION:
                ev.errorMessage(N_("Unknown function!"));
                break;
@@ -1981,74 +1770,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
 }
 
 
-void BufferView::Pimpl::smartQuote()
-{
-       LyXText const * lt = bv_->getLyXText();
-       Paragraph const * par = lt->cursor.par();
-       pos_type pos = lt->cursor.pos();
-       char c;
-
-       if (!pos
-           || (par->isInset(pos - 1)
-               && par->getInset(pos - 1)->isSpace()))
-               c = ' ';
-       else
-               c = par->getChar(pos - 1);
-
-       hideCursor();
-
-       LyXLayout_ptr const & style = par->layout();
-
-       if (style->pass_thru ||
-           par->getFontSettings(buffer_->params,
-                                pos).language()->lang() == "hebrew" ||
-               (!insertInset(new InsetQuotes(c, buffer_->params))))
-               bv_->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
-}
-
-
-void BufferView::Pimpl::insertAndEditInset(Inset * inset)
-{
-#if 0
-       if (insertInset(inset))
-               inset->edit(bv_);
-       else
-               delete inset;
-#else
-       bool gotsel = false;
-
-       if (bv_->getLyXText()->selection.set()) {
-               bv_->getLyXText()->cutSelection(bv_, true, false);
-               gotsel = true;
-       }
-
-       if (insertInset(inset)) {
-               inset->edit(bv_);
-               if (gotsel)
-                       owner_->dispatch(FuncRequest(LFUN_PASTESELECTION));
-       }
-       else
-               delete inset;
-#endif
-}
-
-
-// Open and lock an updatable inset
-bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
-{
-       LyXText * lt = bv_->getLyXText();
-
-       beforeChange(lt);
-       finishUndo();
-       if (!insertInset(new_inset)) {
-               delete new_inset;
-               return false;
-       }
-       new_inset->edit(bv_, !behind);
-       return true;
-}
-
-
 bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
 {
        // if we are in a locking inset we should try to insert the
@@ -2167,50 +1888,3 @@ void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
                }
        }
 }
-
-
-void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
-                                 bool same_content)
-{
-       if (!available()) return;
-
-       hideCursor();
-       beforeChange(bv_->text);
-       update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
-
-       LyXCursor const & cursor = bv_->text->cursor;
-
-       string contents;
-       if (same_content &&
-           cursor.par()->isInset(cursor.pos())) {
-               Inset const * inset = cursor.par()->getInset(cursor.pos());
-               if (find(codes.begin(), codes.end(), inset->lyxCode())
-                   != codes.end())
-                       contents =
-                               static_cast<InsetCommand const *>(inset)->getContents();
-       }
-
-
-       if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
-               if (bv_->text->cursor.pos()
-                   || bv_->text->cursor.par() != bv_->text->ownerParagraph()) {
-                       LyXCursor tmp = bv_->text->cursor;
-                       bv_->text->cursor.par(bv_->text->ownerParagraph());
-                       bv_->text->cursor.pos(0);
-                       if (!bv_->text->gotoNextInset(bv_, codes, contents)) {
-                               bv_->text->cursor = tmp;
-                               bv_->owner()->message(_("No more insets"));
-                       }
-               } else {
-                       bv_->owner()->message(_("No more insets"));
-               }
-       }
-       update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
-       bv_->text->selection.cursor = bv_->text->cursor;
-}
-
-
-void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
-{
-       gotoInset(vector<Inset::Code>(1, code), same_content);
-}