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