]> git.lyx.org Git - lyx.git/blobdiff - src/insets/inseturl.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / inseturl.C
index bb188b9075aed4fdabc99a40ac536cbdd362e39c..4bd7f5765a8d581e512c828af431d7aafdd426ab 100644 (file)
-#include <config.h>
-
-#include <cstdlib>
+/**
+ * \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 "debug.h"
-#include "gettext.h"
-#include "LaTeXFeatures.h"
-#include "lyx_gui_misc.h" // CancelCloseBoxCB
-
-using std::ostream;
-
-
-InsetUrl::InsetUrl(string const & cmd)
-       : fd_form_url(0)
-{
-       scanCommand(cmd);
-       if (getCmdName() == "url")
-               flag = InsetUrl::URL;
-       else
-               flag = InsetUrl::HTML_URL;
-}
 
+#include "dispatchresult.h"
+#include "funcrequest.h"
+#include "LaTeXFeatures.h"
+#include "gettext.h"
+#include "outputparams.h"
 
-InsetUrl::InsetUrl(InsetCommand const & inscmd)
-       : fd_form_url(0)
-{
-       setCmdName(inscmd.getCmdName());
-       setContents(inscmd.getContents());
-       setOptions(inscmd.getOptions());
-       if (getCmdName() == "url")
-               flag = InsetUrl::URL;
-       else
-               flag = InsetUrl::HTML_URL;
-}
-
+#include "support/lstrings.h"
 
-InsetUrl::InsetUrl(string const & ins_name, string const & ins_cont,
-                  string const & ins_opt)
-       : fd_form_url(0)
-{
-       setCmdName(ins_name);
-       setContents(ins_cont);
-       setOptions(ins_opt);
-       if (ins_name == "url")
-               flag = InsetUrl::URL;
-       else
-               flag = InsetUrl::HTML_URL;
-}
+#include "support/std_ostream.h"
 
 
-InsetUrl::~InsetUrl()
-{
-       if (fd_form_url) {
-               fl_hide_form(fd_form_url->form_url);
-               fl_free_form(fd_form_url->form_url);
-               fd_form_url = 0;
-       }
-}
+namespace lyx {
 
+using support::subst;
 
-void InsetUrl::CloseUrlCB(FL_OBJECT * ob, long)
-{
-       Holder * holder = static_cast<Holder*>(ob->u_vdata);
-       
-       InsetUrl * inset = holder->inset;
-       BufferView * bv = holder->view;
-       
-       string url = fl_get_input(inset->fd_form_url->url_name);
-       string name = fl_get_input(inset->fd_form_url->name_name);
-       string cmdname;
-       if (fl_get_button(inset->fd_form_url->radio_html))
-               cmdname = "htmlurl";
-       else
-               cmdname = "url";
-       
-       Buffer * buffer = bv->buffer();
-       
-       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;
-               bv->updateInset(inset, true);
-       }
-       
-       if (inset->fd_form_url) {
-               fl_hide_form(inset->fd_form_url->form_url);
-               fl_free_form(inset->fd_form_url->form_url);
-               inset->fd_form_url = 0;
-       }
-}
-
-
-extern "C"
-void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
-{
-       InsetUrl::CloseUrlCB(ob, data);
-}
+using std::string;
+using std::ostream;
 
 
-char const * InsetUrl::EditMessage() const 
-{
-       return _("Opened Url");
-}
+InsetUrl::InsetUrl(InsetCommandParams const & p)
+       : InsetCommand(p, "url")
+{}
 
 
-void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
+docstring const InsetUrl::getScreenLabel(Buffer const &) const
 {
-       static int ow = -1, oh;
+       docstring const temp =
+               (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
 
-       if(bv->buffer()->isReadonly())
-               WarnReadonly(bv->buffer()->fileName());
-
-       if (!fd_form_url) {
-               fd_form_url = create_form_form_url();
-               holder.inset = this;
-               fd_form_url->button_close->u_vdata = &holder;
-               fl_set_form_atclose(fd_form_url->form_url,
-                                   CancelCloseBoxCB, 0);
-       }
-       holder.view = bv;
-       fl_set_input(fd_form_url->url_name, getContents().c_str());
-       fl_set_input(fd_form_url->name_name, getOptions().c_str());
-       switch(flag) {
-       case InsetUrl::URL:
-               fl_set_button(fd_form_url->radio_html, 0);
-               break;
-       case InsetUrl::HTML_URL:
-               fl_set_button(fd_form_url->radio_html, 1);
-               break;
-       }
-       
-       if (fd_form_url->form_url->visible) {
-               fl_raise_form(fd_form_url->form_url);
-       } else {
-               fl_show_form(fd_form_url->form_url,
-                            FL_PLACE_MOUSE | FL_FREE_SIZE,
-                            FL_FULLBORDER, _("Insert Url"));
-               if (ow < 0) {
-                       ow = fd_form_url->form_url->w;
-                       oh = fd_form_url->form_url->h;
-               }
-               fl_set_form_minsize(fd_form_url->form_url, ow, oh);
-       }
-}
+       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: ");
-       if(!getOptions().empty()) {
-               temp += getOptions();
-       } else {
-         temp += getContents();
+       // 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(Buffer const *, ostream & os,
-                   bool fragile, bool /*free_spc*/) const
+int InsetUrl::latex(Buffer const &, odocstream & os,
+                   OutputParams const & runparams) const
 {
-       if (!getOptions().empty())
-               os << getOptions() + ' ';
-       if (fragile)
+       docstring const & name = getParam("name");
+       if (!name.empty())
+               os << name + ' ';
+       if (runparams.moving_arg)
                os << "\\protect";
-       os << "\\url{" << getContents() << '}';
+       os << "\\url{" << getParam("target") << '}';
        return 0;
 }
 
 
-int InsetUrl::Ascii(Buffer const *, ostream & os) const
+int InsetUrl::plaintext(Buffer const &, odocstream & os,
+                   OutputParams const &) const
 {
-       if (getOptions().empty())
-               os << "[" << getContents() << "]";
+       os << '[' << getParam("target");
+       if (getParam("name").empty())
+               os << ']';
        else
-               os << "[" << getContents() << "||" <<  getOptions() << "]";
+               os << "||" << getParam("name") << ']';
        return 0;
 }
 
 
-int InsetUrl::Linuxdoc(Buffer const *, ostream & os) const
+int InsetUrl::docbook(Buffer const &, odocstream & os,
+                     OutputParams const &) const
 {
-       os << "<" << getCmdName()
-          << " url=\""  << getContents() << "\""
-          << " name=\"" << getOptions() << "\">";
-
+       os << "<ulink url=\"" 
+          << subst(getParam("target"), from_ascii("&"), from_ascii("&amp;"))
+          << "\">" 
+          << getParam("name")
+          << "</ulink>";
        return 0;
 }
 
 
-int InsetUrl::DocBook(Buffer const *, ostream & os) const
+int InsetUrl::textString(Buffer const & buf, odocstream & os,
+                      OutputParams const & op) const
 {
-       os << "<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