]> git.lyx.org Git - lyx.git/blob - src/bufferview_funcs.C
remove unused code
[lyx.git] / src / bufferview_funcs.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "bufferview_funcs.h"
18 #include "frontends/LyXView.h"
19 #include "BufferView.h"
20 #include "paragraph.h"
21 #include "lyxfont.h"
22 #include "lyxtext.h"
23 #include "buffer.h"
24 #include "lyx_cb.h"
25 #include "language.h"
26 #include "gettext.h"
27 #include "ParagraphParameters.h"
28
29 #include "frontends/Alert.h"
30
31 #include "support/lstrings.h"
32
33 void emph(BufferView * bv)
34 {
35         LyXFont font(LyXFont::ALL_IGNORE);
36         font.setEmph(LyXFont::TOGGLE);
37         toggleAndShow(bv, font);
38 }
39
40
41 void bold(BufferView * bv)
42 {
43         LyXFont font(LyXFont::ALL_IGNORE);
44         font.setSeries(LyXFont::BOLD_SERIES);
45         toggleAndShow(bv, font);
46 }
47
48
49 void noun(BufferView * bv)
50 {
51         LyXFont font(LyXFont::ALL_IGNORE);
52         font.setNoun(LyXFont::TOGGLE);
53         toggleAndShow(bv, font);
54 }
55
56
57 void number(BufferView * bv)
58 {
59         LyXFont font(LyXFont::ALL_IGNORE);
60         font.setNumber(LyXFont::TOGGLE);
61         toggleAndShow(bv, font);
62 }
63
64 void lang(BufferView * bv, string const & l)
65 {
66         LyXFont font(LyXFont::ALL_IGNORE);
67         Language const * lang = languages.getLanguage(l);
68         if (lang) {
69                 font.setLanguage(lang);
70                 toggleAndShow(bv, font);
71         } else
72                 Alert::alert(_("Error! unknown language"),l);
73 }
74
75
76 // Change environment depth.
77 // if decInc >= 0, increment depth
78 // if decInc <  0, decrement depth
79 void changeDepth(BufferView * bv, LyXText * text, int decInc)
80 {
81         if (!bv->available() || !text)
82             return;
83
84         bv->hideCursor();
85         bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
86         if (decInc >= 0)
87                 text->incDepth(bv);
88         else
89                 text->decDepth(bv);
90         if (text->inset_owner)
91             bv->updateInset((Inset *)text->inset_owner, true);
92         bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
93         bv->owner()->message(_("Changed environment depth "
94                                "(in possible range, maybe not)"));
95 }
96
97
98 void code(BufferView * bv)
99 {
100         LyXFont font(LyXFont::ALL_IGNORE);
101         font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
102         toggleAndShow(bv, font);
103 }
104
105
106 void sans(BufferView * bv)
107 {
108         LyXFont font(LyXFont::ALL_IGNORE);
109         font.setFamily(LyXFont::SANS_FAMILY);
110         toggleAndShow(bv, font);
111 }
112
113
114 void roman(BufferView * bv)
115 {
116         LyXFont font(LyXFont::ALL_IGNORE);
117         font.setFamily(LyXFont::ROMAN_FAMILY);
118         toggleAndShow(bv, font);
119 }
120
121
122 void styleReset(BufferView * bv)
123 {
124 #ifndef INHERIT_LANG
125         LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
126 #else
127         LyXFont font(LyXFont::ALL_INHERIT);
128 #endif
129         toggleAndShow(bv, font);
130 }
131
132
133 void underline(BufferView * bv)
134 {
135         LyXFont font(LyXFont::ALL_IGNORE);
136         font.setUnderbar(LyXFont::TOGGLE);
137         toggleAndShow(bv, font);
138 }
139
140
141 void fontSize(BufferView * bv, string const & size)
142 {
143         LyXFont font(LyXFont::ALL_IGNORE);
144         font.setLyXSize(size);
145         toggleAndShow(bv, font);
146 }
147
148
149 // Returns the current font and depth as a message.
150 string const currentState(BufferView * bv)
151 {
152         ostringstream state;
153
154         if (bv->available()) {
155                 // I think we should only show changes from the default
156                 // font. (Asger)
157                 LyXText * text = bv->getLyXText();
158                 Buffer * buffer = bv->buffer();
159                 LyXFont font = text->real_current_font;
160                 LyXFont const & defaultfont =
161                         buffer->params.getLyXTextClass().defaultfont();
162                 font.reduce(defaultfont);
163
164                 state << _("Font:") << ' '
165                       << font.stateText(&buffer->params);
166
167                 // The paragraph depth
168                 int depth = text->getDepth();
169                 if (depth > 0)
170                         state << _(", Depth: ") << depth;
171
172                 // The paragraph spacing, but only if different from
173                 // buffer spacing.
174                 if (!text->cursor.par()->params().spacing().isDefault()) {
175                         Spacing::Space cur_space =
176                                 text->cursor.par()->params().spacing().getSpace();
177                         state << _(", Spacing: ");
178
179                         switch (cur_space) {
180                         case Spacing::Single:
181                                 state << _("Single");
182
183                                 break;
184                         case Spacing::Onehalf:
185                                 state << _("Onehalf");
186                                 break;
187                         case Spacing::Double:
188                                 state << _("Double");
189                                 break;
190                         case Spacing::Other:
191                                 state << _("Other (")
192                                       << text->cursor.par()->params().spacing().getValue()
193                                       << ")";
194                                 break;
195                         case Spacing::Default:
196                                 // should never happen, do nothing
197                                 break;
198                         }
199                 }
200 #ifdef DEVEL_VERSION
201                 state << _(", Paragraph: ") << text->cursor.par()->id();
202 #endif
203         }
204         return state.str().c_str();
205 }
206
207
208 /* Does the actual toggle job of the calls above.
209  * Also shows the current font state.
210  */
211 void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
212 {
213         if (!bv->available())
214                 return;
215  
216         if (bv->theLockingInset()) {
217                 bv->theLockingInset()->setFont(bv, font, toggleall);
218                 return;
219         }
220  
221         LyXText * text = bv->getLyXText();
222         // FIXME: can this happen ?? 
223         if (!text)
224                 return;
225
226         bv->hideCursor();
227         bv->update(text, BufferView::SELECT | BufferView::FITCUR);
228         text->toggleFree(bv, font, toggleall);
229         bv->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
230
231         if (font.language() != ignore_language ||
232             font.number() != LyXFont::IGNORE) {
233                 LyXCursor & cursor = text->cursor;
234                 text->computeBidiTables(bv->buffer(), cursor.row());
235                 if (cursor.boundary() !=
236                     text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
237                                      text->real_current_font))
238                         text->setCursor(bv, cursor.par(), cursor.pos(),
239                                         false, !cursor.boundary());
240         }
241 }