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 / insetindex.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  3KB  |  172 lines

  1. #include <config.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #ifdef __GNUG__
  6. #pragma implementation
  7. #endif
  8.  
  9. #include FORMS_H_LOCATION  
  10. #include "insetindex.h"
  11. #include "buffer.h"
  12. #include "error.h"
  13. #include "LaTeXFeatures.h"
  14. #include "gettext.h"
  15. #include "LString.h"
  16. #include "lyx_gui_misc.h" // WarnReadonly()
  17.  
  18. extern BufferView *current_view;
  19. extern void UpdateInset(Inset* inset, bool mark_dirty = true);
  20.  
  21. struct FD_index_form {
  22.     FL_FORM *index_form;
  23.     FL_OBJECT *key;
  24.     void *vdata;
  25.     long ldata;
  26. };
  27.  
  28. static FD_index_form *index_form=0;
  29.  
  30. static
  31. void index_cb(FL_OBJECT *, long data)
  32. {
  33.     InsetIndex *inset = (InsetIndex*)index_form->vdata;
  34.     
  35.     switch (data) {
  36. // -       case 0: fl_hide_form(index_form->index_form); break;
  37. // -       case 1: 
  38. // -       {
  39. // -               inset->setContents(fl_get_input(index_form->key));
  40. // -               fl_hide_form(index_form->index_form);
  41. // -               UpdateInset(inset);
  42. // -               break;
  43. // -       }
  44.     case 1: // OK
  45.         if(!current_view->currentBuffer()->isReadonly()) {
  46.             LString tmp = fl_get_input(index_form->key);
  47.             if(tmp != inset->getContents())    {
  48.                 inset->setContents(tmp);
  49.                 fl_hide_form(index_form->index_form);
  50.                 UpdateInset(inset);
  51.                 break;
  52.             }
  53.         } // fall through to Cancel on RO
  54.     case 0: // Cancel
  55.         fl_hide_form(index_form->index_form); break;
  56.     }
  57. }
  58.  
  59.  
  60. static
  61. FD_index_form *create_form_index_form()
  62. {
  63.     FL_OBJECT *obj;
  64.     FD_index_form *fdui = (FD_index_form *) fl_calloc(1, sizeof(*fdui));
  65.  
  66.     fdui->index_form = fl_bgn_form(FL_NO_BOX, 258, 196);
  67.     obj = fl_add_box(FL_UP_BOX,0,0,258,196,"");
  68.     fdui->key = obj = fl_add_input(FL_NORMAL_INPUT,93,26,130,30,
  69.                        idex(_("Keyword:|#K")));
  70.       fl_set_object_shortcut(obj,scex(_("Keyword:|#K")),1);
  71.       fl_set_object_lsize(obj,FL_NORMAL_SIZE);
  72.     obj = fl_add_button(FL_RETURN_BUTTON,50,140,80,30,_("OK"));
  73.       obj->u_vdata = index_form;
  74.       fl_set_object_callback(obj,index_cb,1);
  75.     obj = fl_add_button(FL_NORMAL_BUTTON,150,140,80,30,
  76.                 idex(_("Cancel|^[")));
  77.       fl_set_object_shortcut(obj,scex(_("Cancel|^[")),1);
  78.       obj->u_vdata = index_form;
  79.       fl_set_object_callback(obj,index_cb,0);
  80.     fl_end_form();
  81.  
  82.     return fdui;
  83. }
  84.  
  85.  
  86.  
  87. /*---------------------------------------*/
  88.  
  89.  
  90. InsetIndex::InsetIndex(LString const & key)
  91.     : InsetCommand("index", key) 
  92. {
  93. }
  94.  
  95.  
  96. InsetIndex::~InsetIndex()
  97. {
  98.     if(index_form && index_form->index_form
  99.        && index_form->index_form->visible
  100.        && index_form->vdata == this)
  101.         fl_hide_form(index_form->index_form);
  102. }
  103.  
  104.  
  105. void InsetIndex::Edit(int, int)
  106. {
  107.     if(current_view->currentBuffer()->isReadonly())
  108.         WarnReadonly();
  109.  
  110.     if (!index_form)
  111.         index_form = create_form_index_form();
  112.     
  113.     index_form->vdata = this;
  114.     fl_set_input(index_form->key, getContents().c_str());
  115.     if (index_form->index_form->visible) {
  116.         fl_raise_form(index_form->index_form);
  117.     } else {
  118.         fl_show_form(index_form->index_form,
  119.                  FL_PLACE_MOUSE, FL_FULLBORDER,
  120.                  _("Index"));
  121.     }
  122. }
  123.  
  124.  
  125. LString InsetIndex::getScreenLabel() const
  126. {
  127.     LString tmp;
  128.     tmp = _("Index: ");
  129.     tmp+=getContents();
  130.     return tmp;
  131. }
  132.  
  133.  
  134. //
  135. // InsetPrintIndex
  136. //
  137.  
  138. InsetPrintIndex::InsetPrintIndex()
  139.     : InsetCommand("printindex")
  140. {
  141.     owner = NULL;
  142. }
  143.  
  144.  
  145. InsetPrintIndex::InsetPrintIndex(Buffer *o)
  146.     : InsetCommand("printindex"), owner(o)
  147. {
  148. }
  149.  
  150.  
  151. InsetPrintIndex::~InsetPrintIndex()
  152. {
  153. }
  154.  
  155.  
  156. LString InsetPrintIndex::getScreenLabel() const
  157. {
  158.     return _("PrintIndex");
  159. }
  160.  
  161.  
  162. void InsetPrintIndex::Validate(LaTeXFeatures &features) const
  163. {
  164.     features.makeidx = true;
  165. }
  166.  
  167.  
  168. Inset::Code InsetPrintIndex::LyxCode() const
  169. {
  170.      return Inset::INDEX_CODE;
  171. }
  172.