]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinfo.C
clear()->erase() ; lots of using directives for cxx
[lyx.git] / src / insets / insetinfo.C
index 1fc4387e9ff439b7cfd292167bc7ce5c34c5ef05..3c58a89091a6712664fb6cd0b797b7019277fab9 100644 (file)
@@ -3,13 +3,14 @@
  * 
  *           LyX, The Document Processor
  *      
- *         Copyright (C) 1995 Matthias Ettrich
- *          Copyright (C) 1995-1998 The LyX Team.
+ *         Copyright 1995 Matthias Ettrich
+ *          Copyright 1995-2000 The LyX Team.
  *
- *======================================================*/
+ * ====================================================== */
 
 #include <config.h>
-#include <ctype.h>
+
+#include <cctype>
 
 #ifdef __GNUG__
 #pragma implementation
 
 #include "insetinfo.h"
 #include "lyxparagraph.h"
-#include "error.h"
-#include "lyxdraw.h"
+#include "debug.h"
 #include "gettext.h"
 #include "lyx_gui_misc.h" // CancelCloseBoxCB
 #include "buffer.h"
+#include "support/lstrings.h"
+#include "Painter.h"
+#include "font.h"
 
-//     $Id: insetinfo.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $ 
+using std::ostream;
+using std::endl;
 
-#if !defined(lint) && !defined(WITH_WARNINGS)
-static char vcid[] = "$Id: insetinfo.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $";
-#endif /* lint */
+/* Info, used for the Info boxes */
 
-extern BufferView *current_view;
+extern BufferView * current_view;
 
-/* Info, used for the Info boxes */
 
 InsetInfo::InsetInfo()
 {
-       form = NULL;
+       form = 0;
 }
 
 
-InsetInfo::InsetInfo(LString const & string)
+InsetInfo::InsetInfo(string const & string)
        : contents(string)
 {
-       form = NULL;
+       form = 0;
 }
 
 
@@ -51,61 +52,65 @@ InsetInfo::~InsetInfo()
        if (form){
                fl_hide_form(form);
                fl_free_form(form);
-               form = NULL;
+               form = 0;
        }
 }
 
 
-int InsetInfo::Ascent(LyXFont const &font) const
+int InsetInfo::ascent(Painter &, LyXFont const & font) const
 {
-       return font.maxAscent()+1;
+       return lyxfont::maxAscent(font) + 1;
 }
 
 
-int InsetInfo::Descent(LyXFont const &font) const
+int InsetInfo::descent(Painter &, LyXFont const & font) const
 {
-       return font.maxDescent()+1;
+       return lyxfont::maxDescent(font) + 1;
 }
 
 
-int InsetInfo::Width(LyXFont const &font) const
+int InsetInfo::width(Painter &, LyXFont const & font) const
 {
-       return 6 + font.textWidth(_("Note"), strlen(_("Note")));
+       return 6 + lyxfont::width(_("Note"), font);
 }
 
 
-void InsetInfo::Draw(LyXFont font, LyXScreen &scr,
-                    int baseline, float &x)
+void InsetInfo::draw(Painter & pain, LyXFont const & f,
+                    int baseline, float & x) const
 {
+       LyXFont font(f);
+       
        /* Info-insets are never LaTeX, so just correct the font */
-       font.setLatex(LyXFont::OFF);
-
+       font.setLatex(LyXFont::OFF).setColor(LColor::note);
+       
        // Draw as "Note" in a yellow box
        x += 1;
-       scr.fillRectangle(gc_note,
-                         int(x), baseline - Ascent(font)+1,
-                         Width(font)-2, Ascent(font)+Descent(font)-2);
-       scr.drawRectangle(gc_note_frame,
-                         int(x), baseline- Ascent(font)+1,
-                         Width(font)-2, Ascent(font)+Descent(font)-2);
+       pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
+                          width(pain, font) - 2,
+                          ascent(pain, font) + descent(pain, font) - 2,
+                          LColor::notebg);
+       pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
+                      width(pain, font) - 2,
+                      ascent(pain, font) + descent(pain, font) - 2,
+                      LColor::noteframe);
        
-       scr.drawString(font, _("Note"), baseline, int(x+2));
-       x +=  Width(font) - 1;
+       pain.text(int(x + 2), baseline, _("Note"), font);
+       x +=  width(pain, font) - 1;
 }
 
 
-void InsetInfo::Write(FILE *file)
+void InsetInfo::Write(ostream & os) const
 {
-       fprintf(file, "Info %s", contents.c_str());
+       os << "Info " << contents;
 }
 
 
