home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / insetinfo.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  4KB  |  207 lines

  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. #include <ctype.h>
  13.  
  14. #ifdef __GNUG__
  15. #pragma implementation
  16. #endif
  17.  
  18. #include "insetinfo.h"
  19. #include "lyxparagraph.h"
  20. #include "error.h"
  21. #include "lyxdraw.h"
  22. #include "gettext.h"
  23. #include "lyx_gui_misc.h" // CancelCloseBoxCB
  24. #include "buffer.h"
  25.  
  26. //     $Id: insetinfo.C,v 1.1.1.1 1998/04/23 16:02:50 larsbj Exp $    
  27.  
  28. #if !defined(lint) && !defined(WITH_WARNINGS)
  29. static char vcid[] = "$Id: insetinfo.C,v 1.1.1.1 1998/04/23 16:02:50 larsbj Exp $";
  30. #endif /* lint */
  31.  
  32. extern BufferView *current_view;
  33.  
  34. /* Info, used for the Info boxes */
  35.  
  36. InsetInfo::InsetInfo()
  37. {
  38.     form = NULL;
  39. }
  40.  
  41.  
  42. InsetInfo::InsetInfo(LString const & string)
  43.     : contents(string)
  44. {
  45.     form = NULL;
  46. }
  47.  
  48.  
  49. InsetInfo::~InsetInfo()
  50. {
  51.     if (form){
  52.         fl_hide_form(form);
  53.         fl_free_form(form);
  54.         form = NULL;
  55.     }
  56. }
  57.  
  58.  
  59. int InsetInfo::Ascent(LyXFont const &font) const
  60. {
  61.     return font.maxAscent()+1;
  62. }
  63.  
  64.  
  65. int InsetInfo::Descent(LyXFont const &font) const
  66. {
  67.     return font.maxDescent()+1;
  68. }
  69.  
  70.  
  71. int InsetInfo::Width(LyXFont const &font) const
  72. {
  73.     return 6 + font.stringWidth(_("Note"));
  74. }
  75.  
  76.  
  77. void InsetInfo::Draw(LyXFont font, LyXScreen &scr,
  78.              int baseline, float &x)
  79. {
  80.     /* Info-insets are never LaTeX, so just correct the font */
  81.     font.setLatex(LyXFont::OFF);
  82.  
  83.     // Draw as "Note" in a yellow box
  84.     x += 1;
  85.     scr.fillRectangle(gc_note,
  86.               int(x), baseline - Ascent(font)+1,
  87.               Width(font)-2, Ascent(font)+Descent(font)-2);
  88.     scr.drawRectangle(gc_note_frame,
  89.               int(x), baseline- Ascent(font)+1,
  90.               Width(font)-2, Ascent(font)+Descent(font)-2);
  91.     
  92.     scr.drawString(font, _("Note"), baseline, int(x+2));
  93.     x +=  Width(font) - 1;
  94. }
  95.  
  96.  
  97. void InsetInfo::Write(FILE *file)
  98. {
  99.     fprintf(file, "Info %s", contents.c_str());
  100. }
  101.  
  102.  
  103. void InsetInfo::Read(LyXLex &lex)
  104. {
  105.     LString tmp = lex.GetString(); // should be "Info"
  106.     if (tmp != "Info")
  107.         lyxerr.print("ERROR (InsetInfo::Read): "
  108.                   "consistency check 1 failed.");
  109.  
  110.     while (lex.IsOK()) {
  111.         if (!lex.EatLine())
  112.             // blank line in the file being read
  113.             // should we skip blank lines?
  114.             continue;
  115.  
  116.         LString const token = lex.GetString().strip();
  117.         lyxerr.debug("Note: " + token, Error::PARSER);
  118.         
  119.         if (token != "\\end_inset") {
  120.             contents += token + '\n';
  121.         }
  122.         else // token == "\\end_inset"
  123.             break;
  124.     }
  125.     // now remove the last '\n's
  126.     contents.strip('\n');
  127. }
  128.       
  129.  
  130. int InsetInfo::Latex(FILE *, signed char /*fragile*/)
  131. {
  132.     return 0;
  133. }
  134.  
  135.  
  136. int InsetInfo::Latex(LString &, signed char /*fragile*/)
  137. {
  138.     return 0;
  139. }
  140.  
  141.  
  142. unsigned char InsetInfo::Editable() const
  143. {
  144.     return 1;
  145. }
  146.  
  147.  
  148. void InsetInfo::CloseInfoCB(FL_OBJECT *, long data)
  149. {
  150.     InsetInfo *inset = (InsetInfo*) data;
  151. //    inset->contents = fl_get_input(inset->strobj);
  152.     LString tmp = fl_get_input(inset->strobj);
  153.     Buffer *buffer = current_view->currentBuffer();
  154.     if(tmp != inset->contents && !(buffer->isReadonly()) ) {
  155.         buffer->markDirty();
  156.         inset->contents = tmp;
  157.     }
  158.     if (inset->form) {
  159.         fl_hide_form(inset->form);
  160.         fl_free_form(inset->form);
  161.         inset->form = NULL;
  162.     }
  163. }
  164.  
  165.  
  166. void InsetInfo::Edit(int, int)
  167. {
  168.     if(current_view->currentBuffer()->isReadonly())
  169.         WarnReadonly();
  170.     
  171.     if (!form) {
  172.         FL_OBJECT *obj;
  173.         form = fl_bgn_form(FL_UP_BOX,400,180);
  174.         strobj = obj = fl_add_input(FL_MULTILINE_INPUT,10,10,380,120,"");
  175.         fl_set_object_color(obj,FL_MCOL,FL_MCOL);
  176.         fl_set_object_resize(obj, FL_RESIZE_ALL);
  177.         fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
  178.         obj = fl_add_button(FL_NORMAL_BUTTON,130,140,120,30,idex(_("Close|#C^[")));
  179.         fl_set_object_resize(obj, FL_RESIZE_NONE);
  180.         fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
  181.         fl_set_object_callback(obj, CloseInfoCB, (long)this);
  182.         fl_set_object_shortcut(obj, scex(_("Close|#C^[")), (long)this);
  183.         fl_end_form();
  184.         fl_set_form_atclose(form, CancelCloseBoxCB, NULL);
  185.     }
  186.     fl_set_input(strobj, contents.c_str());
  187.     if (form->visible) {
  188.         fl_raise_form(form);
  189.     } else {
  190.         fl_show_form(form,FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, 
  191.                  _("Note"));
  192.     }
  193. }
  194.  
  195.  
  196. Inset* InsetInfo::Clone()
  197. {
  198.     InsetInfo *result = new InsetInfo(contents);
  199.     return result;
  200. }
  201.  
  202.  
  203. Inset::Code InsetInfo::LyxCode() const
  204. {
  205.     return Inset::IGNORE_CODE;
  206. }
  207.