]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
- Link against qt-mt333.lib which is what the current qt3 cvs produces
[lyx.git] / src / BufferView_pimpl.C
index 35298307d71f5f6032730590ba305bb250643e3a..7491e27213e26af48a1458d9a254455cdedc8ea5 100644 (file)
@@ -34,6 +34,7 @@
 #include "gettext.h"
 #include "intl.h"
 #include "insetiterator.h"
+#include "LaTeXFeatures.h"
 #include "lyx_cb.h" // added for Dispatch functions
 #include "lyx_main.h"
 #include "lyxfind.h"
@@ -56,6 +57,7 @@
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
+#include "frontends/font_metrics.h"
 #include "frontends/LyXView.h"
 #include "frontends/LyXScreenFactory.h"
 #include "frontends/screen.h"
 
 #include "graphics/Previews.h"
 
+#include "support/convert.h"
 #include "support/filefilterlist.h"
 #include "support/filetools.h"
 #include "support/forkedcontr.h"
-#include "support/path_defines.h"
-#include "support/tostr.h"
+#include "support/package.h"
 #include "support/types.h"
 
 #include <boost/bind.hpp>
@@ -85,8 +87,7 @@ using lyx::support::ForkedcallsController;
 using lyx::support::IsDirWriteable;
 using lyx::support::MakeDisplayPath;
 using lyx::support::MakeAbsPath;
-using lyx::support::strToUnsignedInt;
-using lyx::support::system_lyxdir;
+using lyx::support::package;
 
 using std::endl;
 using std::istringstream;
@@ -337,7 +338,7 @@ void BufferView::Pimpl::setBuffer(Buffer * b)
        cursor_ = LCursor(*bv_);
        anchor_ref_ = 0;
        offset_ref_ = 0;
-       
+
 
        // if we're quitting lyx, don't bother updating stuff
        if (quitting)
@@ -410,7 +411,7 @@ void BufferView::Pimpl::updateScrollbar()
                anchor_ref_ = int(t.paragraphs().size()) - 1;
                offset_ref_ = 0;
        }
-           
+
        lyxerr[Debug::GUI]
                << "Updating scrollbar: height: " << t.paragraphs().size()
                << " curr par: " << bv_->cursor().bottom().pit()
@@ -454,7 +455,7 @@ void BufferView::Pimpl::scrollDocView(int value)
        int const first = height;
        int const last = workarea().workHeight() - height;
        LCursor & cur = bv_->cursor();
