Just some changes to be able to change TabularFeatures with the Table menu

so that I can test the stuff.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@724 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2000-05-05 14:45:59 +00:00
parent 4c7916d1cd
commit ba08201457
4 changed files with 152 additions and 206 deletions

View File

@ -1,3 +1,13 @@
2000-05-05 Juergen Vigna <jug@sad.it>
* src/insets/insettabular.C (UpdateLocal): resetCursorPos when
recalculating inset-widths.
(TabularFeatures): activated this function so that I can change
tabular-features via menu.
* src/menus.C (ShowEditMenu): inserted support for insettabular so
that I can test some functions with the Table menu.
2000-05-05 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/lyxfont.C (stateText): guard against stupid c++libs.

View File

@ -27,6 +27,7 @@
#include "Painter.h"
#include "font.h"
#include "lyxtext.h"
#include "lyx_gui_misc.h"
#include "insets/insettext.h"
const int ADD_TO_HEIGHT = 2;
@ -252,8 +253,10 @@ void InsetTabular::InsetUnlock(BufferView * bv)
void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
{
if (flag)
if (flag) {
calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
resetPos(bv->painter());
}
bv->updateInset(this, flag);
}
@ -792,9 +795,8 @@ void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
}
void InsetTabular::TabularFeatures(int, string)
void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
{
#if 0
int
i,
sel_pos_start,
@ -838,183 +840,62 @@ void InsetTabular::TabularFeatures(int, string)
break;
case LyXTabular::APPEND_ROW:
{
int
pos = cursor.pos,
cell_org = actcell,
cell = actcell;
// if there is a ContRow following this row I have to add
// the row after the ContRow's
if ((pos < par->last()) && tabular->RowHasContRow(cell_org)) {
while((pos < par->last()) && !tabular->IsContRow(cell)) {
while (pos < par->last() && !par->IsNewline(pos))
++pos;
if (pos < par->last())
++pos;
++cell;
}
while((pos < par->last()) && tabular->IsContRow(cell)) {
while (pos < par->last() && !par->IsNewline(pos))
++pos;
if (pos < par->last())
++pos;
++cell;
}
cell_org = --cell;
if (pos < par->last())
--pos;
}
while ((pos < par->last()) &&
((cell == cell_org) || !tabular->IsFirstCell(cell))) {
while ((pos < par->last()) && !par->IsNewline(pos))
++pos;
if (pos < par->last())
++pos;
++cell;
}
// insert the new cells
int number = tabular->NumberOfCellsInRow(cell_org);
for (i=0; i<number; ++i)
par->InsertChar(pos, LYX_META_NEWLINE);
// append the row into the tabular
tabular->AppendRow(cell_org);
calculate_width_of_cells();
UpdateLocal();
return;
}
case LyXTabular::APPEND_CONT_ROW:
{
int
pos = cursor.pos,
cell_org = actcell,
cell = actcell;
// if there is already a controw but not for this cell
// the AppendContRow sets only the right values but does
// not actually add a row
if (tabular->RowHasContRow(cell_org) &&
(tabular->CellHasContRow(cell_org) < 0)) {
tabular->AppendContRow(cell_org);
calculate_width_of_cells();
UpdateLocal();
return;
}
while ((pos < par->last()) &&
((cell == cell_org) || !tabular->IsFirstCell(cell))) {
while (pos < par->last() && !par->IsNewline(pos))
++pos;
if (pos < par->last())
++pos;
++cell;
}
// insert the new cells
int number = tabular->NumberOfCellsInRow(cell_org);
for (i=0; i<number; ++i)
par->InsertChar(pos, LYX_META_NEWLINE);
// append the row into the tabular
tabular->AppendContRow(cell_org);
calculate_width_of_cells();
UpdateLocal();
tabular->AppendRow(actcell);
UpdateLocal(bv, true);
return;
}
case LyXTabular::APPEND_COLUMN:
{
int
pos = 0,
cell_org = actcell,
cell = 0;
do {
if (pos && (par->IsNewline(pos-1))) {
if (tabular->AppendCellAfterCell(cell_org, cell)) {
par->InsertChar(pos, LYX_META_NEWLINE);
if (pos <= cursor.pos)
++cursor.pos;
++pos;
}
++cell;
}
++pos;
} while (pos <= par->last());
// remember that the very last cell doesn't end with a newline.
// This saves one byte memory per tabular ;-)
if (tabular->AppendCellAfterCell(cell_org, cell))
par->InsertChar(par->last(), LYX_META_NEWLINE);
// append the column into the tabular
tabular->AppendColumn(cell_org);
calculate_width_of_cells();
UpdateLocal();
tabular->AppendColumn(actcell);
UpdateLocal(bv, true);
return;
}
case LyXTabular::DELETE_ROW:
RemoveTabularRow();
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
case LyXTabular::DELETE_COLUMN:
{
int pos = 0;
int cell = 0;
do {
if (!pos || (par->IsNewline(pos-1))){
if (tabular->DeleteCellIfColumnIsDeleted(cell, actcell)) {
// delete one cell
while (pos < par->last() && !par->IsNewline(pos))
par->Erase(pos);
if (pos < par->last())
par->Erase(pos);
else
par->Erase(pos - 1); // the missing newline
// at the end of a tabular
--pos; // because of ++pos below
}
++cell;
}
++pos;
} while (pos <= par->last());
/* delete the column from the tabular */
tabular->DeleteColumn(actcell);
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
}
case LyXTabular::TOGGLE_LINE_TOP:
lineSet = !tabular->TopLine(actcell);
for(i=sel_pos_start; i<=sel_pos_end; ++i)
tabular->SetTopLine(i,lineSet);
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
case LyXTabular::TOGGLE_LINE_BOTTOM:
lineSet = !tabular->BottomLine(actcell);
for(i=sel_pos_start; i<=sel_pos_end; ++i)
tabular->SetBottomLine(i,lineSet);
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
case LyXTabular::TOGGLE_LINE_LEFT:
lineSet = !tabular->LeftLine(actcell);
for(i=sel_pos_start; i<=sel_pos_end; ++i)
tabular->SetLeftLine(i,lineSet);
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
case LyXTabular::TOGGLE_LINE_RIGHT:
lineSet = !tabular->RightLine(actcell);
for(i=sel_pos_start; i<=sel_pos_end; ++i)
tabular->SetRightLine(i,lineSet);
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
case LyXTabular::ALIGN_LEFT:
case LyXTabular::ALIGN_RIGHT:
case LyXTabular::ALIGN_CENTER:
for(i=sel_pos_start; i<=sel_pos_end; ++i)
tabular->SetAlignment(i,setAlign);
UpdateLocal();
UpdateLocal(bv, true);
return;
case LyXTabular::MULTICOLUMN:
{
@ -1029,26 +910,17 @@ void InsetTabular::TabularFeatures(int, string)
if (!hasCellSelection()) {
// check wether we are completly in a multicol
if (tabular->IsMultiColumn(actcell)) {
int
newlines,
pos = cursor.pos;
if ((newlines=tabular->UnsetMultiColumn(actcell))) {
while ((pos < par->last()) && !par->IsNewline(pos))
++pos;
for (;newlines;--newlines)
par->InsertChar(pos, LYX_META_NEWLINE);
}
calculate_width_of_cells();
tabular->UnsetMultiColumn(actcell);
UpdateLocal(bv, true);
} else {
tabular->SetMultiColumn(actcell, 1);
UpdateLocal(bv, false);
}
UpdateLocal();
return;
}
// we have a selection so this means we just add all this
// cells to form a multicolumn cell
int
number = 1,
s_start, s_end;
if (sel_pos_start > sel_pos_end) {
@ -1058,23 +930,10 @@ void InsetTabular::TabularFeatures(int, string)
s_start = sel_pos_start;
s_end = sel_pos_end;
}
for(i=s_start; i < s_end; ++i) {
if (par->IsNewline(i)) {
par->Erase(i);
// check for double-blanks
if ((i && !par->IsLineSeparator(i-1)) &&
(i < par->last()) && !par->IsLineSeparator(i))
par->InsertChar(i, ' ');
else
--i;
++number;
}
}
tabular->SetMultiColumn(sel_pos_start,number);
tabular->SetMultiColumn(s_start, s_end);
cursor.pos = s_start;
sel_cell_end = sel_cell_start;
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
}
case LyXTabular::SET_ALL_LINES:
@ -1082,16 +941,15 @@ void InsetTabular::TabularFeatures(int, string)
case LyXTabular::UNSET_ALL_LINES:
for(i=sel_pos_start; i<=sel_pos_end; ++i)
tabular->SetAllLines(i, setLines);
calculate_width_of_cells();
UpdateLocal();
UpdateLocal(bv, true);
return;
case LyXTabular::SET_LONGTABULAR:
tabular->SetLongTabular(true);
UpdateLocal(); // because this toggles displayed
UpdateLocal(bv, true); // because this toggles displayed
return;
case LyXTabular::UNSET_LONGTABULAR:
tabular->SetLongTabular(false);
UpdateLocal(); // because this toggles displayed
UpdateLocal(bv, true); // because this toggles displayed
return;
case LyXTabular::SET_ROTATE_TABULAR:
tabular->SetRotateTabular(true);
@ -1108,7 +966,7 @@ void InsetTabular::TabularFeatures(int, string)
tabular->SetRotateCell(i,false);
return;
case LyXTabular::SET_LINEBREAKS:
what = !tabular->Linebreaks(tabular->FirstVirtualCell(actcell));
what = !tabular->GetLinebreaks(actcell);
for(i=sel_pos_start; i<=sel_pos_end; ++i)
tabular->SetLinebreaks(i,what);
return;
@ -1125,11 +983,10 @@ void InsetTabular::TabularFeatures(int, string)
tabular->SetLTFoot(actcell,true);
return;
case LyXTabular::SET_LTNEWPAGE:
what = !tabular->LTNewPage(actcell);
what = !tabular->GetLTNewPage(actcell);
tabular->SetLTNewPage(actcell,what);
return;
}
#endif
}
void InsetTabular::RemoveTabularRow()

