]> git.lyx.org Git - lyx.git/blobdiff - src/insets/inseturl.C
Hopefully fixed the redo problems with insets!
[lyx.git] / src / insets / inseturl.C
index 2b6b41484813590d34ecf13342997ee1a4bedd3d..2be9d6d96f648a49064bb6dff13329412c6cdc61 100644 (file)
 #include <config.h>
 
-#include <cstdlib>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
-#include FORMS_H_LOCATION 
 #include "inseturl.h"
-#include "LString.h"
-#include "commandtags.h"
-#include "gettext.h"
+#include "BufferView.h"
 #include "LaTeXFeatures.h"
-#include "lyx_gui_misc.h" // CancelCloseBoxCB
-
-extern BufferView * current_view;
-extern void UpdateInset(Inset * inset, bool mark_dirty = true);
-
-InsetUrl::InsetUrl(string const & cmd)
-       : fd_form_url(0)
-{
-       scanCommand(cmd);
-       if (getCmdName() == "url")
-               flag = InsetUrl::URL;
-       else
-               flag = InsetUrl::HTML_URL;
-}
-
-
-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;
-}
-
-
-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 "LyXView.h"
+#include "debug.h"
+#include "frontends/Dialogs.h"
+#include "gettext.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;
-       }
-}
+using std::ostream;
 
 
-void InsetUrl::CloseUrlCB(FL_OBJECT * ob, long)
-{
-       InsetUrl * inset = static_cast<InsetUrl*>(ob->u_vdata);
-       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 = current_view->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;
-               UpdateInset(inset);
-       }
-       
-       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;
-       }
-}
+InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
+               : InsetCommand(p)
+{}
 
 
-extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
+void InsetUrl::edit(BufferView * bv, int, int, unsigned int)
 {
-       InsetUrl::CloseUrlCB(ob, data);
+       bv->owner()->getDialogs()->showUrl( this );
 }
 
 
-void InsetUrl::Edit(int, int)
+void InsetUrl::edit(BufferView * bv, bool)
 {
-       static int ow = -1, oh;
-
-       if(current_view->buffer()->isReadonly())
-               WarnReadonly(current_view->buffer()->fileName());
-
-       if (!fd_form_url) {
-               fd_form_url = create_form_form_url();
-               fd_form_url->button_close->u_vdata = this;
-               fl_set_form_atclose(fd_form_url->form_url,
-                                   CancelCloseBoxCB, 0);
-       }
-       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);
-       }
+       edit(bv, 0, 0, 0);
 }
 
 
-string InsetUrl::getScreenLabel() const
+string const InsetUrl::getScreenLabel(Buffer const *) const
 {
        string temp;
-       if (flag == InsetUrl::HTML_URL)
-               temp += _("HtmlUrl: ");
+       if (getCmdName() == "url" )
+               temp = _("Url: ");
        else 
-               temp += _("Url: ");
-       temp += getContents();
-       if(!getOptions().empty()) {
-               temp += "||";
-               temp += getOptions();
-       }
-       return temp;
-}
+               temp = _("HtmlUrl: ");
 
+       if (!getOptions().empty())
+               temp += getOptions();
+       else
+               temp += getContents();
 
-int InsetUrl::Latex(ostream & os, signed char fragile)
-{
-       string latex_output;
-       int res = Latex(latex_output, fragile);
-       os << latex_output;
-
-       return res;
+       return temp;
 }
 
 
-int InsetUrl::Latex(string & file, signed char fragile)
+int InsetUrl::latex(Buffer const *, ostream & os,
+                   bool fragile, bool /*free_spc*/) const
 {
        if (!getOptions().empty())
-               file += getOptions() + ' ';
+               os << getOptions() + ' ';
        if (fragile)
-               file += "\\protect";
+               os << "\\protect";
+       os << "\\url{" << getContents() << '}';
+       return 0;
+}
 
-       file += "\\url{" + getContents() + '}';
 
+int InsetUrl::ascii(Buffer const *, ostream & os, int) const
+{
+       if (getOptions().empty())
+               os << "[" << getContents() << "]";
+       else
+               os << "[" << getContents() << "||" <<  getOptions() << "]";
        return 0;
 }
 
 
-int InsetUrl::Linuxdoc(string & file)
+int InsetUrl::linuxdoc(Buffer const *, ostream & os) const
 {
-       file +=  "<"+ getCmdName() +
-                " url=\""  + getContents()+"\"" +
-                " name=\"" + getOptions() +"\">";
+       os << "<" << getCmdName()
+          << " url=\""  << getContents() << "\""
+          << " name=\"" << getOptions() << "\">";
 
        return 0;
 }
 
 
-int InsetUrl::DocBook(string & file)
+int InsetUrl::docbook(Buffer const *, ostream & os) const
 {
-       file +=  "<ulink url=\""  + getContents() + "\">" +
-                getOptions() +"</ulink>";
-
+       os << "<ulink url=\"" << getContents() << "\">"
+          << getOptions() << "</ulink>";
        return 0;
 }
 
 
-void InsetUrl::Validate(LaTeXFeatures & features) const
+void InsetUrl::validate(LaTeXFeatures & features) const
 {
-       features.url = true;
+       features.require("url");
 }