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 / TableLayout.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  18KB  |  412 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 "lyx_main.h"
  8. #include "lyxrc.h"
  9. #include "LString.h"
  10. #include "filetools.h"
  11. #include "buffer.h"
  12. #include "vspace.h"
  13. #include "lyx_gui_misc.h"
  14. #include "BufferView.h"
  15. #include "lyxscreen.h"
  16. #include "gettext.h"
  17. #include "lyxtext.h"
  18.  
  19. //     $Id: TableLayout.C,v 1.1.1.1 1998/04/23 16:02:48 larsbj Exp $    
  20.  
  21. #if !defined(lint) && !defined(WITH_WARNINGS)
  22. static char vcid[] = "$Id: TableLayout.C,v 1.1.1.1 1998/04/23 16:02:48 larsbj Exp $";
  23. #endif /* lint */
  24.  
  25. extern void BeforeChange();
  26.  
  27. /* Prototypes */
  28. extern FD_form_table_options *fd_form_table_options;
  29. extern BufferView *current_view;
  30.  
  31. static int
  32.     Confirmed = false,
  33.     ActCell;
  34.  
  35. bool UpdateLayoutTable(int flag)
  36. {
  37.     bool update = true;
  38.     if (!current_view->getScreen() || !current_view->available())
  39.         update = false;
  40.     
  41.     if (update && current_view->currentBuffer()->text->cursor.par->table) {
  42.         int
  43.             align,
  44.             cell,
  45.             column,row;
  46.         char
  47.             buf[12];
  48.         LString
  49.             pwidth;
  50.     
  51.         LyXTable *table = current_view->currentBuffer()->text->cursor.par->table;
  52.  
  53.         cell = current_view->currentBuffer()->text->
  54.             NumberOfCell(current_view->currentBuffer()->text->cursor.par, 
  55.                          current_view->currentBuffer()->text->cursor.pos);
  56.         ActCell = cell;
  57.         column = table->column_of_cell(cell)+1;
  58.         fl_set_object_label(fd_form_table_options->text_warning,"");
  59.         Confirmed = false;
  60.         sprintf(buf,"%d",column);
  61.         fl_set_input(fd_form_table_options->input_table_column, buf);
  62.         fl_deactivate_object(fd_form_table_options->input_table_column);
  63.         row = table->row_of_cell(cell)+1;
  64.         sprintf(buf,"%d",row);
  65.         fl_set_input(fd_form_table_options->input_table_row, buf);
  66.         fl_deactivate_object(fd_form_table_options->input_table_row);
  67.         if (table->IsMultiColumn(cell))
  68.             fl_set_button(fd_form_table_options->radio_multicolumn, 1);
  69.         else
  70.             fl_set_button(fd_form_table_options->radio_multicolumn, 0);
  71.         if (table->RotateCell(cell))
  72.             fl_set_button(fd_form_table_options->radio_rotate_cell, 1);
  73.         else
  74.             fl_set_button(fd_form_table_options->radio_rotate_cell, 0);
  75.         if (table->TopLine(cell))
  76.             fl_set_button(fd_form_table_options->radio_border_top, 1);
  77.         else
  78.             fl_set_button(fd_form_table_options->radio_border_top, 0);
  79.         if (table->BottomLine(cell))
  80.             fl_set_button(fd_form_table_options->radio_border_bottom, 1);
  81.         else
  82.             fl_set_button(fd_form_table_options->radio_border_bottom, 0);
  83.         if (table->LeftLine(cell))
  84.             fl_set_button(fd_form_table_options->radio_border_left, 1);
  85.         else
  86.             fl_set_button(fd_form_table_options->radio_border_left, 0);
  87.         if (table->RightLine(cell))
  88.             fl_set_button(fd_form_table_options->radio_border_right, 1);
  89.         else
  90.             fl_set_button(fd_form_table_options->radio_border_right, 0);
  91.         align = table->GetAlignment(cell);
  92.         fl_set_button(fd_form_table_options->radio_align_left, 0);
  93.         fl_set_button(fd_form_table_options->radio_align_right, 0);
  94.         fl_set_button(fd_form_table_options->radio_align_center, 0);
  95.         pwidth = table->GetPWidth(cell);
  96.         if (flag)
  97.             fl_set_input(fd_form_table_options->input_column_width,pwidth.c_str());
  98.         if (current_view->currentBuffer()->isReadonly()) 
  99.             fl_deactivate_object(fd_form_table_options->input_column_width);
  100.         if (!pwidth.empty()) {
  101.             fl_activate_object(fd_form_table_options->radio_linebreak_cell);
  102.         fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
  103.                    FL_BLACK);
  104.             fl_set_button(fd_form_table_options->radio_linebreak_cell,
  105.                           table->Linebreaks(table->FirstVirtualCell(cell)));
  106.         } else {
  107.             fl_deactivate_object(fd_form_table_options->radio_linebreak_cell);
  108.         fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell,
  109.                    FL_INACTIVE);
  110.             fl_set_button(fd_form_table_options->radio_linebreak_cell,0);
  111.         }
  112.         if ((!pwidth.empty() && !table->IsMultiColumn(cell)) ||
  113.             (align == LYX_ALIGN_LEFT))
  114.             fl_set_button(fd_form_table_options->radio_align_left, 1);
  115.         else if (align == LYX_ALIGN_RIGHT)
  116.             fl_set_button(fd_form_table_options->radio_align_right, 1);
  117.         else
  118.             fl_set_button(fd_form_table_options->radio_align_center, 1);
  119.         if (!pwidth.empty() && !table->IsMultiColumn(cell)) {
  120.             fl_deactivate_object(fd_form_table_options->radio_align_left);
  121.             fl_deactivate_object(fd_form_table_options->radio_align_right);
  122.             fl_deactivate_object(fd_form_table_options->radio_align_center);
  123.         fl_set_object_lcol(fd_form_table_options->radio_align_left,
  124.                    FL_INACTIVE);
  125.         fl_set_object_lcol(fd_form_table_options->radio_align_right,
  126.                    FL_INACTIVE);
  127.         fl_set_object_lcol(fd_form_table_options->radio_align_center,
  128.                    FL_INACTIVE);
  129.         } else {
  130.             fl_activate_object(fd_form_table_options->radio_align_left);
  131.             fl_activate_object(fd_form_table_options->radio_align_right);
  132.             fl_activate_object(fd_form_table_options->radio_align_center);
  133.         fl_set_object_lcol(fd_form_table_options->radio_align_left,
  134.                    FL_BLACK);
  135.         fl_set_object_lcol(fd_form_table_options->radio_align_right,
  136.                    FL_BLACK);
  137.         fl_set_object_lcol(fd_form_table_options->radio_align_center,
  138.                    FL_BLACK);
  139.         }
  140.         fl_set_button(fd_form_table_options->radio_longtable,table->IsLongTable());
  141.         if (table->IsLongTable()) {
  142.             fl_activate_object(fd_form_table_options->radio_lt_firsthead);
  143.             fl_activate_object(fd_form_table_options->radio_lt_head);
  144.             fl_activate_object(fd_form_table_options->radio_lt_foot);
  145.             fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
  146.             fl_activate_object(fd_form_table_options->radio_lt_newpage);
  147.         fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
  148.                    FL_BLACK);
  149.         fl_set_object_lcol(fd_form_table_options->radio_lt_head,
  150.                    FL_BLACK);
  151.         fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
  152.                    FL_BLACK);
  153.         fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
  154.                    FL_BLACK);
  155.         fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
  156.                    FL_BLACK);
  157.             fl_set_button(fd_form_table_options->radio_lt_firsthead,
  158.                           table->RowOfLTFirstHead(cell));
  159.             fl_set_button(fd_form_table_options->radio_lt_head,
  160.                           table->RowOfLTHead(cell));
  161.             fl_set_button(fd_form_table_options->radio_lt_foot,
  162.                           table->RowOfLTFoot(cell));
  163.             fl_set_button(fd_form_table_options->radio_lt_lastfoot,
  164.                           table->RowOfLTLastFoot(cell));
  165.             fl_set_button(fd_form_table_options->radio_lt_newpage,
  166.                           table->LTNewPage(cell));
  167.         } else {
  168.             fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
  169.             fl_deactivate_object(fd_form_table_options->radio_lt_head);
  170.             fl_deactivate_object(fd_form_table_options->radio_lt_foot);
  171.             fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
  172.             fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
  173.             fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
  174.             fl_set_button(fd_form_table_options->radio_lt_head,0);
  175.             fl_set_button(fd_form_table_options->radio_lt_foot,0);
  176.             fl_set_button(fd_form_table_options->radio_lt_lastfoot,0);
  177.             fl_set_button(fd_form_table_options->radio_lt_newpage,0);
  178.         fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
  179.                    FL_INACTIVE);
  180.         fl_set_object_lcol(fd_form_table_options->radio_lt_head,
  181.                    FL_INACTIVE);
  182.         fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
  183.                    FL_INACTIVE);
  184.         fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
  185.                    FL_INACTIVE);
  186.         fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
  187.                    FL_INACTIVE);
  188.         }
  189.         fl_set_button(fd_form_table_options->radio_rotate_table,table->RotateTable());
  190.     } else if (fd_form_table_options->form_table_options->visible) {
  191.         fl_hide_form(fd_form_table_options->form_table_options);
  192.     }
  193.     return update;
  194. }
  195.  
  196. void MenuLayoutTable(int flag)
  197. {
  198.     if (UpdateLayoutTable(flag)) {
  199.         if (fd_form_table_options->form_table_options->visible) {
  200.             fl_raise_form(fd_form_table_options->form_table_options);
  201.         }
  202.         else {
  203.             fl_show_form(fd_form_table_options->form_table_options,
  204.                          FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
  205.                          _("Table Layout"));
  206.         }
  207.     }
  208. }
  209.  
  210. void TableOptionsCB(FL_OBJECT *ob, long)
  211. {
  212.     LyXTable
  213.         *table = 0;
  214.     int
  215.         cell,
  216.         s,
  217.         num = 0;
  218.     LString
  219.         str;
  220.  
  221.     if (!current_view->available()
  222.     ||
  223.     !(table = current_view->currentBuffer()->text->cursor.par->table)) 
  224.       {
  225.         MenuLayoutTable(0);
  226.     return;
  227.       }
  228.     cell = current_view->currentBuffer()->text->
  229.         NumberOfCell(current_view->currentBuffer()->text->cursor.par, 
  230.                      current_view->currentBuffer()->text->cursor.pos);
  231.     if (ActCell != cell) {
  232.         MenuLayoutTable(0);
  233.         fl_set_object_label(fd_form_table_options->text_warning,
  234.                             _("Warning: Wrong Cursor position, updated window"));
  235.         fl_show_object(fd_form_table_options->text_warning);
  236.         return;
  237.     }
  238.     // No point in processing directives that you can't do anything with
  239.     // anyhow, so exit now if the buffer is read-only.
  240.     if (current_view->currentBuffer()->isReadonly()) {
  241.       MenuLayoutTable(0);
  242.       return;
  243.     }
  244.     
  245.     if (ob != fd_form_table_options->button_table_delete) {
  246.         fl_set_object_label(fd_form_table_options->text_warning,"");
  247.         Confirmed = false;
  248.     }
  249.     str = fl_get_input(fd_form_table_options->input_column_width);
  250.     if (!str.empty() && !isValidLength(str)) {
  251.         fl_set_object_label(fd_form_table_options->text_warning,
  252.                             _("Warning: Invalid Length (valid example: 10mm)"));
  253.         fl_show_object(fd_form_table_options->text_warning);
  254.         return;
  255.     }
  256.     if (((ob==fd_form_table_options->button_delete_row) && (table->rows<=1)) ||
  257.         ((ob==fd_form_table_options->button_delete_column) && (table->columns<=1)))
  258.         ob = fd_form_table_options->button_table_delete;
  259.     if (ob == fd_form_table_options->button_append_row)
  260.         num = LyXTable::APPEND_ROW;
  261.     else if (ob == fd_form_table_options->button_append_column)
  262.         num = LyXTable::APPEND_COLUMN;
  263.     else if (ob == fd_form_table_options->button_delete_row)
  264.         num = LyXTable::DELETE_ROW;
  265.     else if (ob == fd_form_table_options->button_delete_column)
  266.         num = LyXTable::DELETE_COLUMN;
  267.     else if (ob == fd_form_table_options->button_set_borders)
  268.         num = LyXTable::SET_ALL_LINES;
  269.     else if (ob == fd_form_table_options->button_unset_borders)
  270.         num = LyXTable::UNSET_ALL_LINES;
  271.     else if (ob == fd_form_table_options->radio_border_top)
  272.         num = LyXTable::TOGGLE_LINE_TOP;
  273.     else if (ob == fd_form_table_options->radio_border_bottom)
  274.         num = LyXTable::TOGGLE_LINE_BOTTOM;
  275.     else if (ob == fd_form_table_options->radio_border_left)
  276.         num = LyXTable::TOGGLE_LINE_LEFT;
  277.     else if (ob == fd_form_table_options->radio_border_right)
  278.         num = LyXTable::TOGGLE_LINE_RIGHT;
  279.     else if (ob == fd_form_table_options->radio_align_left)
  280.         num = LyXTable::ALIGN_LEFT;
  281.     else if (ob == fd_form_table_options->radio_align_right)
  282.         num = LyXTable::ALIGN_RIGHT;
  283.     else if (ob == fd_form_table_options->radio_align_center)
  284.         num = LyXTable::ALIGN_CENTER;
  285.     else if ((ob==fd_form_table_options->button_table_delete) && !Confirmed) {
  286.         fl_set_object_label(fd_form_table_options->text_warning,
  287.                             _("Confirm: press Delete-Button again"));
  288.         Confirmed = true;
  289.         return;
  290.     } else if ((ob == fd_form_table_options->button_table_delete) 
  291.            && Confirmed) {
  292.         num = LyXTable::DELETE_TABLE;
  293.         Confirmed = false;
  294.     } else if (ob == fd_form_table_options->radio_multicolumn)
  295.         num = LyXTable::MULTICOLUMN;
  296.     else if (ob == fd_form_table_options->radio_longtable) {
  297.         s=fl_get_button(fd_form_table_options->radio_longtable);
  298.         if (s) {
  299.             num = LyXTable::SET_LONGTABLE;
  300.             fl_activate_object(fd_form_table_options->radio_lt_firsthead);
  301.             fl_activate_object(fd_form_table_options->radio_lt_head);
  302.             fl_activate_object(fd_form_table_options->radio_lt_foot);
  303.             fl_activate_object(fd_form_table_options->radio_lt_lastfoot);
  304.             fl_activate_object(fd_form_table_options->radio_lt_newpage);
  305.             fl_set_button(fd_form_table_options->radio_lt_firsthead,
  306.                           table->RowOfLTFirstHead(cell));
  307.             fl_set_button(fd_form_table_options->radio_lt_head,
  308.                           table->RowOfLTHead(cell));
  309.             fl_set_button(fd_form_table_options->radio_lt_foot,
  310.                           table->RowOfLTFoot(cell));
  311.             fl_set_button(fd_form_table_options->radio_lt_lastfoot,
  312.                           table->RowOfLTLastFoot(cell));
  313.             fl_set_button(fd_form_table_options->radio_lt_firsthead,
  314.                           table->LTNewPage(cell));
  315.         } else {
  316.         num = LyXTable::UNSET_LONGTABLE;
  317.             fl_deactivate_object(fd_form_table_options->radio_lt_firsthead);
  318.             fl_deactivate_object(fd_form_table_options->radio_lt_head);
  319.             fl_deactivate_object(fd_form_table_options->radio_lt_foot);
  320.             fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot);
  321.             fl_deactivate_object(fd_form_table_options->radio_lt_newpage);
  322.             fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
  323.             fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
  324.             fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
  325.             fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
  326.             fl_set_button(fd_form_table_options->radio_lt_firsthead,0);
  327.         fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead,
  328.                    FL_INACTIVE);
  329.         fl_set_object_lcol(fd_form_table_options->radio_lt_head,
  330.                    FL_INACTIVE);
  331.         fl_set_object_lcol(fd_form_table_options->radio_lt_foot,
  332.                    FL_INACTIVE);
  333.         fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot,
  334.                    FL_INACTIVE);
  335.         fl_set_object_lcol(fd_form_table_options->radio_lt_newpage,
  336.                    FL_INACTIVE);
  337.         }
  338.     } else if (ob == fd_form_table_options->radio_rotate_table) {
  339.         s=fl_get_button(fd_form_table_options->radio_rotate_table);
  340.     if (s)
  341.             num = LyXTable::SET_ROTATE_TABLE;
  342.     else
  343.         num = LyXTable::UNSET_ROTATE_TABLE;
  344.     } else if (ob == fd_form_table_options->radio_rotate_cell) {
  345.         s=fl_get_button(fd_form_table_options->radio_rotate_cell);
  346.     if (s)
  347.             num = LyXTable::SET_ROTATE_CELL;
  348.     else
  349.         num = LyXTable::UNSET_ROTATE_CELL;
  350.     } else if (ob == fd_form_table_options->radio_linebreak_cell) {
  351.         num = LyXTable::SET_LINEBREAKS;
  352.     } else if (ob == fd_form_table_options->radio_lt_firsthead) {
  353.         num = LyXTable::SET_LTFIRSTHEAD;
  354.     } else if (ob == fd_form_table_options->radio_lt_head) {
  355.         num = LyXTable::SET_LTHEAD;
  356.     } else if (ob == fd_form_table_options->radio_lt_foot) {
  357.         num = LyXTable::SET_LTFOOT;
  358.     } else if (ob == fd_form_table_options->radio_lt_lastfoot) {
  359.         num = LyXTable::SET_LTLASTFOOT;
  360.     } else if (ob == fd_form_table_options->radio_lt_newpage) {
  361.         num = LyXTable::SET_LTNEWPAGE;
  362.     } else
  363.         return;
  364.     if (current_view->available()){
  365.         current_view->getScreen()->HideCursor();
  366.         if (!current_view->currentBuffer()->text->selection){
  367.             BeforeChange(); 
  368.             current_view->currentBuffer()->update(-2);
  369.         }
  370.         current_view->currentBuffer()->text->TableFeatures(num);
  371.         current_view->currentBuffer()->update(1);
  372.     }
  373.     if (num == LyXTable::DELETE_TABLE)
  374.         fl_hide_form(fd_form_table_options->form_table_options);
  375.     else
  376.         UpdateLayoutTable(true);
  377.     return;
  378. }
  379.  
  380. void TableOptCloseCB(FL_OBJECT *, long)
  381. {
  382.     fl_hide_form(fd_form_table_options->form_table_options);
  383.     return;
  384. }
  385.  
  386. void SetPWidthCB(FL_OBJECT *ob, long)
  387. {
  388.     fl_set_object_label(fd_form_table_options->text_warning,"");
  389.     Confirmed = false;
  390.     if (ob == fd_form_table_options->input_column_width) {
  391.         LString
  392.             str;
  393.         str = fl_get_input(ob);
  394.         if (!str.empty() && !isValidLength(str)) {
  395.             fl_set_object_label(fd_form_table_options->text_warning,
  396.                             _("Warning: Invalid Length (valid example: 10mm)"));
  397.             fl_show_object(fd_form_table_options->text_warning);
  398.             return;
  399.         }
  400.         if (current_view->available()){
  401.             current_view->getScreen()->HideCursor();
  402.             if (!current_view->currentBuffer()->text->selection){
  403.                 BeforeChange(); 
  404.                 current_view->currentBuffer()->update(-2);
  405.             }
  406.             current_view->currentBuffer()->text->TableFeatures(LyXTable::SET_PWIDTH,str);
  407.             current_view->currentBuffer()->update(1);
  408.         }
  409.         MenuLayoutTable(0); // update for alignment
  410.     }
  411. }
  412.