-       
+
        bv_funcs::CurStatus st = bv_funcs::status(bv_, cur);
 
        switch (st) {
@@ -586,8 +587,9 @@ void BufferView::Pimpl::workAreaResize()
 bool BufferView::Pimpl::fitCursor()
 {
        if (bv_funcs::status(bv_, bv_->cursor()) == bv_funcs::CUR_INSIDE) {
-               int asc, des;
-               bv_->cursor().getDim(asc, des);
+               LyXFont const font = bv_->cursor().getFont();
+               int const asc = font_metrics::maxAscent(font);
+               int const des = font_metrics::maxDescent(font);
                Point p = bv_funcs::getPos(bv_->cursor());
                if (p.y_ - asc >= 0 && p.y_ + des < bv_->workHeight())
                        return false;
@@ -601,7 +603,7 @@ void BufferView::Pimpl::update(bool fitcursor, bool forceupdate)
 {
        lyxerr << "BufferView::Pimpl::update(fc=" << fitcursor << ", fu="
               << forceupdate << ")  buffer: " << buffer_ << endl;
-       
+
        // check needed to survive LyX startup
        if (buffer_) {
                // update macro store
@@ -680,7 +682,7 @@ void BufferView::Pimpl::savePosition(unsigned int i)
                                      bv_->cursor().paragraph().id(),
                                      bv_->cursor().pos());
        if (i > 0)
-               owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
+               owner_->message(bformat(_("Saved bookmark %1$d"), i));
 }
 
 
@@ -713,7 +715,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
                min(par->size(), saved_positions[i].par_pos));
 
        if (i > 0)
-               owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
+               owner_->message(bformat(_("Moved to bookmark %1$d"), i));
 }
 
 
@@ -777,7 +779,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
                        make_pair(string(_("Documents|#o#O")),
                                  string(lyxrc.document_path)),
                        make_pair(string(_("Examples|#E#e")),
-                                 string(AddPath(system_lyxdir(), "examples"))));
+                                 string(AddPath(package().system_support(), "examples"))));
 
                FileDialog::Result result =
                        fileDlg.open(initpath,
@@ -958,17 +960,26 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
        case LFUN_MARK_ON:
        case LFUN_SETMARK:
        case LFUN_CENTER:
+       case LFUN_WORDS_COUNT:
                flag.enabled(true);
                break;
-               
+
        case LFUN_BOOKMARK_GOTO:
-               flag.enabled(bv_->isSavedPosition(strToUnsignedInt(cmd.argument)));
+               flag.enabled(bv_->isSavedPosition(convert<unsigned int>(cmd.argument)));
                break;
        case LFUN_TRACK_CHANGES:
                flag.enabled(true);
                flag.setOnOff(buf->params().tracking_changes);
                break;
 
+       case LFUN_OUTPUT_CHANGES: {
+               LaTeXFeatures features(*buf, buf->params(), false);
+               flag.enabled(buf && buf->params().tracking_changes
+                       && features.isAvailable("dvipost"));
+               flag.setOnOff(buf->params().output_changes);
+               break;
+       }
+
        case LFUN_MERGE_CHANGES:
        case LFUN_ACCEPT_CHANGE: // what about these two
        case LFUN_REJECT_CHANGE: // what about these two
@@ -1040,11 +1051,11 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_BOOKMARK_SAVE:
-               savePosition(strToUnsignedInt(cmd.argument));
+               savePosition(convert<unsigned int>(cmd.argument));
                break;
 
        case LFUN_BOOKMARK_GOTO:
-               restorePosition(strToUnsignedInt(cmd.argument));
+               restorePosition(convert<unsigned int>(cmd.argument));
                break;
 
        case LFUN_REF_GOTO: {
@@ -1068,6 +1079,13 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
                trackChanges();
                break;
 
+       case LFUN_OUTPUT_CHANGES: {
+               Buffer * buf = bv_->buffer();
+               bool const state = buf->params().output_changes;
+               buf->params().output_changes = !state;
+               break;
+       }
+
        case LFUN_MERGE_CHANGES:
                owner_->getDialogs().show("changes");
                break;
@@ -1130,6 +1148,35 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
                bv_->center();
                break;
 
+       case LFUN_WORDS_COUNT: {
+               DocIterator from, to;
+               if (cur.selection()) {
+                       from = cur.selectionBegin();
+                       to = cur.selectionEnd();
+               } else {
+                       from = doc_iterator_begin(bv_->buffer()->inset());
+                       to = doc_iterator_end(bv_->buffer()->inset());
+               }
+               int const count = countWords(from, to);
+               string message;
+               if (count != 1) {
+                       if (cur.selection())
+                               message = bformat(_("%1$d words in selection."),
+                                         count);
+                               else
+                                       message = bformat(_("%1$d words in document."),
+                                                         count);
+               }
+               else {
+                       if (cur.selection())
+                               message = _("One word in selection.");
+                       else
+                               message = _("One word in document.");
+               }
+
+               Alert::information(_("Count words"), message);
+       }
+               break;
        default:
                return false;
        }
@@ -1153,13 +1200,13 @@ ViewMetricsInfo BufferView::Pimpl::metrics()
        int pit1 = pit;
        int pit2 = pit;
        size_t npit = text->paragraphs().size();
-       lyxerr << "npit: " << npit << " pit1: " << pit1 
+       lyxerr << "npit: " << npit << " pit1: " << pit1
                << " pit2: " << pit2 << endl;
 
-       // rebreak anchor par   
+       // rebreak anchor par
        text->redoParagraph(pit);
        int y0 = text->getPar(pit1).ascent() - offset_ref_;
-       
+
        // redo paragraphs above cursor if necessary
        int y1 = y0;
        while (y1 > 0 && pit1 > 0) {
@@ -1169,7 +1216,7 @@ ViewMetricsInfo BufferView::Pimpl::metrics()
                y1 -= text->getPar(pit1).descent();
        }
 
-       
+
        // take care of ascent of first line
        y1 -= text->getPar(pit1).ascent();
 
@@ -1183,7 +1230,7 @@ ViewMetricsInfo BufferView::Pimpl::metrics()
                y1 = 0;
                anchor_ref_ = 0;
        }
-       
+
        // redo paragraphs below cursor if necessary
        int y2 = y0;
        while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
@@ -1193,7 +1240,7 @@ ViewMetricsInfo BufferView::Pimpl::metrics()
                y2 += text->getPar(pit2).ascent();
        }
 
-       // take care of descent of last line 
+       // take care of descent of last line
        y2 += text->getPar(pit2).descent();
 
        // the coordinates of all these paragraphs are correct, cache them
@@ -1203,7 +1250,7 @@ ViewMetricsInfo BufferView::Pimpl::metrics()
                theCoords.pars_[text][pit] = Point(0, y);
                y += text->getPar(pit).descent();
        }
-       
+
        lyxerr << "bv:metrics:  y1: " << y1 << " y2: " << y2 << endl;
        return ViewMetricsInfo(pit1, pit2, y1, y2);
 }