-void InsetInfo::Read(LyXLex &lex)
+void InsetInfo::Read(LyXLex & lex)
 {
-       LString tmp = lex.GetString(); // should be "Info"
+       string tmp = lex.GetString(); // should be "Info"
        if (tmp != "Info")
-               lyxerr.print("ERROR (InsetInfo::Read): "
-                             "consistency check 1 failed.");
+               lyxerr << "ERROR (InsetInfo::Read): "
+                       "consistency check 1 failed." << endl;
 
        while (lex.IsOK()) {
                if (!lex.EatLine())
@@ -113,8 +118,8 @@ void InsetInfo::Read(LyXLex &lex)
                        // should we skip blank lines?
                        continue;
 
-               LString const token = lex.GetString().strip();
-               lyxerr.debug("Note: " + token, Error::LEX_PARSER);
+               string const token = strip(lex.GetString());
+               lyxerr[Debug::PARSER] << "Note: " << token << endl;
                
                if (token != "\\end_inset") {
                        contents += token + '\n';
@@ -123,46 +128,46 @@ void InsetInfo::Read(LyXLex &lex)
                        break;
        }
        // now remove the last '\n's
-       contents.strip('\n');
+       contents = strip(contents, '\n');
 }
       
 
-int InsetInfo::Latex(FILE *, signed char /*fragile*/)
+int InsetInfo::Latex(ostream &,
+                    bool /*fragile*/, bool /*free_spc*/) const
 {
        return 0;
 }
 
 
-int InsetInfo::Latex(LString &, signed char /*fragile*/)
+int InsetInfo::Ascii(ostream &) const
 {
        return 0;
 }
 
 
-int InsetInfo::Linuxdoc(LString &)
+int InsetInfo::Linuxdoc(ostream &) const
 {
        return 0;
 }
 
 
-int InsetInfo::DocBook(LString &)
+int InsetInfo::DocBook(ostream &) const
 {
        return 0;
 }
 
 
-unsigned char InsetInfo::Editable() const
+Inset::EDITABLE InsetInfo::Editable() const
 {
-       return 1;
+       return IS_EDITABLE;
 }
 
 
-void InsetInfo::CloseInfoCB(FL_OBJECT *, long data)
+void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
 {
-       InsetInfo *inset = (InsetInfo*) data;
-//     inset->contents = fl_get_input(inset->strobj);
-       LString tmp = fl_get_input(inset->strobj);
-       Buffer *buffer = current_view->currentBuffer();
+       InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
+       string tmp = fl_get_input(inset->strobj);
+       Buffer * buffer = current_view->buffer();
        if(tmp != inset->contents && !(buffer->isReadonly()) ) {
                buffer->markDirty();
                inset->contents = tmp;
@@ -170,45 +175,65 @@ void InsetInfo::CloseInfoCB(FL_OBJECT *, long data)
        if (inset->form) {
                fl_hide_form(inset->form);
                fl_free_form(inset->form);
-               inset->form = NULL;
+               inset->form = 0;
        }
 }
 
 
-void InsetInfo::Edit(int, int)
+// This is just a wrapper.
+extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data) 
+{
+       InsetInfo::CloseInfoCB(ob, data);
+}
+
+
+char const * InsetInfo::EditMessage() const 
+{
+       return _("Opened note");
+}
+
+
+void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
 {
-       if(current_view->currentBuffer()->isReadonly())
-               WarnReadonly();
+       static int ow = -1, oh;
+
+       if(bv->buffer()->isReadonly())
+               WarnReadonly(bv->buffer()->fileName());
        
        if (!form) {
                FL_OBJECT *obj;
-               form = fl_bgn_form(FL_UP_BOX,400,180);
-               strobj = obj = fl_add_input(FL_MULTILINE_INPUT,10,10,380,120,"");
-               fl_set_object_color(obj,FL_MCOL,FL_MCOL);
+               form = fl_bgn_form(FL_UP_BOX, 400, 180);
+               strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
+               fl_set_object_color(obj, FL_MCOL, FL_MCOL);
                fl_set_object_resize(obj, FL_RESIZE_ALL);
                fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
-               obj = fl_add_button(FL_NORMAL_BUTTON,130,140,120,30,idex(_("Close|#C^[")));
+               obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
                fl_set_object_resize(obj, FL_RESIZE_NONE);
-               fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
-               fl_set_object_callback(obj, CloseInfoCB, (long)this);
-               fl_set_object_shortcut(obj, scex(_("Close|#C^[")), (long)this);
+               fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
+               fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
+               obj->u_vdata = this;
+               fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
                fl_end_form();
-               fl_set_form_atclose(form, CancelCloseBoxCB, NULL);
+               fl_set_form_atclose(form, CancelCloseBoxCB, 0);
        }
        fl_set_input(strobj, contents.c_str());
        if (form->visible) {
                fl_raise_form(form);
        } else {
-               fl_show_form(form,FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, 
+               fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, 
                             _("Note"));
+               if (ow < 0) {
+                       ow = form->w;
+                       oh = form->h;
+               }
+               fl_set_form_minsize(form, ow, oh);
        }
 }
 
 
-Inset* InsetInfo::Clone()
+Inset * InsetInfo::Clone() const
 {
-       InsetInfo *result = new InsetInfo(contents);
-       return result;
+       return new InsetInfo(contents);
 }