]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbibitem.C
the convert patch
[lyx.git] / src / insets / insetbibitem.C
index 3b18f098546527befba9f237da965e874af46e2b..19144e23104a65c0388056698498f82d43af5757 100644 (file)
 #include "lyxfont.h"
 #include "lyxlex.h"
 #include "paragraph.h"
+#include "ParagraphList_fwd.h"
 
 #include "frontends/font_metrics.h"
 
 #include "support/lstrings.h"
-#include "support/tostr.h"
+#include "support/std_ostream.h"
+#include "support/convert.h"
 
 using lyx::support::prefixIs;
-using lyx::support::strToInt;
 
 using std::max;
 using std::string;
 using std::auto_ptr;
-
+using std::ostream;
 
 int InsetBibitem::key_counter = 0;
 string const key_prefix = "key-";
 
 
 InsetBibitem::InsetBibitem(InsetCommandParams const & p)
-       : InsetCommand(p), counter(1)
+       : InsetCommand(p, "bibitem"), counter(1)
 {
        if (getContents().empty())
-               setContents(key_prefix + tostr(++key_counter));
-}
-
-
-InsetBibitem::~InsetBibitem()
-{
-       InsetCommandMailer("bibitem", *this).hideDialog();
+               setContents(key_prefix + convert<string>(++key_counter));
 }
 
 
-auto_ptr<InsetBase> InsetBibitem::clone() const
+auto_ptr<InsetBase> InsetBibitem::doClone() const
 {
        auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
        b->setCounter(counter);
@@ -59,29 +54,21 @@ auto_ptr<InsetBase> InsetBibitem::clone() const
 }
 
 
-DispatchResult
-InsetBibitem::priv_dispatch(FuncRequest const & cmd,
-                           idx_type & idx, pos_type & pos)
+void InsetBibitem::doDispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
-       case LFUN_MOUSE_PRESS:
-               InsetCommandMailer("bibitem", *this).showDialog(cmd.view());
-               return DispatchResult(true, true);
-
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p;
-               InsetCommandMailer::string2params(cmd.argument, p);
-               if (p.getCmdName().empty())
-                       return DispatchResult(true, true);
-               setParams(p);
-               cmd.view()->update();
-               cmd.view()->fitCursor();
-               return DispatchResult(true, true);
+               InsetCommandMailer::string2params("bibitem", cmd.argument, p);
+               if (!p.getCmdName().empty())
+                       setParams(p);
+               break;
        }
 
        default:
-               return InsetCommand::priv_dispatch(cmd, idx, pos);
+               InsetCommand::doDispatch(cur, cmd);
+               break;
        }
 }
 
@@ -109,14 +96,13 @@ void InsetBibitem::write(Buffer const &, std::ostream & os) const
 // This should be changed!!! (Jug)
 void InsetBibitem::read(Buffer const &, LyXLex & lex)
 {
-       if (lex.eatLine()) {
+       if (lex.eatLine())
                scanCommand(lex.getString());
-       } else {
+       else
                lex.printError("InsetCommand: Parse error: `$$Token'");
-       }
 
        if (prefixIs(getContents(), key_prefix)) {
-               int key = strToInt(getContents().substr(key_prefix.length()));
+               int const key = convert<int>(getContents().substr(key_prefix.length()));
                key_counter = max(key_counter, key);
        }
 }
@@ -124,7 +110,7 @@ void InsetBibitem::read(Buffer const &, LyXLex & lex)
 
 string const InsetBibitem::getBibLabel() const
 {
-       return getOptions().empty() ? tostr(counter) : getOptions();
+       return getOptions().empty() ? convert<string>(counter) : getOptions();
 }
 
 
@@ -133,6 +119,12 @@ string const InsetBibitem::getScreenLabel(Buffer const &) const
        return getContents() + " [" + getBibLabel() + ']';
 }
 
+int InsetBibitem::plaintext(Buffer const &, ostream & os,
+                           OutputParams const &) const
+{
+       os << '[' << getCounter() << "] ";
+       return 0;
+}
 
 // ale070405 This function maybe shouldn't be here. We'll fix this at 0.13.
 int bibitemMaxWidth(BufferView * bv, LyXFont const &)
@@ -144,7 +136,9 @@ int bibitemMaxWidth(BufferView * bv, LyXFont const &)
        ParagraphList::iterator end = bv->buffer()->paragraphs().end();
        for (; it != end; ++it) {
                if (it->bibitem()) {
+#ifdef WITH_WARNINGS
 #warning metrics broken!
+#endif
                        int const wx = it->bibitem()->width();
                        if (wx > w)
                                w = wx;