]> git.lyx.org Git - features.git/blob - src/insets/InsetSpace.cpp
Fix MSVC warning
[features.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 namespace {
177 int const arrow_size = 8;
178 }
179
180
181 void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
182 {
183         if (isStretchableSpace()) {
184                 // The metrics for this kinds are calculated externally in
185                 // \c TextMetrics::computeRowMetrics. Those are dummy value:
186                 dim = Dimension(10, 10, 10);
187                 return;
188         }
189
190         frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
191         dim.asc = fm.maxAscent();
192         dim.des = fm.maxDescent();
193
194         switch (params_.kind) {
195                 case InsetSpaceParams::THIN:
196                 case InsetSpaceParams::NEGTHIN:
197                         dim.wid = fm.width(char_type('M')) / 6;
198                         break;
199                 case InsetSpaceParams::PROTECTED:
200                 case InsetSpaceParams::NORMAL:
201                         dim.wid = fm.width(char_type(' '));
202                         break;
203                 case InsetSpaceParams::QUAD:
204                         dim.wid = fm.width(char_type('M'));
205                         break;
206                 case InsetSpaceParams::QQUAD:
207                         dim.wid = 2 * fm.width(char_type('M'));
208                         break;
209                 case InsetSpaceParams::ENSPACE:
210                 case InsetSpaceParams::ENSKIP:
211                         dim.wid = int(0.5 * fm.width(char_type('M')));
212                         break;
213                 case InsetSpaceParams::CUSTOM:
214                 case InsetSpaceParams::CUSTOM_PROTECTED: {
215                         int minwidth = 4;
216                         if (params_.length.inBP() < 0)
217                                 minwidth = 3 * arrow_size;
218                         dim.wid = max(minwidth, abs(params_.length.inBP()));
219                         break;
220                 }
221                 case InsetSpaceParams::HFILL:
222                 case InsetSpaceParams::HFILL_PROTECTED:
223                 case InsetSpaceParams::DOTFILL:
224                 case InsetSpaceParams::HRULEFILL:
225                 case InsetSpaceParams::LEFTARROWFILL:
226                 case InsetSpaceParams::RIGHTARROWFILL:
227                 case InsetSpaceParams::UPBRACEFILL:
228                 case InsetSpaceParams::DOWNBRACEFILL:
229                         // shut up compiler
230                         break;
231         }
232         // Cache the inset dimension.
233         setDimCache(mi, dim);
234 }
235
236
237 void InsetSpace::draw(PainterInfo & pi, int x, int y) const
238 {
239         Dimension const dim = dimension(*pi.base.bv);
240
241         if (isStretchableSpace() || params_.length.inBP() < 0) {
242                 int const asc = theFontMetrics(pi.base.font).ascent('M');
243                 int const desc = theFontMetrics(pi.base.font).descent('M');
244                 // Pixel height divisible by 2 for prettier fill graphics:
245                 int const oddheight = (asc ^ desc) & 1;
246                 int const x0 = x + 1;
247                 int const x1 = x + dim.wid - 2;
248                 int const y0 = y + desc - 1;
249                 int const y1 = y - asc + oddheight - 1;
250                 int const y2 = (y0 + y1) / 2;
251                 int xoffset = (y0 - y1) / 2;
252
253                 // Two tests for very narrow insets
254                 if (xoffset > x1 - x0
255                      && (params_.kind == InsetSpaceParams::LEFTARROWFILL
256                          || params_.kind == InsetSpaceParams::RIGHTARROWFILL))
257                                 xoffset = x1 - x0;
258                 if (xoffset * 6 > (x1 - x0)
259                      && (params_.kind == InsetSpaceParams::UPBRACEFILL
260                          || params_.kind == InsetSpaceParams::DOWNBRACEFILL))
261                                 xoffset = (x1 - x0) / 6;
262
263                 int const x2 = x0 + xoffset;
264                 int const x3 = x1 - xoffset;
265                 int const xm = (x0 + x1) / 2;
266                 int const xml = xm - xoffset;
267                 int const xmr = xm + xoffset;
268
269                 if (params_.kind == InsetSpaceParams::HFILL) {
270                         pi.pain.line(x0, y1, x0, y0, Color_added_space);
271                         pi.pain.line(x0, y2 , x1, y2, Color_added_space,
272                                 frontend::Painter::line_onoffdash);
273                         pi.pain.line(x1, y1, x1, y0, Color_added_space);
274                 } else if (params_.kind == InsetSpaceParams::HFILL_PROTECTED) {
275                         pi.pain.line(x0, y1, x0, y0, Color_latex);
276                         pi.pain.line(x0, y2 , x1, y2, Color_latex,
277                                 frontend::Painter::line_onoffdash);
278                         pi.pain.line(x1, y1, x1, y0, Color_latex);
279                 } else if (params_.kind == InsetSpaceParams::DOTFILL) {
280                         pi.pain.line(x0, y1, x0, y0, Color_special);
281                         pi.pain.line(x0, y0, x1, y0, Color_special,
282                                 frontend::Painter::line_onoffdash);
283                         pi.pain.line(x1, y1, x1, y0, Color_special);
284                 } else if (params_.kind == InsetSpaceParams::HRULEFILL) {
285                         pi.pain.line(x0, y1, x0, y0, Color_special);
286                         pi.pain.line(x0, y0, x1, y0, Color_special);
287                         pi.pain.line(x1, y1, x1, y0, Color_special);
288                 } else if (params_.kind == InsetSpaceParams::LEFTARROWFILL) {
289                         pi.pain.line(x2, y1 + 1 , x0 + 1, y2, Color_special);
290                         pi.pain.line(x0 + 1, y2 + 1 , x2, y0, Color_special);
291                         pi.pain.line(x0, y2 , x1, y2, Color_special);
292                 } else if (params_.kind == InsetSpaceParams::RIGHTARROWFILL) {
293                         pi.pain.line(x3 + 1, y1 + 1 , x1, y2, Color_special);
294                         pi.pain.line(x1, y2 + 1 , x3 + 1, y0, Color_special);
295                         pi.pain.line(x0, y2 , x1, y2, Color_special);
296                 } else if (params_.kind == InsetSpaceParams::UPBRACEFILL) {
297                         pi.pain.line(x0 + 1, y1 + 1 , x2, y2, Color_special);
298                         pi.pain.line(x2, y2 , xml, y2, Color_special);
299                         pi.pain.line(xml + 1, y2 + 1 , xm, y0, Color_special);
300                         pi.pain.line(xm + 1, y0 , xmr, y2 + 1, Color_special);
301                         pi.pain.line(xmr, y2 , x3, y2, Color_special);
302                         pi.pain.line(x3 + 1, y2 , x1, y1 + 1, Color_special);
303                 } else if (params_.kind == InsetSpaceParams::DOWNBRACEFILL) {
304                         pi.pain.line(x0 + 1, y0 , x2, y2 + 1, Color_special);
305                         pi.pain.line(x2, y2 , xml, y2, Color_special);
306                         pi.pain.line(xml + 1, y2 , xm, y1 + 1, Color_special);
307                         pi.pain.line(xm + 1, y1 + 1 , xmr, y2, Color_special);
308                         pi.pain.line(xmr, y2 , x3, y2, Color_special);
309                         pi.pain.line(x3 + 1, y2 + 1 , x1, y0, Color_special);
310                 } else if (params_.kind == InsetSpaceParams::CUSTOM) {
311                         pi.pain.line(x0, y1 + 1 , x2 + 1, y2, Color_special);
312                         pi.pain.line(x2 + 1, y2 + 1 , x0, y0, Color_special);
313                         pi.pain.line(x1 + 1, y1 + 1 , x3, y2, Color_special);
314                         pi.pain.line(x3, y2 + 1 , x1 + 1, y0, Color_special);
315                         pi.pain.line(x2, y2 , x3, y2, Color_special);
316                 } else if (params_.kind == InsetSpaceParams::CUSTOM_PROTECTED) {
317                         pi.pain.line(x0, y1 + 1 , x2 + 1, y2, Color_latex);
318                         pi.pain.line(x2 + 1, y2 + 1 , x0, y0, Color_latex);
319                         pi.pain.line(x1 + 1, y1 + 1 , x3, y2, Color_latex);
320                         pi.pain.line(x3, y2 + 1 , x1 + 1, y0, Color_latex);
321                         pi.pain.line(x2, y2 , x3, y2, Color_latex);
322                 }
323                 return;
324         }
325
326         int const w = dim.wid;
327         int const h = theFontMetrics(pi.base.font).ascent('x');
328         int xp[4], yp[4];
329
330         xp[0] = x;
331         yp[0] = y - max(h / 4, 1);
332         if (params_.kind == InsetSpaceParams::NORMAL ||
333             params_.kind == InsetSpaceParams::PROTECTED) {
334                 xp[1] = x;     yp[1] = y;
335                 xp[2] = x + w; yp[2] = y;
336         } else {
337                 xp[1] = x;     yp[1] = y + max(h / 4, 1);
338                 xp[2] = x + w; yp[2] = y + max(h / 4, 1);
339         }
340         xp[3] = x + w;
341         yp[3] = y - max(h / 4, 1);
342
343         if (params_.kind == InsetSpaceParams::PROTECTED ||
344             params_.kind == InsetSpaceParams::ENSPACE ||
345             params_.kind == InsetSpaceParams::NEGTHIN ||
346             params_.kind == InsetSpaceParams::CUSTOM_PROTECTED)
347                 pi.pain.lines(xp, yp, 4, Color_latex);
348         else
349                 pi.pain.lines(xp, yp, 4, Color_special);
350 }
351
352
353 void InsetSpaceParams::write(ostream & os) const
354 {
355         string command;
356         switch (kind) {
357         case InsetSpaceParams::NORMAL:
358                 os << "\\space{}";
359                 break;
360         case InsetSpaceParams::PROTECTED:
361                 os <<  "~";
362                 break;
363         case InsetSpaceParams::THIN:
364                 os <<  "\\thinspace{}";
365                 break;
366         case InsetSpaceParams::QUAD:
367                 os <<  "\\quad{}";
368                 break;
369         case InsetSpaceParams::QQUAD:
370                 os <<  "\\qquad{}";
371                 break;
372         case InsetSpaceParams::ENSPACE:
373                 os <<  "\\enspace{}";
374                 break;
375         case InsetSpaceParams::ENSKIP:
376                 os <<  "\\enskip{}";
377                 break;
378         case InsetSpaceParams::NEGTHIN:
379                 os <<  "\\negthinspace{}";
380                 break;
381         case InsetSpaceParams::HFILL:
382                 os <<  "\\hfill{}";
383                 break;
384         case InsetSpaceParams::HFILL_PROTECTED:
385                 os <<  "\\hspace*{\\fill}";
386                 break;
387         case InsetSpaceParams::DOTFILL:
388                 os <<  "\\dotfill{}";
389                 break;
390         case InsetSpaceParams::HRULEFILL:
391                 os <<  "\\hrulefill{}";
392                 break;
393         case InsetSpaceParams::LEFTARROWFILL:
394                 os <<  "\\leftarrowfill{}";
395                 break;
396         case InsetSpaceParams::RIGHTARROWFILL:
397                 os <<  "\\rightarrowfill{}";
398                 break;
399         case InsetSpaceParams::UPBRACEFILL:
400                 os <<  "\\upbracefill{}";
401                 break;
402         case InsetSpaceParams::DOWNBRACEFILL:
403                 os <<  "\\downbracefill{}";
404                 break;
405         case InsetSpaceParams::CUSTOM:
406                 os <<  "\\hspace{}";
407                 break;
408         case InsetSpaceParams::CUSTOM_PROTECTED:
409                 os <<  "\\hspace*{}";
410                 break;
411         }
412         
413         if (!length.empty())
414                 os << "\n\\length " << length.asString();
415 }
416
417
418 void InsetSpaceParams::read(Lexer & lex)
419 {
420         lex.setContext("InsetSpaceParams::read");
421         string command;
422         lex >> command;
423
424         if (command == "\\space{}")
425                 kind = InsetSpaceParams::NORMAL;
426         else if (command == "~")
427                 kind = InsetSpaceParams::PROTECTED;
428         else if (command == "\\thinspace{}")
429                 kind = InsetSpaceParams::THIN;
430         else if (command == "\\quad{}")
431                 kind = InsetSpaceParams::QUAD;
432         else if (command == "\\qquad{}")
433                 kind = InsetSpaceParams::QQUAD;
434         else if (command == "\\enspace{}")
435                 kind = InsetSpaceParams::ENSPACE;
436         else if (command == "\\enskip{}")
437                 kind = InsetSpaceParams::ENSKIP;
438         else if (command == "\\negthinspace{}")
439                 kind = InsetSpaceParams::NEGTHIN;
440         else if (command == "\\hfill{}")
441                 kind = InsetSpaceParams::HFILL;
442         else if (command == "\\hspace*{\\fill}")
443                 kind = InsetSpaceParams::HFILL_PROTECTED;
444         else if (command == "\\dotfill{}")
445                 kind = InsetSpaceParams::DOTFILL;
446         else if (command == "\\hrulefill{}")
447                 kind = InsetSpaceParams::HRULEFILL;
448         else if (command == "\\hspace{}")
449                 kind = InsetSpaceParams::CUSTOM;
450         else if (command == "\\leftarrowfill{}")
451                 kind = InsetSpaceParams::LEFTARROWFILL;
452         else if (command == "\\rightarrowfill{}")
453                 kind = InsetSpaceParams::RIGHTARROWFILL;
454         else if (command == "\\upbracefill{}")
455                 kind = InsetSpaceParams::UPBRACEFILL;
456         else if (command == "\\downbracefill{}")
457                 kind = InsetSpaceParams::DOWNBRACEFILL;
458         else if (command == "\\hspace*{}")
459                 kind = InsetSpaceParams::CUSTOM_PROTECTED;
460         else
461                 lex.printError("InsetSpace: Unknown kind: `$$Token'");
462
463         if (lex.checkFor("\\length"))
464                 lex >> length;
465 }
466
467
468 void InsetSpace::write(ostream & os) const
469 {
470         os << "space ";
471         params_.write(os);
472 }
473
474
475 void InsetSpace::read(Lexer & lex)
476 {
477         params_.read(lex);
478         lex >> "\\end_inset";
479 }
480
481
482 int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const
483 {
484         switch (params_.kind) {
485         case InsetSpaceParams::NORMAL:
486                 os << (runparams.free_spacing ? " " : "\\ ");
487                 break;
488         case InsetSpaceParams::PROTECTED:
489                 os << (runparams.free_spacing ? ' ' : '~');
490                 break;
491         case InsetSpaceParams::THIN:
492                 os << (runparams.free_spacing ? " " : "\\,");
493                 break;
494         case InsetSpaceParams::QUAD:
495                 os << (runparams.free_spacing ? " " : "\\quad{}");
496                 break;
497         case InsetSpaceParams::QQUAD:
498                 os << (runparams.free_spacing ? " " : "\\qquad{}");
499                 break;
500         case InsetSpaceParams::ENSPACE:
501                 os << (runparams.free_spacing ? " " : "\\enspace{}");
502                 break;
503         case InsetSpaceParams::ENSKIP:
504                 os << (runparams.free_spacing ? " " : "\\enskip{}");
505                 break;
506         case InsetSpaceParams::NEGTHIN:
507                 os << (runparams.free_spacing ? " " : "\\negthinspace{}");
508                 break;
509         case InsetSpaceParams::HFILL:
510                 os << (runparams.free_spacing ? " " : "\\hfill{}");
511                 break;
512         case InsetSpaceParams::HFILL_PROTECTED:
513                 os << (runparams.free_spacing ? " " : "\\hspace*{\\fill}");
514                 break;
515         case InsetSpaceParams::DOTFILL:
516                 os << (runparams.free_spacing ? " " : "\\dotfill{}");
517                 break;
518         case InsetSpaceParams::HRULEFILL:
519                 os << (runparams.free_spacing ? " " : "\\hrulefill{}");
520                 break;
521         case InsetSpaceParams::LEFTARROWFILL:
522                 os << (runparams.free_spacing ? " " : "\\leftarrowfill{}");
523                 break;
524         case InsetSpaceParams::RIGHTARROWFILL:
525                 os << (runparams.free_spacing ? " " : "\\rightarrowfill{}");
526                 break;
527         case InsetSpaceParams::UPBRACEFILL:
528                 os << (runparams.free_spacing ? " " : "\\upbracefill{}");
529                 break;
530         case InsetSpaceParams::DOWNBRACEFILL:
531                 os << (runparams.free_spacing ? " " : "\\downbracefill{}");
532                 break;
533         case InsetSpaceParams::CUSTOM:
534                 if (runparams.free_spacing)
535                         os << " ";
536                 else
537                         os << "\\hspace{" << from_ascii(params_.length.asLatexString()) << "}";
538                 break;
539         case InsetSpaceParams::CUSTOM_PROTECTED:
540                 if (runparams.free_spacing)
541                         os << " ";
542                 else
543                         os << "\\hspace*{" << from_ascii(params_.length.asLatexString()) << "}";
544                 break;
545         }
546         return 0;
547 }
548
549
550 int InsetSpace::plaintext(odocstream & os, OutputParams const &) const
551 {
552         switch (params_.kind) {
553         case InsetSpaceParams::HFILL:
554         case InsetSpaceParams::HFILL_PROTECTED:
555                 os << "     ";
556                 return 5;
557         case InsetSpaceParams::DOTFILL:
558                 os << ".....";
559                 return 5;
560         case InsetSpaceParams::HRULEFILL:
561                 os << "_____";
562                 return 5;
563         case InsetSpaceParams::LEFTARROWFILL:
564                 os << "<----";
565                 return 5;
566         case InsetSpaceParams::RIGHTARROWFILL:
567                 os << "---->";
568                 return 5;
569         case InsetSpaceParams::UPBRACEFILL:
570                 os << "\\-v-/";
571                 return 5;
572         case InsetSpaceParams::DOWNBRACEFILL:
573                 os << "/-^-\\";
574                 return 5;
575         default:
576                 os << ' ';
577                 return 1;
578         }
579 }
580
581
582 int InsetSpace::docbook(odocstream & os, OutputParams const &) const
583 {
584         switch (params_.kind) {
585         case InsetSpaceParams::NORMAL:
586         case InsetSpaceParams::QUAD:
587         case InsetSpaceParams::QQUAD:
588         case InsetSpaceParams::ENSKIP:
589                 os << " ";
590                 break;
591         case InsetSpaceParams::PROTECTED:
592         case InsetSpaceParams::ENSPACE:
593         case InsetSpaceParams::THIN:
594         case InsetSpaceParams::NEGTHIN:
595                 os << "&nbsp;";
596                 break;
597         case InsetSpaceParams::HFILL:
598         case InsetSpaceParams::HFILL_PROTECTED:
599                 os << '\n';
600         case InsetSpaceParams::DOTFILL:
601                 // FIXME
602                 os << '\n';
603         case InsetSpaceParams::HRULEFILL:
604                 // FIXME
605                 os << '\n';
606         case InsetSpaceParams::LEFTARROWFILL:
607         case InsetSpaceParams::RIGHTARROWFILL:
608         case InsetSpaceParams::UPBRACEFILL:
609         case InsetSpaceParams::DOWNBRACEFILL:
610         case InsetSpaceParams::CUSTOM:
611         case InsetSpaceParams::CUSTOM_PROTECTED:
612                 // FIXME
613                 os << '\n';
614         }
615         return 0;
616 }
617
618
619 void InsetSpace::textString(odocstream & os) const
620 {
621         plaintext(os, OutputParams(0));
622 }
623
624
625 bool InsetSpace::isStretchableSpace() const
626 {
627         return params_.kind == InsetSpaceParams::HFILL
628                 || params_.kind == InsetSpaceParams::HFILL_PROTECTED
629                 || params_.kind == InsetSpaceParams::DOTFILL
630                 || params_.kind == InsetSpaceParams::HRULEFILL
631                 || params_.kind == InsetSpaceParams::LEFTARROWFILL
632                 || params_.kind == InsetSpaceParams::RIGHTARROWFILL
633                 || params_.kind == InsetSpaceParams::UPBRACEFILL
634                 || params_.kind == InsetSpaceParams::DOWNBRACEFILL;
635 }
636
637
638 docstring InsetSpace::contextMenu(BufferView const &, int, int) const
639 {
640         return from_ascii("context-space");
641 }
642
643
644 void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
645 {
646         params = InsetSpaceParams();
647         if (in.empty())
648                 return;
649
650         istringstream data(in);
651         Lexer lex;
652         lex.setStream(data);
653         lex.setContext("InsetSpace::string2params");
654         lex >> "space";
655
656         // There are cases, such as when we are called via getStatus() from
657         // Dialog::canApply(), where we are just called with "space" rather
658         // than a full "space \type{}\n\\end_inset".
659         if (lex.isOK())
660                 params.read(lex);
661 }
662
663
664 string InsetSpace::params2string(InsetSpaceParams const & params)
665 {
666         ostringstream data;
667         data << "space" << ' ';
668         params.write(data);
669         return data.str();
670 }
671
672
673 } // namespace lyx