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