]> git.lyx.org Git - lyx.git/blob - src/figureForm.C
Fix working of the spellchecker dialog with ispell when there are no
[lyx.git] / src / figureForm.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 #include <fstream>
14 #include <algorithm>
15 #include <utility> 
16 #include <iostream>
17
18 #include FORMS_H_LOCATION
19
20 #include "figure_form.h"
21 #include "insets/figinset.h"
22 #include "BufferView.h"
23 #include "lyxtext.h"
24 #include "LyXView.h"
25 #include "undo_funcs.h"
26 #include "gettext.h"
27
28 extern FD_form_figure * fd_form_figure;
29 extern BufferView * current_view;
30
31 void Figure()
32 {
33         if (fd_form_figure->form_figure->visible) {
34                 fl_raise_form(fd_form_figure->form_figure);
35         } else {
36                 fl_show_form(fd_form_figure->form_figure,
37                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
38                              _("Insert Figure"));
39         }
40 }
41
42
43 /* callbacks for form form_figure */
44 extern "C" {
45         
46 void FigureApplyCB(FL_OBJECT *, long)
47 {
48         if (!current_view->available())
49                 return;
50
51         Buffer * buffer = current_view->buffer();
52         if (buffer->isReadonly()) // paranoia
53                 return;
54
55         current_view->owner()->message(_("Inserting figure..."));
56         if (fl_get_button(fd_form_figure->radio_inline)) {
57                 InsetFig * new_inset = new InsetFig(100, 20, *buffer);
58                 current_view->insertInset(new_inset);
59                 current_view->owner()->message(_("Figure inserted"));
60                 new_inset->edit(current_view, 0, 0, 0);
61                 return;
62         }
63         
64         current_view->hideCursor();
65         current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
66         current_view->beforeChange(current_view->text);
67       
68         setCursorParUndo(current_view); 
69         freezeUndo();
70
71         current_view->text->breakParagraph(current_view);
72         current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
73
74         if (current_view->text->cursor.par()->size()) {
75                 current_view->text->cursorLeft(current_view);
76          
77                 current_view->text->breakParagraph(current_view);
78                 current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
79         }
80
81         // The standard layout should always be numer 0;
82         current_view->text->setLayout(current_view, 0);
83
84                 current_view->text->
85                         setParagraph(current_view, 0, 0,
86                                      0, 0,
87                                      VSpace (0.3 * buffer->params.spacing.getValue(),
88                                              LyXLength::CM),
89                                      VSpace (0.3 *
90                                              buffer->params.spacing.getValue(),
91                                              LyXLength::CM),
92                                      Spacing(),
93                                      LYX_ALIGN_CENTER, string(), 0);
94         
95         current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
96       
97         Inset * new_inset = new InsetFig(100, 100, *buffer);
98         current_view->insertInset(new_inset);
99         new_inset->edit(current_view, 0, 0, 0);
100         current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
101         current_view->owner()->message(_("Figure inserted"));
102         unFreezeUndo();
103         current_view->setState();
104 }
105
106
107 void FigureCancelCB(FL_OBJECT *, long)
108 {
109         fl_hide_form(fd_form_figure->form_figure);
110 }
111
112
113 void FigureOKCB(FL_OBJECT * ob, long data)
114 {
115         FigureApplyCB(ob, data);
116         FigureCancelCB(ob, data);
117 }
118
119 }
120