]> git.lyx.org Git - lyx.git/blob - src/insets/insetspecialchar.C
removed a warning from screen and added CFLAGS in lyx.spec.in.
[lyx.git] / src / insets / insetspecialchar.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1997 Asger Alstrup
7  *
8  * ======================================================*/
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "insetspecialchar.h"
17 #include "lyxdraw.h"
18 #include "debug.h"
19 #include "LaTeXFeatures.h"
20
21 InsetSpecialChar::InsetSpecialChar()
22 {
23 }
24
25
26 InsetSpecialChar::InsetSpecialChar(Kind k)
27         : kind(k)
28 {
29 }
30
31
32 InsetSpecialChar::~InsetSpecialChar()
33 {
34 }
35
36
37 int InsetSpecialChar::Ascent(LyXFont const&font) const
38 {
39         return font.maxAscent();
40 }
41
42
43 int InsetSpecialChar::Descent(LyXFont const&font) const
44 {
45         return font.maxDescent();
46 }
47
48
49 int InsetSpecialChar::Width(LyXFont const&font) const
50 {
51         LyXFont f = font;
52         switch (kind) {
53         case HYPHENATION:
54         {
55                 int w = f.textWidth("-", 1);
56                 if (w > 5) 
57                         w -= 2; // to make it look shorter
58                 return w;
59         }
60         case END_OF_SENTENCE:
61         {
62                 return f.textWidth(".", 1);
63         }
64         case LDOTS:
65         {
66                 return f.textWidth(". . .", 5);
67         }
68         case MENU_SEPARATOR: {
69                 return f.textWidth(" x ", 3);
70         }
71         }
72         return 1; // To shut up gcc
73 }
74
75
76 void InsetSpecialChar::Draw(LyXFont font, LyXScreen &scr,
77                             int baseline, float &x)
78 {
79         switch (kind) {
80         case HYPHENATION:
81         {
82                 font.setColor(LyXFont::MAGENTA);
83                 scr.drawText(font, "-", 1, baseline, int(x));
84                 x += Width(font);
85                 break;
86         }
87         case END_OF_SENTENCE:
88         {
89                 font.setColor(LyXFont::MAGENTA);
90                 scr.drawText(font, ".", 1, baseline, int(x));
91                 x += Width(font);
92                 break;
93         }
94         case LDOTS:
95         {
96                 font.setColor(LyXFont::MAGENTA);
97                 scr.drawText(font, ". . .", 5, baseline, int(x));
98                 x += Width(font);
99                 break;
100         }
101         case MENU_SEPARATOR:
102         {
103                 // A triangle the width and height of an 'x'
104                 int w = font.textWidth("x", 1);
105                 int ox = font.textWidth(" ", 1) + int(x);
106                 int h = font.ascent('x');
107                 XPoint p[4];
108                 p[0].x = ox;    p[0].y = baseline;
109                 p[1].x = ox;    p[1].y = baseline - h;
110                 p[2].x = ox + w;p[2].y = baseline - h/2;
111                 p[3].x = ox;    p[3].y = baseline;
112                 scr.drawLines(getGC(gc_copy), p, 4);
113                 x += Width(font);
114         }
115         }
116 }
117
118
119 // In lyxf3 this will be just LaTeX
120 void InsetSpecialChar::Write(FILE *file)
121 {
122         string command;
123         switch (kind) {
124         case HYPHENATION:       command = "\\-";        break;
125         case END_OF_SENTENCE:   command = "\\@.";       break;
126         case LDOTS:             command = "\\ldots{}";  break;
127         case MENU_SEPARATOR:    command = "\\menuseparator"; break;
128         }
129         fprintf(file, "\\SpecialChar %s\n", command.c_str());
130 }
131
132
133 // This function will not be necessary when lyx3
134 void InsetSpecialChar::Read(LyXLex &lex)
135 {    
136         lex.nextToken();
137         string command = lex.GetString();
138
139         if (command=="\\-")
140                 kind = HYPHENATION;
141         else if (command=="\\@.")
142                 kind = END_OF_SENTENCE;
143         else if (command=="\\ldots{}")
144                 kind = LDOTS;
145         else if (command=="\\menuseparator")
146                 kind = MENU_SEPARATOR;
147         else
148                 lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
149 }
150
151
152 int InsetSpecialChar::Latex(FILE *file, signed char /*fragile*/)
153 {
154         string command;
155         signed char dummy = 0;
156         Latex(command, dummy);
157         fprintf(file, "%s", command.c_str());
158         return 0;
159 }
160
161
162 int InsetSpecialChar::Latex(string &file, signed char /*fragile*/)
163 {
164         switch (kind) {
165         case HYPHENATION:       file += "\\-";  break;
166         case END_OF_SENTENCE:   file += "\\@."; break;
167         case LDOTS:             file += "\\ldots{}";    break;
168         case MENU_SEPARATOR:    file += "\\lyxarrow{}"; break;
169         }
170         return 0;
171 }
172
173
174 int InsetSpecialChar::Linuxdoc(string &file)
175 {
176         switch (kind) {
177         case HYPHENATION:       file += "";     break;
178         case END_OF_SENTENCE:   file += "";     break;
179         case LDOTS:             file += "...";  break;
180         case MENU_SEPARATOR:    file += "->";   break;
181         }
182         return 0;
183 }
184
185
186 int InsetSpecialChar::DocBook(string &file)
187 {
188         switch (kind) {
189         case HYPHENATION:       file += "";     break;
190         case END_OF_SENTENCE:   file += "";     break;
191         case LDOTS:             file += "...";  break;
192         case MENU_SEPARATOR:    file += "->";   break;
193         }
194         return 0;
195 }
196
197
198 Inset* InsetSpecialChar::Clone()
199 {
200         InsetSpecialChar *result = new InsetSpecialChar(kind);
201         return result;
202 }
203
204
205 void InsetSpecialChar::Validate(LaTeXFeatures& features) const
206 {
207         if (kind == MENU_SEPARATOR) {
208                 features.lyxarrow = true;
209         }
210 }