From 6de5d0ad584f59f23f07e59972fab2ac8b66c814 Mon Sep 17 00:00:00 2001 From: Bernhard Roider Date: Sat, 12 May 2007 20:59:21 +0000 Subject: [PATCH] fix bug 2453 change of behavior of rotate-tabular and rotate-cell toolbar buttons such that they toggle the rotation. Therefore a toggle feature is added to the tabular features. Moreover after the patch the state of the set-rotate-cell and toggle-rotate-cell buttons is on only if all selected cells in the table are rotated. If not all selected cells are rotated then the toggle button rotates all selected cells. The toggle-icons are copied from the set-icons. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18280 a592a061-630c-0410-9148-cb99ea01b6c8 --- .../tabular-feature_toggle-rotate-cell.xpm | 46 +++++++++++++++++++ .../tabular-feature_toggle-rotate-tabular.xpm | 46 +++++++++++++++++++ lib/ui/stdtoolbars.inc | 4 +- src/insets/InsetTabular.cpp | 45 ++++++++++++++++-- src/insets/InsetTabular.h | 8 ++++ 5 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 lib/images/tabular-feature_toggle-rotate-cell.xpm create mode 100644 lib/images/tabular-feature_toggle-rotate-tabular.xpm diff --git a/lib/images/tabular-feature_toggle-rotate-cell.xpm b/lib/images/tabular-feature_toggle-rotate-cell.xpm new file mode 100644 index 0000000000..7fc23fd430 --- /dev/null +++ b/lib/images/tabular-feature_toggle-rotate-cell.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static char *tabular_feature_set_rotate_cell_[] = { +/* columns rows colors chars-per-pixel */ +"22 22 18 1", +" c black", +". c gray4", +"X c #131313131313", +"o c #1B1B1B1B1B1B", +"O c gray14", +"+ c #343434343434", +"@ c gray23", +"# c #414141414141", +"$ c #484848484848", +"% c gray32", +"& c #5D5D5D5D5D5D", +"* c #626262626262", +"= c #6D6D6D6D6D6D", +"- c gray48", +"; c #838383838383", +": c gray58", +"> c gray100", +", c None", +/* pixels */ +",,,,,,,,,,, ,,,,,,,,,,", +",,,,,,,,,,X.,,,,,,,,,,", +",,,,,,,,,o;. ,,,,,,,,", +",,,,,,,,X:=.+&@ ,,,,,,", +",,,,,,,.:*o =* ,,,,,", +",,,,,,,> *# X& ,,,,", +",,,,,,,,, *o Xoo# >,,", +",,,,,,,,,, . >*O+o.=>,", +",,,,,,,,,,>.,,>,@*.@>,", +",,,,,,,,,,,,,,,>*=o.,,", +",,,,,,, ,,> @ ,,", +",,,,,,, >>>>> ,,, * ,,", +",,,,,,, >>>>> ,,, -O>,", +",,,,,,, >>>>> ,,> *@>,", +",,,,,,, >>>>> ,>* .,>,", +",,,,,,, ,> =%>,,", +",,,,,,,,,,,,,,, = >,,,", +",,,,,,,,,,,,>,.$ ,,,,,", +",,,,,,,,,,,>&Xo ,,,,,,", +",,,,,,,,, X$->,,,,,,", +",,,,,,,,,,,,,>>,,,,,,,", +",,,,,,,,,,,,,,,,,,,,,," +}; diff --git a/lib/images/tabular-feature_toggle-rotate-tabular.xpm b/lib/images/tabular-feature_toggle-rotate-tabular.xpm new file mode 100644 index 0000000000..bbb689e4ab --- /dev/null +++ b/lib/images/tabular-feature_toggle-rotate-tabular.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static char *tabular_feature_set_rotate_tabular_[] = { +/* columns rows colors chars-per-pixel */ +"22 22 18 1", +" c black", +". c gray4", +"X c #131313131313", +"o c #1B1B1B1B1B1B", +"O c gray14", +"+ c #343434343434", +"@ c gray23", +"# c #414141414141", +"$ c #484848484848", +"% c gray32", +"& c #5D5D5D5D5D5D", +"* c #626262626262", +"= c #6D6D6D6D6D6D", +"- c gray48", +"; c #838383838383", +": c gray58", +"> c gray100", +", c None", +/* pixels */ +",,,,,,,,,,, ,,,,,,,,,,", +",,,,,,,,,,X.,,,,,,,,,,", +",,,,,,,,,o;. ,,,,,,,,", +",,, X:=.+&@ ,,,", +",,, >>>.:*o =* > ,,,", +",,, >>>> *# X& ,,,", +",,, *o Xoo# >,,", +",,, >>>> > . >*O+o.=>,", +",,, >>>> >>.> >>@*.@>,", +",,, >*=o.,,", +",,, >>>> >>>> >>> @ ,,", +",,, >>>> >>>> >>> * ,,", +",,, -O>,", +",,, >>>> >>>> >>> *@>,", +",,, >>>> >>>> >>* .,>,", +",,, > =%>,,", +",,, >>>> >>>> > = >,,,", +",,, >>>> >>>> .$ > ,,,", +",,, >&Xo ,,,", +",,,,,,,,, X$->,,,,,,", +",,,,,,,,,,,,,>>,,,,,,,", +",,,,,,,,,,,,,,,,,,,,,," +}; diff --git a/lib/ui/stdtoolbars.inc b/lib/ui/stdtoolbars.inc index 78a4542868..e110df0797 100644 --- a/lib/ui/stdtoolbars.inc +++ b/lib/ui/stdtoolbars.inc @@ -128,8 +128,8 @@ ToolbarSet Item "Align middle" "tabular-feature valign-middle" Item "Align bottom" "tabular-feature valign-bottom" Separator - Item "Rotate cell" "tabular-feature set-rotate-cell" - Item "Rotate table" "tabular-feature set-rotate-tabular" + Item "Rotate cell" "tabular-feature toggle-rotate-cell" + Item "Rotate table" "tabular-feature toggle-rotate-tabular" Item "Set multi-column" "tabular-feature multicolumn" End diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index f5a13e498a..fe48b69843 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -151,8 +151,10 @@ TabularFeature tabularFeature[] = { Tabular::SET_MPWIDTH, "set-mpwidth" }, { Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular" }, { Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" }, + { Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular" }, { Tabular::SET_ROTATE_CELL, "set-rotate-cell" }, { Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell" }, + { Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell" }, { Tabular::SET_USEBOX, "set-usebox" }, { Tabular::SET_LTHEAD, "set-lthead" }, { Tabular::UNSET_LTHEAD, "unset-lthead" }, @@ -3542,11 +3544,12 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, row_type sel_row_start = 0; row_type sel_row_end = 0; - col_type dummy; + col_type sel_col_start = 0; + col_type sel_col_end = 0; Tabular::ltType dummyltt; bool flag = true; - getSelection(cur, sel_row_start, sel_row_end, dummy, dummy); + getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end); switch (action) { case Tabular::SET_PWIDTH: @@ -3647,6 +3650,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, status.setOnOff(!tabular.isLongTabular()); break; + case Tabular::TOGGLE_ROTATE_TABULAR: case Tabular::SET_ROTATE_TABULAR: status.setOnOff(tabular.getRotateTabular()); break; @@ -3655,12 +3659,15 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, status.setOnOff(!tabular.getRotateTabular()); break; + case Tabular::TOGGLE_ROTATE_CELL: case Tabular::SET_ROTATE_CELL: - status.setOnOff(tabular.getRotateCell(cur.idx())); + status.setOnOff(!oneCellHasRotationState(false, + sel_row_start, sel_row_end, sel_col_start, sel_col_end)); break; case Tabular::UNSET_ROTATE_CELL: - status.setOnOff(!tabular.getRotateCell(cur.idx())); + status.setOnOff(!oneCellHasRotationState(true, + sel_row_start, sel_row_end, sel_col_start, sel_col_end)); break; case Tabular::SET_USEBOX: @@ -4079,6 +4086,20 @@ static void checkLongtableSpecial(Tabular::ltType & ltt, } } +bool InsetTabular::oneCellHasRotationState(bool rotated, + row_type row_start, row_type row_end, + col_type col_start, col_type col_end) const { + + for (row_type i = row_start; i <= row_end; ++i) { + for (col_type j = col_start; j <= col_end; ++j) { + if (tabular.getRotateCell(tabular.getCellNumber(i, j)) + == rotated) { + return true; + } + } + } + return false; +} void InsetTabular::tabularFeatures(Cursor & cur, Tabular::Feature feature, string const & value) @@ -4339,6 +4360,10 @@ void InsetTabular::tabularFeatures(Cursor & cur, tabular.setRotateTabular(false); break; + case Tabular::TOGGLE_ROTATE_TABULAR: + tabular.setRotateTabular(!tabular.getRotateTabular()); + break; + case Tabular::SET_ROTATE_CELL: for (row_type i = sel_row_start; i <= sel_row_end; ++i) for (col_type j = sel_col_start; j <= sel_col_end; ++j) @@ -4353,6 +4378,18 @@ void InsetTabular::tabularFeatures(Cursor & cur, tabular.getCellNumber(i, j), false); break; + case Tabular::TOGGLE_ROTATE_CELL: + { + bool oneNotRotated = oneCellHasRotationState(false, + sel_row_start, sel_row_end, sel_col_start, sel_col_end); + + for (row_type i = sel_row_start; i <= sel_row_end; ++i) + for (col_type j = sel_col_start; j <= sel_col_end; ++j) + tabular.setRotateCell(tabular.getCellNumber(i, j), + oneNotRotated); + } + break; + case Tabular::SET_USEBOX: { Tabular::BoxType val = Tabular::BoxType(convert(value)); if (val == tabular.getUsebox(cur.idx())) diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 0ff8873cc5..e12b9a55c2 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -144,10 +144,14 @@ public: /// UNSET_ROTATE_TABULAR, /// + TOGGLE_ROTATE_TABULAR, + /// SET_ROTATE_CELL, /// UNSET_ROTATE_CELL, /// + TOGGLE_ROTATE_CELL, + /// SET_USEBOX, /// SET_LTHEAD, @@ -810,6 +814,10 @@ private: /// return the cell nearest to x, y idx_type getNearestCell(BufferView &, int x, int y) const; + /// test the rotation state of the give cell range. + bool oneCellHasRotationState(bool rotated, + row_type row_start, row_type row_end, + col_type col_start, col_type col_end) const; /// Buffer const * buffer_; /// -- 2.39.2