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 / inseterror.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  4KB  |  178 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.  
  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.1.1 1998/04/23 16:02:50 larsbj Exp $    
  25.  
  26. #if !defined(lint) && !defined(WITH_WARNINGS)
  27. static char vcid[] = "$Id: inseterror.C,v 1.1.1.1 1998/04/23 16:02:50 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.stringWidth(_("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. bool InsetError::AutoDelete() const
  127. {
  128.     return true;
  129. }
  130.  
  131.  
  132. unsigned char InsetError::Editable() const
  133. {
  134.     return 1;
  135. }
  136.  
  137.  
  138. void InsetError::CloseErrorCB(FL_OBJECT *, long data)
  139. {
  140.     InsetError *inset = (InsetError*) data;
  141.     if (inset->form) {
  142.         fl_hide_form(inset->form);
  143.         fl_free_form(inset->form);
  144.         inset->form = NULL;
  145.     }
  146. }
  147.  
  148. void InsetError::Edit(int, int)
  149. {
  150.     if (!form) {
  151.         FL_OBJECT *obj;
  152.         form = fl_bgn_form(FL_UP_BOX,400,240);
  153.         strobj = fl_add_box(FL_FRAME_BOX,10,10,380,180,"");
  154.         fl_set_object_color(strobj,FL_MCOL,FL_MCOL);
  155.         fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
  156.         obj = fl_add_button(FL_RETURN_BUTTON,140,200,120,30,_("Close"));
  157.         fl_set_object_callback(obj, CloseErrorCB, (long)this);
  158.         fl_set_object_gravity(obj, FL_South, FL_South);
  159.         fl_set_object_resize(obj, FL_RESIZE_NONE);
  160.         fl_end_form();
  161.         fl_set_form_atclose(form, CancelCloseBoxCB, NULL);
  162.     }
  163.     fl_set_object_label(strobj, contents.c_str());
  164.     if (form->visible) {
  165.         fl_raise_form(form);
  166.     } else {
  167.         fl_show_form(form,FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, 
  168.                  _("LaTeX Error"));
  169.     }
  170. }
  171.  
  172.  
  173. Inset* InsetError::Clone()
  174. {
  175.     InsetError *result = new InsetError(contents);
  176.     return result;
  177. }
  178.