#include "form_citation.h"
#include "gettext.h"
#include "support/lstrings.h"
-#include "biblio.h"
#include "helper_funcs.h"
#include "xforms_helpers.h"
}
-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();
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 =
// 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);
}
}
typedef FormCB<ControlCitation, FormDB<FD_form_citation> > base_class;
FormCitation::FormCitation(ControlCitation & c)
- : base_class(c, _("Citation"))
+ : base_class(c, _("Citation"), false)
{}
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);
}
+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;
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 ||
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);
}
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);
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();