]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
small fix to the doublespace handling in deleteemptyparagraphmechanism that might...
[lyx.git] / src / insets / inseturl.C
1 #include <config.h>
2
3 #include <cstdlib>
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
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
16
17
18 InsetUrl::InsetUrl(string const & cmd)
19         : fd_form_url(0)
20 {
21         scanCommand(cmd);
22         if (getCmdName() == "url")
23                 flag = InsetUrl::URL;
24         else
25                 flag = InsetUrl::HTML_URL;
26 }
27
28
29 InsetUrl::InsetUrl(InsetCommand const & inscmd)
30         : fd_form_url(0)
31 {
32         setCmdName(inscmd.getCmdName());
33         setContents(inscmd.getContents());
34         setOptions(inscmd.getOptions());
35         if (getCmdName() == "url")
36                 flag = InsetUrl::URL;
37         else
38                 flag = InsetUrl::HTML_URL;
39 }
40
41
42 InsetUrl::InsetUrl(string const & ins_name, string const & ins_cont,
43                    string const & ins_opt)
44         : fd_form_url(0)
45 {
46         setCmdName(ins_name);
47         setContents(ins_cont);
48         setOptions(ins_opt);
49         if (ins_name == "url")
50                 flag = InsetUrl::URL;
51         else
52                 flag = InsetUrl::HTML_URL;
53 }
54
55
56 InsetUrl::~InsetUrl()
57 {
58         if (fd_form_url) {
59                 fl_hide_form(fd_form_url->form_url);
60                 fl_free_form(fd_form_url->form_url);
61                 fd_form_url = 0;
62         }
63 }
64
65
66 void InsetUrl::CloseUrlCB(FL_OBJECT * ob, long)
67 {
68         Holder * holder = static_cast<Holder*>(ob->u_vdata);
69         
70         InsetUrl * inset = holder->inset;
71         BufferView * bv = holder->view;
72         
73         string url = fl_get_input(inset->fd_form_url->url_name);
74         string name = fl_get_input(inset->fd_form_url->name_name);
75         string cmdname;
76         if (fl_get_button(inset->fd_form_url->radio_html))
77                 cmdname = "htmlurl";
78         else
79                 cmdname = "url";
80         
81         Buffer * buffer = bv->buffer();
82         
83         if ((url != inset->getContents() ||
84              name != inset->getOptions() ||
85              cmdname != inset->getCmdName())
86             && !(buffer->isReadonly()) ) {
87                 buffer->markDirty();
88                 inset->setContents(url);
89                 inset->setOptions(name);
90                 inset->setCmdName(cmdname);
91                 if (cmdname == "url")
92                         inset->flag = InsetUrl::URL;
93                 else
94                         inset->flag = InsetUrl::HTML_URL;
95                 bv->updateInset(inset, true);
96         }
97         
98         if (inset->fd_form_url) {
99                 fl_hide_form(inset->fd_form_url->form_url);
100                 fl_free_form(inset->fd_form_url->form_url);
101                 inset->fd_form_url = 0;
102         }
103 }
104
105
106 extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
107 {
108         InsetUrl::CloseUrlCB(ob, data);
109 }
110
111
112 void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
113 {
114         static int ow = -1, oh;
115
116         if(bv->buffer()->isReadonly())
117                 WarnReadonly(bv->buffer()->fileName());
118
119         if (!fd_form_url) {
120                 fd_form_url = create_form_form_url();
121                 holder.inset = this;
122                 fd_form_url->button_close->u_vdata = &holder;
123                 fl_set_form_atclose(fd_form_url->form_url,
124                                     CancelCloseBoxCB, 0);
125         }
126         holder.view = bv;
127         fl_set_input(fd_form_url->url_name, getContents().c_str());
128         fl_set_input(fd_form_url->name_name, getOptions().c_str());
129         switch(flag) {
130         case InsetUrl::URL:
131                 fl_set_button(fd_form_url->radio_html, 0);
132                 break;
133         case InsetUrl::HTML_URL:
134                 fl_set_button(fd_form_url->radio_html, 1);
135                 break;
136         }
137         
138         if (fd_form_url->form_url->visible) {
139                 fl_raise_form(fd_form_url->form_url);
140         } else {
141                 fl_show_form(fd_form_url->form_url,
142                              FL_PLACE_MOUSE | FL_FREE_SIZE,
143                              FL_FULLBORDER, _("Insert Url"));
144                 if (ow < 0) {
145                         ow = fd_form_url->form_url->w;
146                         oh = fd_form_url->form_url->h;
147                 }
148                 fl_set_form_minsize(fd_form_url->form_url, ow, oh);
149         }
150 }
151
152
153 string InsetUrl::getScreenLabel() const
154 {
155         string temp;
156         if (flag == InsetUrl::HTML_URL)
157                 temp += _("HtmlUrl: ");
158         else 
159                 temp += _("Url: ");
160         temp += getContents();
161         if(!getOptions().empty()) {
162                 temp += "||";
163                 temp += getOptions();
164         }
165         return temp;
166 }
167
168
169 int InsetUrl::Latex(ostream & os, signed char fragile, bool /*free_spc*/) const
170 {
171         if (!getOptions().empty())
172                 os << getOptions() + ' ';
173         if (fragile)
174                 os << "\\protect";
175         os << "\\url{" << getContents() << '}';
176         return 0;
177 }
178
179
180 int InsetUrl::Linuxdoc(ostream & os) const
181 {
182         os << "<" << getCmdName()
183            << " url=\""  << getContents() << "\""
184            << " name=\"" << getOptions() << "\">";
185
186         return 0;
187 }
188
189
190 int InsetUrl::DocBook(ostream & os) const
191 {
192         os << "<ulink url=\"" << getContents() << "\">"
193            << getOptions() << "</ulink>";
194         return 0;
195 }
196
197
198 void InsetUrl::Validate(LaTeXFeatures & features) const
199 {
200         features.url = true;
201 }