]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
b7c0ee15edc23cf631bc252ee82b746fea5bef6e
[lyx.git] / src / insets / inseterror.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-1999 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "inseterror.h"
18 #include "lyxdraw.h"
19 #include "gettext.h"
20 #include "lyx_gui_misc.h" // CancelCloseBoxCB
21
22 /* Error, used for the LaTeX-Error Messages */
23
24 InsetError::InsetError()
25 {
26         form = 0;
27 }
28
29 InsetError::InsetError(string const & str)
30         : contents(str)
31 {
32         form = 0;
33 }
34
35
36 InsetError::~InsetError()
37 {
38         if (form) {
39                 fl_hide_form(form);
40                 fl_free_form(form);
41                 form = 0;
42         }
43 }
44
45
46 int InsetError::Ascent(LyXFont const & font) const
47 {
48         LyXFont efont;
49         efont.setSize(font.size()).decSize();
50         return efont.maxAscent()+1;
51 }
52
53
54 int InsetError::Descent(LyXFont const & font) const
55 {
56         LyXFont efont;
57         efont.setSize(font.size()).decSize();
58         return efont.maxDescent()+1;
59 }
60
61
62 int InsetError::Width(LyXFont const & font) const
63 {
64         LyXFont efont;
65         efont.setSize(font.size()).decSize();
66         return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
67 }
68
69
70 void InsetError::Draw(LyXFont font, LyXScreen & scr,
71                       int baseline, float & x)
72 {
73         LyXFont efont;
74         efont.setSize(font.size()).decSize();
75         efont.setLatex(LyXFont::ON);
76    
77         // Draw as "Error" in a framed box
78         x += 1;
79         scr.fillRectangle(gc_lighted,
80                           int(x), baseline - Ascent(font)+1,
81                           Width(font)-2, Ascent(font)+ Descent(font)-2);
82         scr.drawRectangle(gc_foot,
83                           int(x), baseline-Ascent(font)+1,
84                           Width(font)-2, Ascent(font)+Descent(font)-2); 
85         scr.drawString(efont, _("Error"), baseline, int(x+2));
86
87         x +=  Width(font) - 1;
88 }
89
90
91 void InsetError::Write(FILE *)
92 {
93 }
94
95 void InsetError::Read(LyXLex &)
96 {
97 }
98
99
100 int InsetError::Latex(FILE *, signed char /*fragile*/)
101 {
102         return 0;
103 }
104
105
106 int InsetError::Latex(string &, signed char /*fragile*/)
107 {
108         return 0;
109 }
110
111
112 int InsetError::Linuxdoc(string &)
113 {
114         return 0;
115 }
116
117
118 int InsetError::DocBook(string &)
119 {
120         return 0;
121 }
122
123
124 bool InsetError::AutoDelete() const
125 {
126         return true;
127 }
128
129
130 unsigned char InsetError::Editable() const
131 {
132         return 1;
133 }
134
135
136 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
137 {
138         InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
139         if (inset->form) {
140                 fl_hide_form(inset->form);
141                 fl_free_form(inset->form);
142                 inset->form = 0;
143         }
144 }
145
146
147 // A C wrapper
148 extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
149 {
150         InsetError::CloseErrorCB(ob , data);
151 }
152
153
154 void InsetError::Edit(int, int)
155 {
156         static int ow = 400, oh = 240;
157
158         if (!form) {
159                 FL_OBJECT * obj;
160                 form = fl_bgn_form(FL_UP_BOX, ow, oh);
161                 strobj = fl_add_box(FL_FRAME_BOX, 10, 10, 380, 180, "");
162                 fl_set_object_color(strobj, FL_MCOL, FL_MCOL);
163                 fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
164                 obj = fl_add_button(FL_RETURN_BUTTON, 140, 200, 120, 30,
165                                     _("Close"));
166                 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
167                 obj->u_vdata = this;
168                 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
169                 fl_set_object_resize(obj, FL_RESIZE_NONE);
170                 fl_end_form();
171                 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
172         }
173         fl_set_object_label(strobj, contents.c_str());
174         if (form->visible) {
175                 fl_raise_form(form);
176         } else {
177                 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
178                              FL_FULLBORDER, _("LaTeX Error"));
179                 fl_set_form_minsize(form, ow, oh);
180         }
181 }
182
183
184 Inset * InsetError::Clone() const
185 {
186         return new InsetError(contents);
187 }