This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / insets / inseturl.C
blob5124c15455d39057ec3a95e80e4cfd673b6d00b3
1 #include <config.h>
3 #include <stdlib.h>
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
9 #include FORMS_H_LOCATION 
10 #include "inseturl.h"
11 #include "LString.h"
12 #include "commandtags.h"
13 #include "gettext.h"
14 #include "LaTeXFeatures.h"
15 #include "lyx_gui_misc.h" // CancelCloseBoxCB
17 extern BufferView *current_view;
18 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
20 InsetUrl::InsetUrl(string const & cmd)
21         : form(0)
23         scanCommand(cmd);
24         if (getCmdName() == "url")
25                 flag = InsetUrl::URL;
26         else
27                 flag = InsetUrl::HTML_URL;
31 InsetUrl::InsetUrl(InsetCommand const &inscmd)
32         : form(0)
34         setCmdName(inscmd.getCmdName());
35         setContents(inscmd.getContents());
36         setOptions(inscmd.getOptions());
37         if (getCmdName() == "url")
38                 flag = InsetUrl::URL;
39         else
40                 flag = InsetUrl::HTML_URL;
44 InsetUrl::InsetUrl(string const &ins_name,string const &ins_cont,
45                    string const &ins_opt)
46         : form(0)
48         setCmdName(ins_name);
49         setContents(ins_cont);
50         setOptions(ins_opt);
51         if (ins_name == "url")
52                 flag = InsetUrl::URL;
53         else
54                 flag = InsetUrl::HTML_URL;
58 InsetUrl::~InsetUrl()
60         if (form) {
61                 fl_hide_form(form);
62                 fl_free_form(form);
63                 form = 0;
64         }
68 void InsetUrl::CloseUrlCB(FL_OBJECT *ob, long)
70         InsetUrl *inset = (InsetUrl*) ob->u_vdata;
71         string url = fl_get_input(inset->url_name);
72         string name = fl_get_input(inset->name_name);
73         string cmdname;
74         if (fl_get_button(inset->radio_html))
75                 cmdname = "htmlurl";
76         else
77                 cmdname = "url";
78         
79         Buffer *buffer = current_view->currentBuffer();
80         
81         if ((url != inset->getContents() ||
82              name != inset->getOptions() ||
83              cmdname != inset->getCmdName())
84             && !(buffer->isReadonly()) ) {
85                 buffer->markDirty();
86                 inset->setContents(url);
87                 inset->setOptions(name);
88                 inset->setCmdName(cmdname);
89                 if (cmdname == "url")
90                         inset->flag = InsetUrl::URL;
91                 else
92                         inset->flag = InsetUrl::HTML_URL;
93                 UpdateInset(inset);
94         }
95         
96         if (inset->form) {
97                 fl_hide_form(inset->form);
98                 inset->form = 0;
99         }
103 void InsetUrl::Edit(int, int)
105         if(current_view->currentBuffer()->isReadonly())
106                 WarnReadonly();
108         if (!form) {
109                 FL_OBJECT *obj;
110                 form = fl_bgn_form(FL_NO_BOX, 530, 170);
111                 obj = fl_add_box(FL_UP_BOX,0,0,530,170,"");
112                 url_name = obj = fl_add_input(FL_NORMAL_INPUT,50,30,460,30,idex(_("Url|#U")));
113                 fl_set_button_shortcut(obj,scex(_("Url|#U")),1);
114                 name_name = obj = fl_add_input(FL_NORMAL_INPUT,50,80,460,30,idex(_("Name|#N")));
115                 fl_set_button_shortcut(obj,scex(_("Name|#N")),1);
116                 obj = fl_add_button(FL_RETURN_BUTTON,360,130,100,30,idex(_("Close|#C^[^M")));
117                 fl_set_button_shortcut(obj,scex(_("Close|#C^[^M")),1);
118                 obj->u_vdata = this;
119                 fl_set_object_callback(obj,CloseUrlCB,0);
120                 radio_html = obj = fl_add_checkbutton(FL_PUSH_BUTTON,50,130,240,30,idex(_("HTML type|#H")));
121                 fl_set_button_shortcut(obj,scex(_("HTML type|#H")),1);
122                 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
123                 fl_end_form();
124                 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
125         }
126         fl_set_input(url_name, getContents().c_str());
127         fl_set_input(name_name, getOptions().c_str());
128         switch(flag) {
129         case InsetUrl::URL:
130                 fl_set_button(radio_html, 0);
131                 break;
132         case InsetUrl::HTML_URL:
133                 fl_set_button(radio_html, 1);
134                 break;
135         }
136         
137         if (form->visible) {
138                 fl_raise_form(form);
139         } else {
140                 fl_show_form(form, FL_PLACE_MOUSE,
141                              FL_FULLBORDER, _("Insert Url"));
142         }
146 string InsetUrl::getScreenLabel() const
148         string temp;
149         if (flag == InsetUrl::HTML_URL)
150                 temp += _("HtmlUrl: ");
151         else 
152                 temp += _("Url: ");
153         temp += getContents();
154         if(!getOptions().empty()) {
155                 temp += "||";
156                 temp += getOptions();
157         }
158         return temp;
162 int InsetUrl::Latex(FILE *file, signed char fragile)
164         string latex_output;
165         int res = Latex(latex_output, fragile);
166         fprintf(file, "%s", latex_output.c_str());
168         return res;
172 int InsetUrl::Latex(string &file, signed char fragile)
174         if (!getOptions().empty())
175                 file += getOptions() + ' ';
176         if (fragile)
177                 file += "\\protect";
179         file += "\\url{" + getContents() + '}';
181         return 0;
185 int InsetUrl::Linuxdoc(string &file)
187         file +=  "<"+ getCmdName() +
188                  " url=\""  + getContents()+"\"" +
189                  " name=\"" + getOptions() +"\">";
191         return 0;
195 int InsetUrl::DocBook(string &file)
197         file +=  "<ulink url=\""  + getContents() + "\">" +
198                  getOptions() +"</ulink>";
200         return 0;
204 void InsetUrl::Validate(LaTeXFeatures& features) const
206         features.url = true;