This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / insets / inseterror.C
blob4f1beaa8a3f1429b72b4232314f87f6877447407
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  * ======================================================*/
11 #include <config.h>
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
17 #include "definitions.h"
18 #include "inseterror.h"
19 #include "lyxdraw.h"
20 #include "gettext.h"
21 #include "lyx_gui_misc.h" // CancelCloseBoxCB
23 /* Error, used for the LaTeX-Error Messages */
25 InsetError::InsetError()
27         form = 0;
30 InsetError::InsetError(string const & string)
31         : contents(string)
33         form = 0;
37 InsetError::~InsetError()
39         if (form) {
40                 fl_hide_form(form);
41                 fl_free_form(form);
42                 form = 0;
43         }
47 int InsetError::Ascent(LyXFont const & font) const
49         LyXFont efont;
50         efont.setSize(font.size()).decSize();
51         return efont.maxAscent()+1;
55 int InsetError::Descent(LyXFont const & font) const
57         LyXFont efont;
58         efont.setSize(font.size()).decSize();
59         return efont.maxDescent()+1;
63 int InsetError::Width(LyXFont const & font) const
65         LyXFont efont;
66         efont.setSize(font.size()).decSize();
67         return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
71 void InsetError::Draw(LyXFont font, LyXScreen & scr,
72                       int baseline, float & x)
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.fillRectangle(gc_lighted,
81                           int(x), baseline - Ascent(font)+1,
82                           Width(font)-2,Ascent(font)+ Descent(font)-2);
83         scr.drawRectangle(gc_foot,
84                           int(x), baseline-Ascent(font)+1,
85                           Width(font)-2, Ascent(font)+Descent(font)-2); 
86         scr.drawString(efont, _("Error"), baseline, int(x+2));
88         x +=  Width(font) - 1;
92 void InsetError::Write(FILE *)
96 void InsetError::Read(LyXLex &)
101 int InsetError::Latex(FILE *, signed char /*fragile*/)
103         return 0;
107 int InsetError::Latex(string &, signed char /*fragile*/)
109         return 0;
113 int InsetError::Linuxdoc(string &)
115         return 0;
119 int InsetError::DocBook(string &)
121         return 0;
125 bool InsetError::AutoDelete() const
127         return true;
131 unsigned char InsetError::Editable() const
133         return 1;
137 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
139         InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
140         if (inset->form) {
141                 fl_hide_form(inset->form);
142                 fl_free_form(inset->form);
143                 inset->form = 0;
144         }
147 // A C wrapper
148 extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
150         InsetError::CloseErrorCB(ob , data);
154 void InsetError::Edit(int, int)
156         static int ow = 400, oh = 240;
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,_("Close"));
165                 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
166                 obj->u_vdata = this;
167                 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
168                 fl_set_object_resize(obj, FL_RESIZE_NONE);
169                 fl_end_form();
170                 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
171         }
172         fl_set_object_label(strobj, contents.c_str());
173         if (form->visible) {
174                 fl_raise_form(form);
175         } else {
176                 fl_show_form(form,FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, 
177                              _("LaTeX Error"));
178                 fl_set_form_minsize(form, ow, oh);
179         }
183 Inset* InsetError::Clone()
185         InsetError * result = new InsetError(contents);
186         return result;