View File

@ -126,7 +126,7 @@ public:
///
void ToggleInsetCursor(BufferView *);
///
void TabularFeatures(int feature, string val="");
void TabularFeatures(BufferView * bv, int feature, string val="");
///
int GetActCell() { return actcell; }
///

View File

@ -46,6 +46,8 @@
#include "layout.h"
#include "lyx_cb.h"
#include "bufferview_funcs.h"
#include "insets/insettabular.h"
#include "tabular.h"
using std::vector;
using std::endl;
@ -860,11 +862,11 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
if (men->currentView()->available() &&
men->currentView()->text->cursor.par->table &&
!tmpbuffer->isReadonly()){
LyXTable *table = men->currentView()->text->cursor.par->table;
fl_addtopup(SubEditTable, _("Table%t"));
if (men->currentView()->text->cursor.par->table->
IsMultiColumn(men->currentView()->text->
if (table->IsMultiColumn(men->currentView()->text->
NumberOfCell(men->currentView()->
text->cursor.par,
men->currentView()->
@ -874,8 +876,7 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
if (men->currentView()->text->cursor.par->table->
TopLine(men->currentView()->text->
if (table->TopLine(men->currentView()->text->
NumberOfCell(men->currentView()->
text->cursor.par,
men->currentView()->text->
@ -885,8 +886,7 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
if (men->currentView()->text->cursor.par->table->
BottomLine(men->currentView()->text->
if (table->BottomLine(men->currentView()->text->
NumberOfCell(men->currentView()->
text->cursor.par,
men->currentView()->
@ -896,8 +896,7 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
if (men->currentView()->text->cursor.par->table->
LeftLine(men->currentView()->text->
if (table->LeftLine(men->currentView()->text->
NumberOfCell(men->currentView()->
text->cursor.par,
men->currentView()->
@ -907,8 +906,7 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
if (men->currentView()->text->cursor.par->table->
RightLine(men->currentView()->text->
if (table->RightLine(men->currentView()->text->
NumberOfCell(men->currentView()->
text->cursor.par,
men->currentView()->
@ -918,7 +916,7 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
int align = men->currentView()->text->cursor.par->
int align =
table->GetAlignment(men->currentView()->text->
NumberOfCell(men->currentView()->
text->cursor.par,
@ -957,8 +955,80 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
// xgettext:no-c-format
fl_addtopup(SubEditTable, _("|Delete Table%x43"));
fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
}
else {
} else if (men->currentView()->the_locking_inset &&
(men->currentView()->the_locking_inset->LyxCode() ==
Inset::TABULAR_CODE) &&
!tmpbuffer->isReadonly()) {
InsetTabular * inset = static_cast<InsetTabular *>(men->currentView()->the_locking_inset);
LyXTabular * table = inset->tabular;
fl_addtopup(SubEditTable, _("Table%t"));
if (table->IsMultiColumn(inset->GetActCell()))
fl_addtopup(SubEditTable, _("|Multicolumn%B%x44%l"));
else
fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
if (table->TopLine(inset->GetActCell()))
fl_addtopup(SubEditTable, _("|Line Top%B%x36"));
else
fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
if (table->BottomLine(inset->GetActCell()))
fl_addtopup(SubEditTable, _("|Line Bottom%B%x37"));
else
fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
if (table->LeftLine(inset->GetActCell()))
fl_addtopup(SubEditTable, _("|Line Left%B%x38"));
else
fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
if (table->RightLine(inset->GetActCell()))
fl_addtopup(SubEditTable, _("|Line Right%B%x39%l"));
else
fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
int align = table->GetAlignment(inset->GetActCell());
if (align == LYX_ALIGN_LEFT)
fl_addtopup(SubEditTable, _("|Align Left%R%x40"));
else
fl_addtopup(SubEditTable, _("|Align Left%r%x40"));
fl_setpup_shortcut(SubEditTable, 40, scex(_("EMT|eE#e#E")));
if (align == LYX_ALIGN_RIGHT)
fl_addtopup(SubEditTable, _("|Align Right%R%x41"));
else
fl_addtopup(SubEditTable, _("|Align Right%r%x41"));
fl_setpup_shortcut(SubEditTable, 41, scex(_("EMT|iI#i#I")));
if (align == LYX_ALIGN_CENTER)
fl_addtopup(SubEditTable, _("|Align Center%R%x42%l"));
else
fl_addtopup(SubEditTable, _("|Align Center%r%x42%l"));
fl_setpup_shortcut(SubEditTable, 42, scex(_("EMT|Cc#c#C")));
// xgettext:no-c-format
fl_addtopup(SubEditTable, _("|Append Row%x32"));
fl_setpup_shortcut(SubEditTable, 32, scex(_("EMT|oO#o#O")));
// xgettext:no-c-format
fl_addtopup(SubEditTable, _("|Append Column%x33%l"));
fl_setpup_shortcut(SubEditTable, 33, scex(_("EMT|uU#u#U")));
// xgettext:no-c-format
fl_addtopup(SubEditTable, _("|Delete Row%x34"));
fl_setpup_shortcut(SubEditTable, 34, scex(_("EMT|wW#w#W")));
// xgettext:no-c-format
fl_addtopup(SubEditTable, _("|Delete Column%x35%l"));
fl_setpup_shortcut(SubEditTable, 35, scex(_("EMT|nN#n#N")));
// xgettext:no-c-format
fl_addtopup(SubEditTable, _("|Delete Table%x43"));
fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
} else {
fl_addtopup(SubEditTable, _("Table%t"));
// xgettext:no-c-format
fl_addtopup(SubEditTable, _("|Insert table%x31"));
@ -1113,10 +1183,19 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
men->currentView()->beforeChange();
men->currentView()->update(-2);
}
if (men->currentView()->the_locking_inset &&
(men->currentView()->the_locking_inset->LyxCode()
== Inset::TABULAR_CODE)) {
InsetTabular * inset =
static_cast<InsetTabular *>
(men->currentView()->the_locking_inset);
inset->TabularFeatures(men->currentView(), choice - 32);
} else {
men->currentView()->text->
TableFeatures(choice - 32);
men->currentView()->update(1);
}
}
break;
// version control sub-menu
case 51: // register