]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormCitation.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormCitation.C
index 97886b1b3e37fce1637f7640ee77a5bde388296f..ac5ad5ccd306a98d593b6151accaee1e1261126d 100644 (file)
@@ -25,7 +25,6 @@
 #include "form_citation.h"
 #include "gettext.h"
 #include "support/lstrings.h"
-#include "biblio.h"
 #include "helper_funcs.h"
 #include "xforms_helpers.h"
 
@@ -47,12 +46,24 @@ int string_width(string const & str)
 }
 
 
-void fillChoice(FL_OBJECT * choice, vector<string> const & vec)
+void fillChoice(FD_form_citation * dialog, vector<string> vec)
 {
+       // Check whether the current contents of the browser will be
+       // changed by loading the contents of the vec...
+       vector<string> const choice_style =
+               getVectorFromChoice(dialog->choice_style);
+
+       if (vec == choice_style)
+               return;
+
+       // They will be changed. Proceed
        string const str = " " + getStringFromVector(vec, " | ") + " ";
 
-       fl_clear_choice(choice);
-       fl_addto_choice(choice, str.c_str());
+       fl_clear_choice(dialog->choice_style);
+       fl_addto_choice(dialog->choice_style, str.c_str());
+
+       // The width of the choice varies with the contents.
+       // Ensure that it is centred in the frame.
 
        int width = 0;
        for (vector<string>::const_iterator it = vec.begin();
@@ -60,16 +71,18 @@ void fillChoice(FL_OBJECT * choice, vector<string> const & vec)
                width = max(width, string_width(*it));
        }
 
-       // Paranoia checks
-       int const x = max(5, int(choice->x + 0.5 * (choice->w - width)));
-       if (x + width > choice->form->w)
-               width = choice->form->w - 10;
-       
-       fl_set_object_geometry(choice, x, choice->y, width + 5, choice->h);
+       int const dx =
+               max(5, int(0.5 * (dialog->frame_style->w - width)));
+
+       fl_set_object_geometry(dialog->choice_style,
+                              dialog->frame_style->x + dx,
+                              dialog->choice_style->y,
+                              width,
+                              dialog->choice_style->h);
 }
 
