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 / ParagraphExtra.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  15KB  |  327 lines

  1. #include <config.h>
  2.  
  3. #include <stdlib.h>
  4. #include "definitions.h"
  5. #include FORMS_H_LOCATION
  6. #include "layout_forms.h"
  7. #include "LString.h"
  8. #include "minibuffer.h"
  9. #include "vspace.h"
  10. #include "buffer.h"
  11. #include "BufferView.h"
  12. #include "lyxparagraph.h"
  13. #include "gettext.h"
  14. #include "lyxtext.h"
  15.  
  16. //     $Id: ParagraphExtra.C,v 1.1.1.1 1998/04/23 16:02:47 larsbj Exp $    
  17.  
  18. #if !defined(lint) && !defined(WITH_WARNINGS)
  19. static char vcid[] = "$Id: ParagraphExtra.C,v 1.1.1.1 1998/04/23 16:02:47 larsbj Exp $";
  20. #endif /* lint */
  21.  
  22. /* Prototypes */
  23. extern FD_form_paragraph_extra *fd_form_paragraph_extra;
  24. extern MiniBuffer *minibuffer;
  25. extern BufferView *current_view;
  26. extern void BeforeChange();
  27. static bool CheckInputWidth();
  28.  
  29. inline void DeactivateParagraphExtraButtons ()
  30. {
  31.     fl_deactivate_object (fd_form_paragraph_extra->button_ok);
  32.     fl_deactivate_object (fd_form_paragraph_extra->button_apply);
  33.     fl_set_object_lcol (fd_form_paragraph_extra->button_ok, FL_INACTIVE);
  34.     fl_set_object_lcol (fd_form_paragraph_extra->button_apply, FL_INACTIVE);
  35. }
  36.  
  37. inline void ActivateParagraphExtraButtons ()
  38. {
  39.     fl_activate_object (fd_form_paragraph_extra->button_ok);
  40.     fl_activate_object (fd_form_paragraph_extra->button_apply);
  41.     fl_set_object_lcol (fd_form_paragraph_extra->button_ok, FL_BLACK);
  42.     fl_set_object_lcol (fd_form_paragraph_extra->button_apply, FL_BLACK);
  43. }
  44.  
  45. inline void DisableParagraphExtra ()
  46. {
  47.         DeactivateParagraphExtraButtons();
  48.     fl_deactivate_object (fd_form_paragraph_extra->input_pextra_width);
  49.     fl_deactivate_object (fd_form_paragraph_extra->input_pextra_widthp);
  50.     fl_deactivate_object (fd_form_paragraph_extra->group_alignment);
  51.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_top);
  52.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_middle);
  53.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_bottom);
  54.     fl_deactivate_object (fd_form_paragraph_extra->text_warning);
  55.     fl_deactivate_object (fd_form_paragraph_extra->group_extraopt);
  56.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_indent);
  57.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_minipage);
  58.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_floatflt);
  59.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_hfill);
  60.     fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_startmp);
  61. }    
  62.  
  63. inline void EnableParagraphExtra ()
  64. {
  65.         ActivateParagraphExtraButtons();
  66.     fl_activate_object (fd_form_paragraph_extra->input_pextra_width);
  67.     fl_activate_object (fd_form_paragraph_extra->input_pextra_widthp);
  68.     fl_activate_object (fd_form_paragraph_extra->group_alignment);
  69.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_top);
  70.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_middle);
  71.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_bottom);
  72.     fl_activate_object (fd_form_paragraph_extra->text_warning);
  73.     fl_activate_object (fd_form_paragraph_extra->group_extraopt);
  74.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_indent);
  75.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_minipage);
  76.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_floatflt);
  77.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_hfill);
  78.     fl_activate_object (fd_form_paragraph_extra->radio_pextra_startmp);
  79. }    
  80.  
  81. bool UpdateParagraphExtra()
  82. {
  83.     bool update = false;
  84.     if (current_view->getScreen() && current_view->available()) {
  85.         update = true;
  86.         LyXParagraph* par = current_view->currentBuffer()->text->cursor.par;
  87.  
  88.     EnableParagraphExtra();
  89.  
  90.         fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
  91.         fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
  92.         fl_set_input(fd_form_paragraph_extra->input_pextra_width,
  93.                      par->pextra_width.c_str());
  94.         fl_set_input(fd_form_paragraph_extra->input_pextra_widthp,
  95.                      par->pextra_widthp.c_str());
  96.         switch(par->pextra_alignment) {
  97.           case MINIPAGE_ALIGN_TOP:
  98.             fl_set_button(fd_form_paragraph_extra->radio_pextra_top,1);
  99.             break;
  100.           case MINIPAGE_ALIGN_MIDDLE:
  101.             fl_set_button(fd_form_paragraph_extra->radio_pextra_middle,1);
  102.             break;
  103.           case MINIPAGE_ALIGN_BOTTOM:
  104.             fl_set_button(fd_form_paragraph_extra->radio_pextra_bottom,1);
  105.             break;
  106.         }
  107.         fl_set_button(fd_form_paragraph_extra->radio_pextra_hfill,
  108.                       par->pextra_hfill);
  109.         fl_set_button(fd_form_paragraph_extra->radio_pextra_startmp,
  110.                       par->pextra_start_minipage);
  111.         CheckInputWidth();
  112.         if (par->pextra_type == PEXTRA_INDENT) {
  113.             fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,1);
  114.             fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
  115.             fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
  116.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
  117.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
  118.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  119.         } else if (par->pextra_type == PEXTRA_MINIPAGE) {
  120.             fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
  121.             fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,1);
  122.             fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
  123.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
  124.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
  125.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  126.         } else if (par->pextra_type == PEXTRA_FLOATFLT) {
  127.             fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
  128.             fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
  129.             fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,1);
  130.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
  131.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
  132.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  133.         } else {
  134.             fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
  135.             fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
  136.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
  137.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
  138.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
  139.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
  140.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  141.         }
  142.         if (par->pextra_type == PEXTRA_NONE)
  143.             ActivateParagraphExtraButtons();
  144.     }
  145.     fl_hide_object(fd_form_paragraph_extra->text_warning);
  146.  
  147.     if (current_view->currentBuffer()->isReadonly()) {
  148.       DisableParagraphExtra();
  149.       fl_set_object_label(fd_form_paragraph_extra->text_warning,
  150.               _("Document is read-only.  No changes to layout permitted."));
  151.       fl_show_object(fd_form_paragraph_extra->text_warning);
  152.     }
  153.     if (!update && fd_form_paragraph_extra->form_paragraph_extra->visible) {
  154.       fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
  155.     }
  156.     return update;
  157. }
  158.  
  159. void ParagraphExtraOpen(FL_OBJECT *, long)
  160. {
  161.     if (UpdateParagraphExtra()) {
  162.         if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
  163.             fl_raise_form(fd_form_paragraph_extra->form_paragraph_extra);
  164.         } else {
  165.             fl_show_form(fd_form_paragraph_extra->form_paragraph_extra,
  166.                          FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
  167.                          _("ParagraphExtra Layout"));
  168.         }
  169.     }
  170. }
  171.  
  172. void ParagraphExtraApplyCB(FL_OBJECT *, long)
  173. {
  174.     if (current_view->getScreen() && current_view->available()) {
  175.         const FD_form_paragraph_extra* fd = fd_form_paragraph_extra;
  176.         const char
  177.             *width = fl_get_input(fd->input_pextra_width),
  178.             *widthp = fl_get_input(fd->input_pextra_widthp);
  179.         LyXText
  180.             *text = current_view->currentBuffer()->text;
  181.         int
  182.             type = PEXTRA_NONE,
  183.             alignment = 0;
  184.         bool
  185.             hfill = false,
  186.             start_minipage = false;
  187.  
  188.         if (fl_get_button(fd_form_paragraph_extra->radio_pextra_indent)) {
  189.             type = PEXTRA_INDENT;
  190.         } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage)) {
  191.             type = PEXTRA_MINIPAGE;
  192.             hfill = fl_get_button(fd_form_paragraph_extra->radio_pextra_hfill);
  193.             start_minipage =
  194.                 fl_get_button(fd_form_paragraph_extra->radio_pextra_startmp);
  195.             if (fl_get_button(fd_form_paragraph_extra->radio_pextra_top))
  196.                 alignment = MINIPAGE_ALIGN_TOP;
  197.             else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_middle))
  198.                 alignment = MINIPAGE_ALIGN_MIDDLE;
  199.             else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_bottom))
  200.                 alignment = MINIPAGE_ALIGN_BOTTOM;
  201.         } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt)) {
  202.             type = PEXTRA_FLOATFLT;
  203.         }
  204.         text->SetParagraphExtraOpt(type,width,widthp,alignment,hfill,
  205.                                    start_minipage);
  206. //        current_view->redoCurrentBuffer();
  207.     current_view->currentBuffer()->update(1);
  208.     minibuffer->Set(_("ParagraphExtra layout set"));
  209. //    current_view->currentBuffer()->markDirty();
  210.     }
  211.     return;
  212. }
  213.  
  214. void ParagraphExtraCancelCB(FL_OBJECT *, long)
  215. {
  216.     fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
  217. }
  218.  
  219. void ParagraphExtraOKCB(FL_OBJECT *ob, long data)
  220. {
  221.     ParagraphExtraCancelCB(ob,data);
  222.     ParagraphExtraApplyCB(ob,data);
  223. }
  224.  
  225. void CheckPExtraOptCB(FL_OBJECT *ob, long)
  226. {
  227.     int
  228.         n;
  229.     LString
  230.         s1, s2;
  231.     
  232.     ActivateParagraphExtraButtons();
  233.     CheckInputWidth();
  234.     if (ob == fd_form_paragraph_extra->radio_pextra_indent) {
  235.         n = fl_get_button(fd_form_paragraph_extra->radio_pextra_indent);
  236.         if (n) {
  237.             fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
  238.             fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
  239.             fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
  240.             fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
  241.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
  242.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
  243.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  244.         } else {
  245.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
  246.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
  247.             ActivateParagraphExtraButtons();
  248.         }
  249.     } else if (ob == fd_form_paragraph_extra->radio_pextra_minipage) {
  250.         n = fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage);
  251.         if (n) {
  252.             fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
  253.             fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
  254.             fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
  255.             fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
  256.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
  257.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
  258.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  259.         } else {
  260.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
  261.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
  262.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
  263.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
  264.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  265.             ActivateParagraphExtraButtons();
  266.         }
  267.     } else if (ob == fd_form_paragraph_extra->radio_pextra_floatflt) {
  268.         n = fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt);
  269.         if (n) {
  270.             fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
  271.             fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
  272.             fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
  273.             fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
  274.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
  275.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
  276.             fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  277.         } else {
  278.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
  279.             fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
  280.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
  281.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
  282.             fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
  283.             ActivateParagraphExtraButtons();
  284.         }
  285.     }
  286.     return;
  287. }
  288.  
  289. static bool CheckInputWidth()
  290. {
  291.     LString
  292.         s1,s2;
  293.  
  294.     s1 = fl_get_input(fd_form_paragraph_extra->input_pextra_width);
  295.     s2 = fl_get_input(fd_form_paragraph_extra->input_pextra_widthp);
  296.     if (s1.empty() && s2.empty()) {
  297.         fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
  298.         fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
  299.         fl_hide_object(fd_form_paragraph_extra->text_warning);
  300.         DeactivateParagraphExtraButtons();
  301.         return false;
  302.     }
  303.     if (!s1.empty()) { // LyXLength parameter
  304.         fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
  305.         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
  306.         if (!isValidLength(s1)) {
  307.             DeactivateParagraphExtraButtons();
  308.             fl_set_object_label(fd_form_paragraph_extra->text_warning,
  309.                                 _("Warning: Invalid Length (valid example: 10mm)"));
  310.             fl_show_object(fd_form_paragraph_extra->text_warning);
  311.             return false;
  312.         }
  313.     } else { // !s2.empty() % parameter
  314.         fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
  315.         fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
  316.         if ((atoi(s2.c_str()) < 0 ) || (atoi(s2.c_str()) > 100)) {
  317.             DeactivateParagraphExtraButtons();
  318.             fl_set_object_label(fd_form_paragraph_extra->text_warning,
  319.                                 _("Warning: Invalid percent value (0-100)"));
  320.             fl_show_object(fd_form_paragraph_extra->text_warning);
  321.             return false;
  322.         }
  323.     }
  324.     fl_hide_object(fd_form_paragraph_extra->text_warning);
  325.     return true;
  326. }
  327.