]> git.lyx.org Git - lyx.git/blobdiff - src/insets/inseturl.C
the fstream/iostream changes and some small other things
[lyx.git] / src / insets / inseturl.C
index f25a945c2083b03ba42506a0845b50f41de966a9..d6e8cbabe70f35c061513e9c01899baf37206d38 100644 (file)
@@ -1,6 +1,6 @@
 #include <config.h>
 
-#include <stdlib.h>
+#include <cstdlib>
 
 #ifdef __GNUG__
 #pragma implementation
 #include "LaTeXFeatures.h"
 #include "lyx_gui_misc.h" // CancelCloseBoxCB
 
-extern BufferView *current_view;
-extern void UpdateInset(Inset* inset, bool mark_dirty = true);
+extern BufferView * current_view;
+extern void UpdateInset(Inset * inset, bool mark_dirty = true);
 
 InsetUrl::InsetUrl(string const & cmd)
-       : form(0)
+       : fd_form_url(0)
 {
        scanCommand(cmd);
        if (getCmdName() == "url")
@@ -28,8 +28,8 @@ InsetUrl::InsetUrl(string const & cmd)
 }
 
 
-InsetUrl::InsetUrl(InsetCommand const &inscmd)
-       : form(0)
+InsetUrl::InsetUrl(InsetCommand const & inscmd)
+       : fd_form_url(0)
 {
        setCmdName(inscmd.getCmdName());
        setContents(inscmd.getContents());
@@ -41,9 +41,9 @@ InsetUrl::InsetUrl(InsetCommand const &inscmd)
 }
 
 
-InsetUrl::InsetUrl(string const &ins_name,string const &ins_cont,
-                  string const &ins_opt)
-       : form(0)
+InsetUrl::InsetUrl(string const & ins_name, string const & ins_cont,
+                  string const & ins_opt)
+       : fd_form_url(0)
 {
        setCmdName(ins_name);
        setContents(ins_cont);
@@ -57,26 +57,26 @@ InsetUrl::InsetUrl(string const &ins_name,string const &ins_cont,
 
 InsetUrl::~InsetUrl()
 {
-       if (form) {
-               fl_hide_form(form);
-               fl_free_form(form);
-               form = 0;
+       if (fd_form_url) {
+               fl_hide_form(fd_form_url->form_url);
+               fl_free_form(fd_form_url->form_url);
+               fd_form_url = 0;
        }
 }
 
 
-void InsetUrl::CloseUrlCB(FL_OBJECT *ob, long)
+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);
+       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->radio_html))
+       if (fl_get_button(inset->fd_form_url->radio_html))
                cmdname = "htmlurl";
        else
                cmdname = "url";
        
-       Buffer *buffer = current_view->currentBuffer();
+       Buffer * buffer = current_view->buffer();
        
        if ((url != inset->getContents() ||
             name != inset->getOptions() ||
@@ -93,56 +93,55 @@ void InsetUrl::CloseUrlCB(FL_OBJECT *ob, long)
                UpdateInset(inset);
        }
        
-       if (inset->form) {
-               fl_hide_form(inset->form);
-               inset->form = 0;
+       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)
+
+extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
 {
-       InsetUrl::CloseUrlCB(ob,0);
+       InsetUrl::CloseUrlCB(ob, data);
 }
 
+
 void InsetUrl::Edit(int, int)
 {
-       if(current_view->currentBuffer()->isReadonly())
+       static int ow = -1, oh;
+
+       if(current_view->buffer()->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);
+       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(url_name, getContents().c_str());
-       fl_set_input(name_name, getOptions().c_str());
+       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(radio_html, 0);
+               fl_set_button(fd_form_url->radio_html, 0);
                break;
        case InsetUrl::HTML_URL:
-               fl_set_button(radio_html, 1);
+               fl_set_button(fd_form_url->radio_html, 1);
                break;
        }
        
-       if (form->visible) {
-               fl_raise_form(form);
+       if (fd_form_url->form_url->visible) {
+               fl_raise_form(fd_form_url->form_url);
        } else {
-               fl_show_form(form, FL_PLACE_MOUSE,
+               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);
        }
 }
 
@@ -163,17 +162,17 @@ string InsetUrl::getScreenLabel() const
 }
 
 
-int InsetUrl::Latex(FILE *file, signed char fragile)
+int InsetUrl::Latex(ostream & os, signed char fragile)
 {
        string latex_output;
        int res = Latex(latex_output, fragile);
-       fprintf(file, "%s", latex_output.c_str());
+       os << latex_output;
 
        return res;
 }
 
 
-int InsetUrl::Latex(string &file, signed char fragile)
+int InsetUrl::Latex(string & file, signed char fragile)
 {
        if (!getOptions().empty())
                file += getOptions() + ' ';
@@ -186,7 +185,7 @@ int InsetUrl::Latex(string &file, signed char fragile)
 }
 
 
-int InsetUrl::Linuxdoc(string &file)
+int InsetUrl::Linuxdoc(string & file)
 {
        file +=  "<"+ getCmdName() +
                 " url=\""  + getContents()+"\"" +
@@ -196,7 +195,7 @@ int InsetUrl::Linuxdoc(string &file)
 }
 
 
-int InsetUrl::DocBook(string &file)
+int InsetUrl::DocBook(string & file)
 {
        file +=  "<ulink url=\""  + getContents() + "\">" +
                 getOptions() +"</ulink>";
@@ -205,7 +204,7 @@ int InsetUrl::DocBook(string &file)
 }
 
 
-void InsetUrl::Validate(LaTeXFeatures& features) const
+void InsetUrl::Validate(LaTeXFeatures & features) const
 {
        features.url = true;
 }