-void updateStyle(FL_OBJECT * choice, FL_OBJECT * full, FL_OBJECT * force,
-                string command)
+
+void updateStyle(FD_form_citation * dialog, string command)
 {
        // Find the style of the citekeys
        vector<biblio::CiteStyle> const & styles =
@@ -81,14 +94,14 @@ void updateStyle(FL_OBJECT * choice, FL_OBJECT * full, FL_OBJECT * force,
 
        // Use this to initialise the GUI
        if (cit == styles.end()) {
-               fl_set_choice(choice, 1);
-               fl_set_button(full, 0);
-               fl_set_button(force, 0);
+               fl_set_choice(dialog->choice_style, 1);
+               fl_set_button(dialog->button_full_author_list, 0);
+               fl_set_button(dialog->button_force_uppercase, 0);
        } else {
                int const i = int(cit - styles.begin());
-               fl_set_choice(choice, i+1);
-               fl_set_button(full,  cs.full);
-               fl_set_button(force, cs.forceUCase);
+               fl_set_choice(dialog->choice_style, i+1);
+               fl_set_button(dialog->button_full_author_list,  cs.full);
+               fl_set_button(dialog->button_force_uppercase, cs.forceUCase);
        }
 }
 
@@ -97,7 +110,7 @@ void updateStyle(FL_OBJECT * choice, FL_OBJECT * full, FL_OBJECT * force,
 typedef FormCB<ControlCitation, FormDB<FD_form_citation> > base_class;
 
 FormCitation::FormCitation(ControlCitation & c)
-       : base_class(c, _("Citation"))
+       : base_class(c, _("Citation"), false)
 {}
 
 
@@ -136,6 +149,7 @@ void FormCitation::build()
 
        fl_set_input_return(dialog_->input_after,  FL_RETURN_CHANGED);
        fl_set_input_return(dialog_->input_before, FL_RETURN_CHANGED);
+       fl_set_input_return(dialog_->input_search, FL_RETURN_END);
 
        fl_set_button(dialog_->button_search_case, 0);
        fl_set_button(dialog_->button_search_type, 0);
@@ -153,9 +167,49 @@ void FormCitation::build()
        bc().addReadOnly(dialog_->choice_style);
        bc().addReadOnly(dialog_->input_before);
        bc().addReadOnly(dialog_->input_after);
+       bc().addReadOnly(dialog_->button_full_author_list);
+       bc().addReadOnly(dialog_->button_force_uppercase);
 }
 
 
+void FormCitation::findBiblio(biblio::Direction const dir)
+{
+       string const str = fl_get_input(dialog_->input_search);
+       biblio::InfoMap const & theMap = controller().bibkeysInfo();
+       bool const caseSensitive =
+               fl_get_button(dialog_->button_search_case);
+       biblio::Search const type =
+               fl_get_button(dialog_->button_search_type) ?
+               biblio::REGEX : biblio::SIMPLE;
+
+       vector<string>::const_iterator start = bibkeys.begin();
+       int const sel = fl_get_browser(dialog_->browser_bib);
+       if (sel >= 1 && sel <= int(bibkeys.size()))
+               start += sel - 1;
+
+       // Find the NEXT instance...
+       (dir == biblio::FORWARD) ? ++start : --start;
+
+
+       vector<string>::const_iterator const cit =
+       biblio::searchKeys(theMap, bibkeys, str,
+                          start, type, dir, caseSensitive);
+
+       if (cit == bibkeys.end())
+               return;
+
+       int const found = int(cit - bibkeys.begin()) + 1;
+       if (found == sel)
+               return;
+
+       // Update the display
+       int const top = max(found - 5, 1);
+       fl_set_browser_topline(dialog_->browser_bib, top);
+       fl_select_browser_line(dialog_->browser_bib, found);
+       input(dialog_->browser_bib, 0);
+}
+
 ButtonPolicy::SMInput FormCitation::input(FL_OBJECT * ob, long)
 {
        ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
@@ -297,50 +351,12 @@ ButtonPolicy::SMInput FormCitation::input(FL_OBJECT * ob, long)
                setCiteButtons(ON);
                activate = ButtonPolicy::SMI_VALID;
 
-       } else if (ob == dialog_->button_previous ||
-                  ob == dialog_->button_next) {
-
-               string const str = fl_get_input(dialog_->input_search);
-
-               biblio::Direction const dir =
-                       (ob == dialog_->button_previous) ?
-                       biblio::BACKWARD : biblio::FORWARD;
-
-               biblio::Search const type =
-                       fl_get_button(dialog_->button_search_type) ?
-                       biblio::REGEX : biblio::SIMPLE;
-
-               vector<string>::const_iterator start = bibkeys.begin();
-               int const sel = fl_get_browser(dialog_->browser_bib);
-               if (sel >= 1 && sel <= int(bibkeys.size()))
-                       start += sel-1;
-
-               // Find the NEXT instance...
-               if (dir == biblio::FORWARD)
-                       start += 1;
-               else
-                       start -= 1;
-
-               bool const caseSensitive =
-                       fl_get_button(dialog_->button_search_case);
-
-               vector<string>::const_iterator const cit =
-                       biblio::searchKeys(theMap, bibkeys, str,
-                                          start, type, dir, caseSensitive);
-
-               if (cit == bibkeys.end())
-                       return ButtonPolicy::SMI_NOOP;
-
-               int const found = int(cit - bibkeys.begin()) + 1;
-               if (found == sel)
-                       return ButtonPolicy::SMI_NOOP;
-
-               // Update the display
-               int const top = max(found-5, 1);
-               fl_set_browser_topline(dialog_->browser_bib, top);
-               fl_select_browser_line(dialog_->browser_bib, found);
-               input(dialog_->browser_bib, 0);
-
+       } else if (ob == dialog_->button_previous) {
+               findBiblio(biblio::BACKWARD);
+       } else if (ob == dialog_->button_next) {
+               findBiblio(biblio::FORWARD);
+       } else if (ob == dialog_->input_search) {
+               findBiblio(biblio::FORWARD);
        } else if (ob == dialog_->choice_style ||
                   ob == dialog_->button_full_author_list ||
                   ob == dialog_->button_force_uppercase ||
@@ -355,7 +371,7 @@ ButtonPolicy::SMInput FormCitation::input(FL_OBJECT * ob, long)
 
        if (topCitekey != currentCitekey) {
                int choice = fl_get_choice(dialog_->choice_style);
-               fillChoice(dialog_->choice_style,
+               fillChoice(dialog_.get(),
                           controller().getCiteStrings(currentCitekey));
                fl_set_choice(dialog_->choice_style, choice);
        }
@@ -378,13 +394,15 @@ void FormCitation::update()
        string key;
        if (!citekeys.empty()) key = citekeys[0];
 
-       fillChoice(dialog_->choice_style, controller().getCiteStrings(key));
+       fillChoice(dialog_.get(), controller().getCiteStrings(key));
 
        // Use the citation command to update the GUI
-       updateStyle(dialog_->choice_style, 
-                   dialog_->button_full_author_list,
-                   dialog_->button_force_uppercase,
-                   controller().params().getCmdName());
+       updateStyle(dialog_.get(), controller().params().getCmdName());
+
+       bool const natbib = controller().usingNatbib();
+       setEnabled(dialog_->button_full_author_list, natbib);
+       setEnabled(dialog_->button_force_uppercase, natbib);
+       setEnabled(dialog_->choice_style, natbib);
        
        // No keys have been selected yet, so...
        fl_clear_browser(dialog_->browser_info);
@@ -404,6 +422,14 @@ void FormCitation::update()
 void FormCitation::updateBrowser(FL_OBJECT * browser,
                                 vector<string> const & keys) const
 {
+       // Check whether the current contents of the browser will be
+       // changed by loading the contents of the vec...
+       vector<string> browser_keys = getVectorFromBrowser(browser);
+
+       if (browser_keys == keys)
+               return;
+
+       // They will be changed. Proceed.
        fl_clear_browser(browser);
 
        for (vector<string>::const_iterator it = keys.begin();