]> git.lyx.org Git - lyx.git/blob - src/bufferview_funcs.C
Changes needed to activate Character dialog buttons when any field is not
[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 "LyXView.h"
19 #include "BufferView.h"
20 #include "lyxparagraph.h"
21 #include "lyxfont.h"
22 #include "lyx_gui_misc.h"
23 #include "lyxtext.h"
24 #include "buffer.h"
25 #include "support/lstrings.h"
26 #include "lyx_cb.h"
27 #include "language.h"
28 #include "gettext.h"
29
30
31 void Emph(BufferView * bv)
32 {
33         LyXFont font(LyXFont::ALL_IGNORE);
34         font.setEmph(LyXFont::TOGGLE);
35         ToggleAndShow(bv, font);
36 }
37
38
39 void Bold(BufferView * bv)
40 {
41         LyXFont font(LyXFont::ALL_IGNORE);
42         font.setSeries(LyXFont::BOLD_SERIES);
43         ToggleAndShow(bv, font);
44 }
45
46
47 void Noun(BufferView * bv)
48 {
49         LyXFont font(LyXFont::ALL_IGNORE);
50         font.setNoun(LyXFont::TOGGLE);
51         ToggleAndShow(bv, font);
52 }
53
54
55 void Number(BufferView * bv)
56 {
57         LyXFont font(LyXFont::ALL_IGNORE);
58         font.setNumber(LyXFont::TOGGLE);
59         ToggleAndShow(bv, font);
60 }
61
62 void Lang(BufferView * bv, string const & l)
63 {
64         LyXFont font(LyXFont::ALL_IGNORE);
65         Language const * lang = languages.getLanguage(l);
66         if (lang) {
67                 font.setLanguage(lang);
68                 ToggleAndShow(bv, font);
69         } else
70                 WriteAlert(_("Error! unknown language"),l);
71 }
72
73
74 void Tex(BufferView * bv)
75 {
76         LyXFont font(LyXFont::ALL_IGNORE);
77         font.setLatex (LyXFont::TOGGLE);
78         ToggleAndShow(bv, font);
79 }
80
81
82 // Change environment depth.
83 // if decInc >= 0, increment depth
84 // if decInc <  0, decrement depth
85 void changeDepth(BufferView * bv, LyXText * text, int decInc)
86 {
87         if (!bv->available() || !text)
88             return;
89         
90         bv->hideCursor();
91         bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
92         if (decInc >= 0)
93                 text->IncDepth(bv);
94         else
95                 text->DecDepth(bv);
96         if (text->inset_owner)
97             bv->updateInset((Inset *)text->inset_owner, true);
98         bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
99         bv->owner()->message(_("Changed environment depth "
100                                "(in possible range, maybe not)"));
101 }
102
103
104 // How should this actually work? Should it prohibit input in all BufferViews,
105 // or just in the current one? If "just the current one", then it should be
106 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
107 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
108 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
109 // current LyxView that should be prohibited (Lgb) (This applies to
110 // "AllowInput" as well.)
111 void ProhibitInput(BufferView * bv)
112 {
113         bv->hideCursor();
114
115         static Cursor cursor;
116         static bool cursor_undefined = true;
117    
118         if (cursor_undefined){
119                 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
120                 XFlush(fl_get_display());
121                 cursor_undefined = false;
122         }
123    
124         /* set the cursor to the watch for all forms and the canvas */ 
125         XDefineCursor(fl_get_display(), bv->owner()->getForm()->window, 
126                       cursor);
127
128         XFlush(fl_get_display());
129         fl_deactivate_all_forms();
130 }
131
132
133 void AllowInput(BufferView * bv)
134 {
135         /* reset the cursor from the watch for all forms and the canvas */
136    
137         XUndefineCursor(fl_get_display(), bv->owner()->getForm()->window);
138
139         XFlush(fl_get_display());
140         fl_activate_all_forms();
141 }
142
143
144 void Code(BufferView * bv)
145 {
146         LyXFont font(LyXFont::ALL_IGNORE);
147         font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
148         ToggleAndShow(bv, font);
149 }
150
151
152 void Sans(BufferView * bv)
153 {
154         LyXFont font(LyXFont::ALL_IGNORE);
155         font.setFamily(LyXFont::SANS_FAMILY);
156         ToggleAndShow(bv, font);
157 }
158
159
160 void Roman(BufferView * bv)
161 {
162         LyXFont font(LyXFont::ALL_IGNORE);
163         font.setFamily(LyXFont::ROMAN_FAMILY);
164         ToggleAndShow(bv, font);
165 }
166
167
168 void StyleReset(BufferView * bv)
169 {
170         LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
171         ToggleAndShow(bv, font);
172 }
173
174
175 void Underline(BufferView * bv)
176 {
177         LyXFont font(LyXFont::ALL_IGNORE);
178         font.setUnderbar(LyXFont::TOGGLE);
179         ToggleAndShow(bv, font);
180 }
181
182
183 void FontSize(BufferView * bv, string const & size)
184 {
185         LyXFont font(LyXFont::ALL_IGNORE);
186         font.setLyXSize(size);
187         ToggleAndShow(bv, font);
188 }
189
190
191 // Returns the current font and depth as a message. 
192 string const CurrentState(BufferView * bv)
193 {
194         string state;
195         if (bv->available()) { 
196                 // I think we should only show changes from the default
197                 // font. (Asger)
198                 LyXText * text = bv->getLyXText();
199                 Buffer * buffer = bv->buffer();
200                 LyXFont font = text->real_current_font;
201                 LyXFont const & defaultfont =
202                         textclasslist
203                         .TextClass(buffer->params.textclass)
204                         .defaultfont();
205                 font.reduce(defaultfont);
206                 state = _("Font: ") + font.stateText(&buffer->params);
207                 // The paragraph depth
208                 int depth = text->GetDepth();
209                 if (depth > 0) 
210                         state += string(_(", Depth: ")) + tostr(depth);
211                 // The paragraph spacing, but only if different from
212                 // buffer spacing.
213                 if (!text->cursor.par()->params.spacing().isDefault()) {
214                         Spacing::Space cur_space =
215                                 text->cursor.par()->params.spacing().getSpace();
216                         state += _(", Spacing: ");
217                         switch (cur_space) {
218                         case Spacing::Single:
219                                 state += _("Single");
220                                 break;
221                         case Spacing::Onehalf:
222                                 state += _("Onehalf");
223                                 break;
224                         case Spacing::Double:
225                                 state += _("Double");
226                                 break;
227                         case Spacing::Other:
228                                 state += _("Other (");
229                                 state += tostr(text->cursor.par()->params.spacing().getValue());
230                                 state += ")";
231                                 break;
232                         case Spacing::Default:
233                                 // should never happen, do nothing
234                                 break;
235                         }
236                 }
237         }
238         return state;
239 }
240
241
242 /* -------> Does the actual toggle job of the XxxCB() calls above.
243  * Also shows the current font state.
244  */
245 void ToggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
246 {
247         if (bv->available()) { 
248                 if (bv->theLockingInset()) {
249                         bv->theLockingInset()->SetFont(bv, font, toggleall);
250                         return;
251                 }
252                 LyXText * text = bv->getLyXText();
253                 if (!text)
254                         return;
255
256                 bv->hideCursor();
257                 bv->update(text, BufferView::SELECT|BufferView::FITCUR);
258                 text->ToggleFree(bv, font, toggleall);
259                 bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
260
261                 if (font.language() != ignore_language ||
262                     font.latex() != LyXFont::IGNORE ||
263                     font.number() != LyXFont::IGNORE)
264                 {
265                         LyXCursor & cursor = text->cursor;
266                         text->ComputeBidiTables(bv->buffer(), cursor.row());
267                         if (cursor.boundary() != 
268                             text->IsBoundary(bv->buffer(), cursor.par(), cursor.pos(),
269                                              text->real_current_font) )
270                                 text->SetCursor(bv, cursor.par(), cursor.pos(),
271                                                 false, !cursor.boundary());
272                 }
273         }
274 }