]> git.lyx.org Git - features.git/blobdiff - src/insets/insetbib.C
read the Changelog
[features.git] / src / insets / insetbib.C
index 4fca380b18e547167db8835cac15490e27906dd6..73ac251a42d689b985b5dcd9b10c74645a7fe18c 100644 (file)
@@ -34,32 +34,14 @@ FD_bibitem_form * bibitem_form = 0;
 FD_bibitem_form * create_form_bibitem_form(void);
 
 
-extern "C" void bibitem_cb(FL_OBJECT *, long data)
+extern "C"
+void bibitem_cb(FL_OBJECT *, long data)
 {
-       switch (data)
-       {
-       case 1:
-       {
-               InsetBibKey::Holder * holder =
-                       static_cast<InsetBibKey::Holder*>
-                       (bibitem_form->bibitem_form->u_vdata);
-               
-               if(!holder->view->buffer()->isReadonly())
-               {
-                       InsetBibKey * inset = holder->inset;
-                       inset->setContents(fl_get_input(bibitem_form->key));
-                       inset->setOptions(fl_get_input(bibitem_form->label));
-                       fl_hide_form(bibitem_form->bibitem_form);
-                       // Does look like a hack? It is! (but will change at 0.13)
-                       holder->view->text->RedoParagraph();
-                       holder->view->update(1);
-                       break;
-               } // fall through to Cancel on RO-mode
-       }
-       case 0:
-               fl_hide_form(bibitem_form->bibitem_form);
-               break;
-        }
+       InsetBibKey::Holder * holder =
+               static_cast<InsetBibKey::Holder*>
+               (bibitem_form->bibitem_form->u_vdata);
+       
+       holder->inset->callback( bibitem_form, data );
 }
 
 
@@ -91,8 +73,8 @@ FD_bibitem_form * create_form_bibitem_form(void)
 }
 
 
-InsetBibKey::InsetBibKey(string const & key, string const & label):
-       InsetCommand("bibitem", key, label)
+InsetBibKey::InsetBibKey(string const & key, string const & label)
+       InsetCommand("bibitem", key, label)
 {
        counter = 1;
        if (key.empty())
@@ -100,8 +82,8 @@ InsetBibKey::InsetBibKey(string const & key, string const & label):
 }
 
 
-InsetBibKey::InsetBibKey(InsetBibKey const * b):
-       InsetCommand("bibitem", b->getContents(), b->getOptions())
+InsetBibKey::InsetBibKey(InsetBibKey const * b)
+       InsetCommand("bibitem", b->getContents(), b->getOptions())
 {
        counter = b->counter;
 }
@@ -115,6 +97,25 @@ InsetBibKey::~InsetBibKey()
                fl_hide_form(bibitem_form->bibitem_form);
 }
 
+
+void InsetBibKey::callback( FD_bibitem_form * form, long data )
+{
+       switch (data) {
+       case 1:
+               if(!holder.view->buffer()->isReadonly()) {
+                       setContents(fl_get_input(form->key));
+                       setOptions(fl_get_input(form->label));
+                       // shouldn't mark the buffer dirty unless
+                       // something was actually altered
+                       holder.view->updateInset( this, true );
+               } // fall through to Cancel
+       case 0:
+               fl_hide_form(form->bibitem_form);
+               break;
+        }
+}
+
+
 void InsetBibKey::setCounter(int c) 
 { 
        counter = c; 
@@ -128,7 +129,7 @@ void InsetBibKey::setCounter(int c)
 // as a LyX 2.x command, and lyxlex is not enough smart to understand
 // real LaTeX commands. Yes, that could be fixed, but would be a waste 
 // of time cause LyX3 won't use lyxlex anyway.  (ale)
-void InsetBibKey::Write(ostream & os) const
+void InsetBibKey::Write(Buffer const *, ostream & os) const
 {
        os << "\\bibitem ";
        if (! getOptions().empty()) {
@@ -140,6 +141,20 @@ void InsetBibKey::Write(ostream & os) const
 }
 
 
+// This is necessary here because this is written without begin_inset
+// This should be changed!!! (Jug)
+void InsetBibKey::Read(Buffer const *, LyXLex & lex)
+{    
+       string token;
+
+       if (lex.EatLine()) {
+               token = lex.GetString();
+               scanCommand(token);
+       } else
+               lex.printError("InsetCommand: Parse error: `$$Token'");
+}
+
+
 string InsetBibKey::getScreenLabel() const
 {
        if (! getOptions().empty())
@@ -149,7 +164,7 @@ string InsetBibKey::getScreenLabel() const
 }
 
 
-/*
+/**
   The value in "Key:" isn't allways set right after a few bibkey insets have
   been added/removed.  Perhaps the wrong object is deleted/used somewhere
   upwards?
@@ -190,8 +205,8 @@ void InsetBibKey::Edit(BufferView * bv, int, int, unsigned int)
 InsetBibtex::InsetBibtex(string const & dbase, string const & style,
                         Buffer * o)
        : InsetCommand("BibTeX", dbase, style), owner(o)
-{
-}
+{}
+
 
 InsetBibtex::~InsetBibtex()
 {
@@ -208,7 +223,7 @@ string InsetBibtex::getScreenLabel() const
 }
 
 
-int InsetBibtex::Latex(ostream & os,
+int InsetBibtex::Latex(Buffer const *, ostream & os,
                       bool /*fragile*/, bool/*fs*/) const
 {
        // this looks like an horrible hack and it is :) The problem
@@ -366,7 +381,7 @@ bool InsetBibtex::delDatabase(string const & db)
 
 
 // ale070405 This function maybe shouldn't be here. We'll fix this at 0.13.
-int bibitemMaxWidth(Painter & pain, LyXFont const & font)
+int bibitemMaxWidth(BufferView * bv, LyXFont const & font)
 {
        int w = 0;
        // Does look like a hack? It is! (but will change at 0.13)
@@ -374,7 +389,7 @@ int bibitemMaxWidth(Painter & pain, LyXFont const & font)
     
        while (par) {
                if (par->bibkey) {
-                       int wx = par->bibkey->width(pain, font);
+                       int wx = par->bibkey->width(bv, font);
                        if (wx > w) w = wx;
                }
                par = par->next;
@@ -384,7 +399,7 @@ int bibitemMaxWidth(Painter & pain, LyXFont const & font)
 
 
 // ale070405
-string bibitemWidest(Painter & pain)
+string bibitemWidest(BufferView * bv)
 {
        int w = 0;
        // Does look like a hack? It is! (but will change at 0.13)
@@ -394,7 +409,7 @@ string bibitemWidest(Painter & pain)
       
        while (par) {
                if (par->bibkey) {
-                       int wx = par->bibkey->width(pain, font);
+                       int wx = par->bibkey->width(bv, font);
                        if (wx > w) {
                                w = wx;
                                bkey = par->bibkey;