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