]> git.lyx.org Git - lyx.git/blob - src/insets/InsetSpace.cpp
d1b89ddd0798cc89e45377f36fb08ef695359b08
[lyx.git] / src / insets / InsetSpace.cpp
1 /**
2  * \file InsetSpace.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup Nielsen
7  * \author Jean-Marc Lasgouttes
8  * \author Lars Gullik Bjønnes
9  * \author Jürgen Spitzmüller
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "InsetSpace.h"
17
18 #include "BufferView.h"
19 #include "Cursor.h"
20 #include "Dimension.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
23 #include "Length.h"
24 #include "Lexer.h"
25 #include "MetricsInfo.h"
26 #include "OutputParams.h"
27
28 #include "support/debug.h"
29 #include "support/docstream.h"
30 #include "support/gettext.h"
31 #include "support/lstrings.h"
32
33 #include "frontends/Application.h"
34 #include "frontends/FontMetrics.h"
35 #include "frontends/Painter.h"
36
37 using namespace std;
38
39 namespace lyx {
40
41
42 InsetSpace::InsetSpace(InsetSpaceParams const & params)
43         : params_(params)
44 {}
45
46
47 InsetSpaceParams::Kind InsetSpace::kind() const
48 {
49         return params_.kind;
50 }
51
52
53 Length InsetSpace::length() const
54 {
55         return params_.length;
56 }
57
58
59 InsetSpace::~InsetSpace()
60 {
61         hideDialogs("space", this);
62 }
63
64
65 docstring InsetSpace::toolTip(BufferView const &, int, int) const
66 {
67         docstring message;
68         switch (params_.kind) {
69         case InsetSpaceParams::NORMAL:
70                 message = _("Interword Space");
71                 break;
72         case InsetSpaceParams::PROTECTED:
73                 message = _("Protected Space");
74                 break;
75         case InsetSpaceParams::THIN:
76                 message = _("Thin Space");
77                 break;
78         case InsetSpaceParams::QUAD:
79                 message = _("Quad Space");
80                 break;
81         case InsetSpaceParams::QQUAD:
82                 message = _("QQuad Space");
83                 break;
84         case InsetSpaceParams::ENSPACE:
85                 message = _("Enspace");
86                 break;
87         case InsetSpaceParams::ENSKIP:
88                 message = _("Enskip");
89                 break;
90         case InsetSpaceParams::NEGTHIN:
91                 message = _("Negative Thin Space");
92                 break;
93         case InsetSpaceParams::HFILL:
94                 message = _("Horizontal Fill");
95                 break;
96         case InsetSpaceParams::HFILL_PROTECTED:
97                 message = _("Protected Horizontal Fill");
98                 break;
99         case InsetSpaceParams::DOTFILL:
100                 message = _("Horizontal Fill (Dots)");
101                 break;
102         case InsetSpaceParams::HRULEFILL:
103                 message = _("Horizontal Fill (Rule)");
104                 break;
105         case InsetSpaceParams::LEFTARROWFILL:
106                 message = _("Horizontal Fill (Left Arrow)");
107                 break;
108         case InsetSpaceParams::RIGHTARROWFILL:
109                 message = _("Horizontal Fill (Right Arrow)");
110                 break;
111         case InsetSpaceParams::UPBRACEFILL:
112                 message = _("Horizontal Fill (Up Brace)");
113                 break;
114         case InsetSpaceParams::DOWNBRACEFILL:
115                 message = _("Horizontal Fill (Down Brace)");
116                 break;
117         case InsetSpaceParams::CUSTOM:
118                 message = support::bformat(_("Horizontal Space (%1$s)"),
119                                 params_.length.asDocstring());
120                 break;
121         case InsetSpaceParams::CUSTOM_PROTECTED:
122                 message = support::bformat(_("Protected Horizontal Space (%1$s)"),
123                                 params_.length.asDocstring());
124                 break;
125         }
126         return message;
127 }
128
129
130 void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
131 {
132         switch (cmd.action) {
133
134         case LFUN_INSET_MODIFY: {
135                 string2params(to_utf8(cmd.argument()), params_);
136                 break;
137         }
138
139         case LFUN_MOUSE_RELEASE:
140                 if (!cur.selection() && cmd.button() == mouse_button::button1)
141                         cur.bv().showDialog("space", params2string(params()), this);
142                 break;
143
144         default:
145                 Inset::doDispatch(cur, cmd);
146                 break;
147         }
148 }
149
150
151 bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
152         FuncStatus & status) const
153 {
154         switch (cmd.action) {
155         // we handle these
156         case LFUN_INSET_MODIFY:
157                 if (cmd.getArg(0) == "space") {
158                         InsetSpaceParams params;
159                         string2params(to_utf8(cmd.argument()), params);
160                         status.setOnOff(params_.kind == params.kind);
161                 }
162                 status.setEnabled(true);
163                 return true;
164         default:
165                 return Inset::getStatus(cur, cmd, status);
166         }
167 }
168
169
170 void InsetSpace::edit(Cursor & cur, bool, EntryDirection)
171 {
172         cur.bv().showDialog("space", params2string(params()), this);
173 }
174
175
176 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
177 {
178         if (isStretchableSpace()) {
179                 // The metrics for this kinds are calculated externally in
180                 // \c TextMetrics::computeRowMetrics. Those are dummy value:
181                 dim = Dimension(10, 10, 10);
182                 return;
183         }
184
185         frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
186         dim.asc = fm.maxAscent();
187         dim.des = fm.maxDescent();
188
189         switch (params_.kind) {
190                 case InsetSpaceParams::THIN:
191                 case InsetSpaceParams::NEGTHIN:
192                         dim.wid = fm.width(char_type('M')) / 6;
193                         break;
194                 case InsetSpaceParams::PROTECTED:
195                 case InsetSpaceParams::NORMAL:
196                         dim.wid = fm.width(char_type(' '));
197                         break;
198                 case InsetSpaceParams::QUAD:
199                         dim.wid = fm.width(char_type('M'));
200                         break;
201                 case InsetSpaceParams::QQUAD:
202                         dim.wid = 2 * fm.width(char_type('M'));
203                         break;
204                 case InsetSpaceParams::ENSPACE:
205                 case InsetSpaceParams::ENSKIP:
206                         dim.wid = int(0.5 * fm.width(char_type('M')));
207                         break;
208                 case InsetSpaceParams::CUSTOM:
209                 case InsetSpaceParams::CUSTOM_PROTECTED:
210                         dim.wid = max(4, abs(params_.length.inBP()));
211                         break;
212                 case InsetSpaceParams::HFILL:
213                 case InsetSpaceParams::HFILL_PROTECTED:
214                 case InsetSpaceParams::DOTFILL:
215                 case InsetSpaceParams::HRULEFILL:
216                 case InsetSpaceParams::LEFTARROWFILL:
217                 case InsetSpaceParams::RIGHTARROWFILL:
218                 case InsetSpaceParams::UPBRACEFILL:
219                 case InsetSpaceParams::DOWNBRACEFILL:
220                         // shut up compiler
221                         break;
222         }
223         // Cache the inset dimension.
224         setDimCache(mi, dim);
225 }
226
227
228 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
229 {
230         Dimension const dim = dimension(*pi.base.bv);
231
232         if (isStretchableSpace()) {
233                 int const asc = theFontMetrics(pi.base.font).ascent('M');
234                 int const desc = theFontMetrics(pi.base.font).descent('M');
235                 // Pixel height divisible by 2 for prettier fill graphics:
236                 int const oddheight = (asc ^ desc) & 1;
237                 int const x0 = x + 1;
238                 int const x1 = x + dim.wid - 2;
239                 int const y0 = y + desc - 1;
240                 int const y1 = y - asc + oddheight - 1;
241                 int const y2 = (y0 + y1) / 2;
242                 int xoffset = (y0 - y1) / 2;
243
244                 // Two tests for very narrow insets
245                 if (xoffset > x1 - x0
246                      && (params_.kind == InsetSpaceParams::LEFTARROWFILL
247                          || params_.kind == InsetSpaceParams::RIGHTARROWFILL))
248                                 xoffset = x1 - x0;
249                 if (xoffset * 6 > (x1 - x0)
250                      && (params_.kind == InsetSpaceParams::UPBRACEFILL
251                          || params_.kind == InsetSpaceParams::DOWNBRACEFILL))
252                                 xoffset = (x1 - x0) / 6;
253
254                 int const x2 = x0 + xoffset;
255                 int const x3 = x1 - xoffset;
256                 int const xm = (x0 + x1) / 2;
257                 int const xml = xm - xoffset;
258                 int const xmr = xm + xoffset;
259
260                 if (params_.kind == InsetSpaceParams::HFILL) {
261                         pi.pain.line(x0, y1, x0, y0, Color_added_space);
262                         pi.pain.line(x0, y2 , x1, y2, Color_added_space,
263                                 frontend::Painter::line_onoffdash);
264                         pi.pain.line(x1, y1, x1, y0, Color_added_space);
265                 } else if (params_.kind == InsetSpaceParams::HFILL_PROTECTED) {
266                         pi.pain.line(x0, y1, x0, y0, Color_latex);
267                         pi.pain.line(x0, y2 , x1, y2, Color_latex,
268                                 frontend::Painter::line_onoffdash);
269                         pi.pain.line(x1, y1, x1, y0, Color_latex);
270                 } else if (params_.kind == InsetSpaceParams::DOTFILL) {
271                         pi.pain.line(x0, y1, x0, y0, Color_special);
272                         pi.pain.line(x0, y0, x1, y0, Color_special,
273                                 frontend::Painter::line_onoffdash);
274                         pi.pain.line(x1, y1, x1, y0, Color_special);
275                 } else if (params_.kind == InsetSpaceParams::HRULEFILL) {
276                         pi.pain.line(x0, y1, x0, y0, Color_special);
277                         pi.pain.line(x0, y0, x1, y0, Color_special);
278                         pi.pain.line(x1, y1, x1, y0, Color_special);
279                 } else if (params_.kind == InsetSpaceParams::LEFTARROWFILL) {
280                         pi.pain.line(x2, y1 + 1 , x0 + 1, y2, Color_special);
281                         pi.pain.line(x0 + 1, y2 + 1 , x2, y0, Color_special);
282                         pi.pain.line(x0, y2 , x1, y2, Color_special);
283                 } else if (params_.kind == InsetSpaceParams::RIGHTARROWFILL) {
284                         pi.pain.line(x3 + 1, y1 + 1 , x1, y2, Color_special);
285                         pi.pain.line(x1, y2 + 1 , x3 + 1, y0, Color_special);
286                         pi.pain.line(x0, y2 , x1, y2, Color_special);
287                 } else if (params_.kind == InsetSpaceParams::UPBRACEFILL) {
288                         pi.pain.line(x0 + 1, y1 + 1 , x2, y2, Color_special);
289                         pi.pain.line(x2, y2 , xml, y2, Color_special);
290                         pi.pain.line(xml + 1, y2 + 1 , xm, y0, Color_special);
291                         pi.pain.line(xm + 1, y0 , xmr, y2 + 1, Color_special);
292                         pi.pain.line(xmr, y2 , x3, y2, Color_special);
293                         pi.pain.line(x3 + 1, y2 , x1, y1 + 1, Color_special);
294                 } else if (params_.kind == InsetSpaceParams::DOWNBRACEFILL) {
295                         pi.pain.line(x0 + 1, y0 , x2, y2 + 1, Color_special);
296                         pi.pain.line(x2, y2 , xml, y2, Color_special);
297                         pi.pain.line(xml + 1, y2 , xm, y1 + 1, Color_special);
298                         pi.pain.line(xm + 1, y1 + 1 , xmr, y2, Color_special);
299                         pi.pain.line(xmr, y2 , x3, y2, Color_special);
300                         pi.pain.line(x3 + 1, y2 + 1 , x1, y0, Color_special);
301                 }
302                 return;
303         }
304
305         int const w = dim.wid;
306         int const h = theFontMetrics(pi.base.font).ascent('x');
307         int xp[4], yp[4];
308
309         xp[0] = x;
310         yp[0] = y - max(h / 4, 1);
311         if (params_.kind == InsetSpaceParams::NORMAL ||
312             params_.kind == InsetSpaceParams::PROTECTED) {
313                 xp[1] = x;     yp[1] = y;
314                 xp[2] = x + w; yp[2] = y;
315         } else {
316                 xp[1] = x;     yp[1] = y + max(h / 4, 1);
317                 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
318         }
319         xp[3] = x + w;
320         yp[3] = y - max(h / 4, 1);
321
322         if (params_.length.inBP() < 0) {
323                 // turn symbol upside down
324                 swap(yp[0], yp[1]);
325                 swap(yp[2], yp[3]);
326         }
327         if (params_.kind == InsetSpaceParams::PROTECTED ||
328             params_.kind == InsetSpaceParams::ENSPACE ||
329             params_.kind == InsetSpaceParams::NEGTHIN ||
330             params_.kind == InsetSpaceParams::CUSTOM_PROTECTED)
331                 pi.pain.lines(xp, yp, 4, Color_latex);
332         else
333                 pi.pain.lines(xp, yp, 4, Color_special);
334 }
335
336
337 void InsetSpaceParams::write(ostream & os) const
338 {
339         string command;
340         switch (kind) {
341         case InsetSpaceParams::NORMAL:
342                 os << "\\space{}";
343                 break;
344         case InsetSpaceParams::PROTECTED:
345                 os <<  "~";
346                 break;
347         case InsetSpaceParams::THIN:
348                 os <<  "\\thinspace{}";
349                 break;
350         case InsetSpaceParams::QUAD:
351                 os <<  "\\quad{}";
352                 break;
353         case InsetSpaceParams::QQUAD:
354                 os <<  "\\qquad{}";
355                 break;
356         case InsetSpaceParams::ENSPACE:
357                 os <<  "\\enspace{}";
358                 break;
359         case InsetSpaceParams::ENSKIP:
360                 os <<  "\\enskip{}";
361                 break;
362         case InsetSpaceParams::NEGTHIN:
363                 os <<  "\\negthinspace{}";
364                 break;
365         case InsetSpaceParams::HFILL:
366                 os <<  "\\hfill{}";
367                 break;
368         case InsetSpaceParams::HFILL_PROTECTED:
369                 os <<  "\\hspace*{\\fill}";
370                 break;
371         case InsetSpaceParams::DOTFILL:
372                 os <<  "\\dotfill{}";
373                 break;
374         case InsetSpaceParams::HRULEFILL:
375                 os <<  "\\hrulefill{}";
376                 break;
377         case InsetSpaceParams::LEFTARROWFILL:
378                 os <<  "\\leftarrowfill{}";
379                 break;
380         case InsetSpaceParams::RIGHTARROWFILL:
381                 os <<  "\\rightarrowfill{}";
382                 break;
383         case InsetSpaceParams::UPBRACEFILL:
384                 os <<  "\\upbracefill{}";
385                 break;
386         case InsetSpaceParams::DOWNBRACEFILL:
387                 os <<  "\\downbracefill{}";
388                 break;
389         case InsetSpaceParams::CUSTOM:
390                 os <<  "\\hspace{}";
391                 break;
392         case InsetSpaceParams::CUSTOM_PROTECTED:
393                 os <<  "\\hspace*{}";
394                 break;
395         }
396         
397         if (!length.empty())
398                 os << "\n\\length " << length.asString();
399 }
400
401
402 void InsetSpaceParams::read(Lexer & lex)
403 {
404         lex.setContext("InsetSpaceParams::read");
405         string command;
406         lex >> command;
407
408         if (command == "\\space{}")
409                 kind = InsetSpaceParams::NORMAL;
410         else if (command == "~")
411                 kind = InsetSpaceParams::PROTECTED;
412         else if (command == "\\thinspace{}")
413                 kind = InsetSpaceParams::THIN;
414         else if (command == "\\quad{}")
415                 kind = InsetSpaceParams::QUAD;
416         else if (command == "\\qquad{}")
417                 kind = InsetSpaceParams::QQUAD;
418         else if (command == "\\enspace{}")
419                 kind = InsetSpaceParams::ENSPACE;
420         else if (command == "\\enskip{}")
421                 kind = InsetSpaceParams::ENSKIP;
422         else if (command == "\\negthinspace{}")
423                 kind = InsetSpaceParams::NEGTHIN;
424         else if (command == "\\hfill{}")
425                 kind = InsetSpaceParams::HFILL;
426         else if (command == "\\hspace*{\\fill}")
427                 kind = InsetSpaceParams::HFILL_PROTECTED;
428         else if (command == "\\dotfill{}")
429                 kind = InsetSpaceParams::DOTFILL;
430         else if (command == "\\hrulefill{}")
431                 kind = InsetSpaceParams::HRULEFILL;
432         else if (command == "\\hspace{}")
433                 kind = InsetSpaceParams::CUSTOM;
434         else if (command == "\\leftarrowfill{}")
435                 kind = InsetSpaceParams::LEFTARROWFILL;
436         else if (command == "\\rightarrowfill{}")
437                 kind = InsetSpaceParams::RIGHTARROWFILL;
438         else if (command == "\\upbracefill{}")
439                 kind = InsetSpaceParams::UPBRACEFILL;
440         else if (command == "\\downbracefill{}")
441                 kind = InsetSpaceParams::DOWNBRACEFILL;
442         else if (command == "\\hspace*{}")
443                 kind = InsetSpaceParams::CUSTOM_PROTECTED;
444         else
445                 lex.printError("InsetSpace: Unknown kind: `$$Token'");
446
447         if (lex.checkFor("\\length"))
448                 lex >> length;
449 }
450
451
452 void InsetSpace::write(ostream & os) const
453 {
454         os << "space ";
455         params_.write(os);
456 }
457
458
459 void InsetSpace::read(Lexer & lex)
460 {
461         params_.read(lex);
462         lex >> "\\end_inset";
463 }
464
465
466 int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const
467 {
468         switch (params_.kind) {
469         case InsetSpaceParams::NORMAL:
470                 os << (runparams.free_spacing ? " " : "\\ ");
471                 break;
472         case InsetSpaceParams::PROTECTED:
473                 os << (runparams.free_spacing ? ' ' : '~');
474                 break;
475         case InsetSpaceParams::THIN:
476                 os << (runparams.free_spacing ? " " : "\\,");
477                 break;
478         case InsetSpaceParams::QUAD:
479                 os << (runparams.free_spacing ? " " : "\\quad{}");
480                 break;
481         case InsetSpaceParams::QQUAD:
482                 os << (runparams.free_spacing ? " " : "\\qquad{}");
483                 break;
484         case InsetSpaceParams::ENSPACE:
485                 os << (runparams.free_spacing ? " " : "\\enspace{}");
486                 break;
487         case InsetSpaceParams::ENSKIP:
488                 os << (runparams.free_spacing ? " " : "\\enskip{}");
489                 break;
490         case InsetSpaceParams::NEGTHIN:
491                 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
492                 break;
493         case InsetSpaceParams::HFILL:
494                 os << (runparams.free_spacing ? " " : "\\hfill{}");
495                 break;
496         case InsetSpaceParams::HFILL_PROTECTED:
497                 os << (runparams.free_spacing ? " " : "\\hspace*{\\fill}");
498                 break;
499         case InsetSpaceParams::DOTFILL:
500                 os << (runparams.free_spacing ? " " : "\\dotfill{}");
501                 break;
502         case InsetSpaceParams::HRULEFILL:
503                 os << (runparams.free_spacing ? " " : "\\hrulefill{}");
504                 break;
505         case InsetSpaceParams::LEFTARROWFILL:
506                 os << (runparams.free_spacing ? " " : "\\leftarrowfill{}");
507                 break;
508         case InsetSpaceParams::RIGHTARROWFILL:
509                 os << (runparams.free_spacing ? " " : "\\rightarrowfill{}");
510                 break;
511         case InsetSpaceParams::UPBRACEFILL:
512                 os << (runparams.free_spacing ? " " : "\\upbracefill{}");
513                 break;
514         case InsetSpaceParams::DOWNBRACEFILL:
515                 os << (runparams.free_spacing ? " " : "\\downbracefill{}");
516                 break;
517         case InsetSpaceParams::CUSTOM:
518                 if (runparams.free_spacing)
519                         os << " ";
520                 else
521                         os << "\\hspace{" << from_ascii(params_.length.asLatexString()) << "}";
522                 break;
523         case InsetSpaceParams::CUSTOM_PROTECTED:
524                 if (runparams.free_spacing)
525                         os << " ";
526                 else
527                         os << "\\hspace*{" << from_ascii(params_.length.asLatexString()) << "}";
528                 break;
529         }
530         return 0;
531 }
532
533
534 int InsetSpace::plaintext(odocstream & os, OutputParams const &) const
535 {
536         switch (params_.kind) {
537         case InsetSpaceParams::HFILL:
538         case InsetSpaceParams::HFILL_PROTECTED:
539                 os << "     ";
540                 return 5;
541         case InsetSpaceParams::DOTFILL:
542                 os << ".....";
543                 return 5;
544         case InsetSpaceParams::HRULEFILL:
545                 os << "_____";
546                 return 5;
547         case InsetSpaceParams::LEFTARROWFILL:
548                 os << "<----";
549                 return 5;
550         case InsetSpaceParams::RIGHTARROWFILL:
551                 os << "---->";
552                 return 5;
553         case InsetSpaceParams::UPBRACEFILL:
554                 os << "\\-v-/";
555                 return 5;
556         case InsetSpaceParams::DOWNBRACEFILL:
557                 os << "/-^-\\";
558                 return 5;
559         default:
560                 os << ' ';
561                 return 1;
562         }
563 }
564
565
566 int InsetSpace::docbook(odocstream & os, OutputParams const &) const
567 {
568         switch (params_.kind) {
569         case InsetSpaceParams::NORMAL:
570         case InsetSpaceParams::QUAD:
571         case InsetSpaceParams::QQUAD:
572         case InsetSpaceParams::ENSKIP:
573                 os << " ";
574                 break;
575         case InsetSpaceParams::PROTECTED:
576         case InsetSpaceParams::ENSPACE:
577         case InsetSpaceParams::THIN:
578         case InsetSpaceParams::NEGTHIN:
579                 os << "&nbsp;";
580                 break;
581         case InsetSpaceParams::HFILL:
582         case InsetSpaceParams::HFILL_PROTECTED:
583                 os << '\n';
584         case InsetSpaceParams::DOTFILL:
585                 // FIXME
586                 os << '\n';
587         case InsetSpaceParams::HRULEFILL:
588                 // FIXME
589                 os << '\n';
590         case InsetSpaceParams::LEFTARROWFILL:
591         case InsetSpaceParams::RIGHTARROWFILL:
592         case InsetSpaceParams::UPBRACEFILL:
593         case InsetSpaceParams::DOWNBRACEFILL:
594         case InsetSpaceParams::CUSTOM:
595         case InsetSpaceParams::CUSTOM_PROTECTED:
596                 // FIXME
597                 os << '\n';
598         }
599         return 0;
600 }
601
602
603 void InsetSpace::textString(odocstream & os) const
604 {
605         plaintext(os, OutputParams(0));
606 }
607
608
609 bool InsetSpace::isStretchableSpace() const
610 {
611         return params_.kind == InsetSpaceParams::HFILL
612                 || params_.kind == InsetSpaceParams::HFILL_PROTECTED
613                 || params_.kind == InsetSpaceParams::DOTFILL
614                 || params_.kind == InsetSpaceParams::HRULEFILL
615                 || params_.kind == InsetSpaceParams::LEFTARROWFILL
616                 || params_.kind == InsetSpaceParams::RIGHTARROWFILL
617                 || params_.kind == InsetSpaceParams::UPBRACEFILL
618                 || params_.kind == InsetSpaceParams::DOWNBRACEFILL;
619 }
620
621
622 docstring InsetSpace::contextMenu(BufferView const &, int, int) const
623 {
624         return from_ascii("context-space");
625 }
626
627
628 void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
629 {
630         params = InsetSpaceParams();
631         if (in.empty())
632                 return;
633
634         istringstream data(in);
635         Lexer lex;
636         lex.setStream(data);
637         lex.setContext("InsetSpace::string2params");
638         lex >> "space";
639
640         // There are cases, such as when we are called via getStatus() from
641         // Dialog::canApply(), where we are just called with "space" rather
642         // than a full "space \type{}\n\\end_inset".
643         if (lex.isOK())
644                 params.read(lex);
645 }
646
647
648 string InsetSpace::params2string(InsetSpaceParams const & params)
649 {
650         ostringstream data;
651         data << "space" << ' ';
652         params.write(data);
653         return data.str();
654 }
655
656
657 } // namespace lyx