-#include <config.h>
-
-#include <stdlib.h>
+/**
+ * \file inseturl.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author José Matos
+ *
+ * Full author contact details are available in file CREDITS.
+ */
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include <config.h>
-#include FORMS_H_LOCATION
#include "inseturl.h"
-#include "LString.h"
-#include "commandtags.h"
-#include "gettext.h"
+
+#include "dispatchresult.h"
+#include "funcrequest.h"
#include "LaTeXFeatures.h"
-#include "lyx_gui_misc.h" // CancelCloseBoxCB
+#include "gettext.h"
+#include "outputparams.h"
-extern BufferView *current_view;
-extern void UpdateInset(Inset* inset, bool mark_dirty = true);
+#include "support/lstrings.h"
-InsetUrl::InsetUrl(string const & cmd)
- : form(0)
-{
- scanCommand(cmd);
- if (getCmdName() == "url")
- flag = InsetUrl::URL;
- else
- flag = InsetUrl::HTML_URL;
-}
+#include "support/std_ostream.h"
-InsetUrl::InsetUrl(InsetCommand const &inscmd)
- : form(0)
-{
- setCmdName(inscmd.getCmdName());
- setContents(inscmd.getContents());
- setOptions(inscmd.getOptions());
- if (getCmdName() == "url")
- flag = InsetUrl::URL;
- else
- flag = InsetUrl::HTML_URL;
-}
-
+namespace lyx {
-InsetUrl::InsetUrl(string const &ins_name,string const &ins_cont,
- string const &ins_opt)
- : form(0)
-{
- setCmdName(ins_name);
- setContents(ins_cont);
- setOptions(ins_opt);
- if (ins_name == "url")
- flag = InsetUrl::URL;
- else
- flag = InsetUrl::HTML_URL;
-}
+using support::subst;
+using std::string;
+using std::ostream;
-InsetUrl::~InsetUrl()
-{
- if (form) {
- fl_hide_form(form);
- fl_free_form(form);
- form = 0;
- }
-}
+InsetUrl::InsetUrl(InsetCommandParams const & p)
+ : InsetCommand(p, "url")
+{}
-void InsetUrl::CloseUrlCB(FL_OBJECT *ob, long)
-{
- InsetUrl *inset = (InsetUrl*) ob->u_vdata;
- string url = fl_get_input(inset->url_name);
- string name = fl_get_input(inset->name_name);
- string cmdname;
- if (fl_get_button(inset->radio_html))
- cmdname = "htmlurl";
- else
- cmdname = "url";
-
- Buffer *buffer = current_view->currentBuffer();
-
- if ((url != inset->getContents() ||
- name != inset->getOptions() ||
- cmdname != inset->getCmdName())
- && !(buffer->isReadonly()) ) {
- buffer->markDirty();
- inset->setContents(url);
- inset->setOptions(name);
- inset->setCmdName(cmdname);
- if (cmdname == "url")
- inset->flag = InsetUrl::URL;
- else
- inset->flag = InsetUrl::HTML_URL;
- UpdateInset(inset);
- }
-
- if (inset->form) {
- fl_hide_form(inset->form);
- inset->form = 0;
- }
-}
-extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT *ob, long)
+docstring const InsetUrl::getScreenLabel(Buffer const &) const
{
- InsetUrl::CloseUrlCB(ob,0);
-}
+ docstring const temp =
+ (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
-void InsetUrl::Edit(int, int)
-{
- if(current_view->currentBuffer()->isReadonly())
- WarnReadonly();
-
- if (!form) {
- FL_OBJECT *obj;
- form = fl_bgn_form(FL_NO_BOX, 530, 170);
- obj = fl_add_box(FL_UP_BOX,0,0,530,170,"");
- url_name = obj = fl_add_input(FL_NORMAL_INPUT,50,30,460,30,idex(_("Url|#U")));
- fl_set_button_shortcut(obj,scex(_("Url|#U")),1);
- name_name = obj = fl_add_input(FL_NORMAL_INPUT,50,80,460,30,idex(_("Name|#N")));
- fl_set_button_shortcut(obj,scex(_("Name|#N")),1);
- obj = fl_add_button(FL_RETURN_BUTTON,360,130,100,30,idex(_("Close|#C^[^M")));
- fl_set_button_shortcut(obj,scex(_("Close|#C^[^M")),1);
- obj->u_vdata = this;
- fl_set_object_callback(obj,C_InsetUrl_CloseUrlCB,0);
- radio_html = obj = fl_add_checkbutton(FL_PUSH_BUTTON,50,130,240,30,idex(_("HTML type|#H")));
- fl_set_button_shortcut(obj,scex(_("HTML type|#H")),1);
- fl_set_object_lsize(obj,FL_NORMAL_SIZE);
- fl_end_form();
- fl_set_form_atclose(form, CancelCloseBoxCB, 0);
- }
- fl_set_input(url_name, getContents().c_str());
- fl_set_input(name_name, getOptions().c_str());
- switch(flag) {
- case InsetUrl::URL:
- fl_set_button(radio_html, 0);
- break;
- case InsetUrl::HTML_URL:
- fl_set_button(radio_html, 1);
- break;
- }
-
- if (form->visible) {
- fl_raise_form(form);
- } else {
- fl_show_form(form, FL_PLACE_MOUSE,
- FL_FULLBORDER, _("Insert Url"));
- }
-}
+ docstring url;
+ if (!getParam("name").empty())
+ url += getParam("name");
+ else
+ url += getParam("target");
-string InsetUrl::getScreenLabel() const
-{
- string temp;
- if (flag == InsetUrl::HTML_URL)
- temp += _("HtmlUrl: ");
- else
- temp += _("Url: ");
- temp += getContents();
- if(!getOptions().empty()) {
- temp += "||";
- temp += getOptions();
+ // elide if long
+ if (url.length() > 30) {
+ url = url.substr(0, 10) + "..."
+ + url.substr(url.length() - 17, url.length());
}
- return temp;
+ return temp + url;
}
-int InsetUrl::Latex(FILE *file, signed char fragile)
+int InsetUrl::latex(Buffer const &, odocstream & os,
+ OutputParams const & runparams) const
{
- string latex_output;
- int res = Latex(latex_output, fragile);
- fprintf(file, "%s", latex_output.c_str());
-
- return res;
+ docstring const & name = getParam("name");
+ if (!name.empty())
+ os << name + ' ';
+ if (runparams.moving_arg)
+ os << "\\protect";
+ os << "\\url{" << getParam("target") << '}';
+ return 0;
}
-int InsetUrl::Latex(string &file, signed char fragile)
+int InsetUrl::plaintext(Buffer const &, odocstream & os,
+ OutputParams const &) const
{
- if (!getOptions().empty())
- file += getOptions() + ' ';
- if (fragile)
- file += "\\protect";
-
- file += "\\url{" + getContents() + '}';
-
+ os << '[' << getParam("target");
+ if (getParam("name").empty())
+ os << ']';
+ else
+ os << "||" << getParam("name") << ']';
return 0;
}
-int InsetUrl::Linuxdoc(string &file)
+int InsetUrl::docbook(Buffer const &, odocstream & os,
+ OutputParams const &) const
{
- file += "<"+ getCmdName() +
- " url=\"" + getContents()+"\"" +
- " name=\"" + getOptions() +"\">";
-
+ os << "<ulink url=\""
+ << subst(getParam("target"), from_ascii("&"), from_ascii("&"))
+ << "\">"
+ << getParam("name")
+ << "</ulink>";
return 0;
}
-int InsetUrl::DocBook(string &file)
+int InsetUrl::textString(Buffer const & buf, odocstream & os,
+ OutputParams const & op) const
{
- file += "<ulink url=\"" + getContents() + "\">" +
- getOptions() +"</ulink>";
-
- return 0;
+ return plaintext(buf, os, op);
}
-void InsetUrl::Validate(LaTeXFeatures& features) const
+void InsetUrl::validate(LaTeXFeatures & features) const
{
- features.url = true;
+ features.require("url");
}
+
+
+} // namespace lyx