From a942cf9e86136857008930d10bcfa632164bc4cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 13 Sep 2008 10:10:01 +0000 Subject: [PATCH] * Fix display of horizontal alignment in fixed width tabular cells (bug 3484) * src/Inset.h: - new member content Alignment that indicates whether the content of text insets should be displayed with a specific alignment * src/TextMetrics.cpp: - handle inset's contentAlignment * src/insets/InsetTabular.{cpp,h}: - set contentAlignment for tabular cells. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26380 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/TextMetrics.cpp | 16 ++++++++++++++++ src/insets/Inset.h | 3 +++ src/insets/InsetTabular.cpp | 6 +++++- src/insets/InsetTabular.h | 7 +++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 9ca701d2d4..a85073c5ac 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -550,6 +550,22 @@ void TextMetrics::computeRowMetrics(pit_type const pit, else align = par.params().align(); + // handle alignment inside tabular cells + if (Inset const * owner = par.inInset()) { + switch (owner->contentAlignment()) { + case LYX_ALIGN_CENTER: + case LYX_ALIGN_LEFT: + case LYX_ALIGN_RIGHT: + if (align == LYX_ALIGN_NONE + || align == LYX_ALIGN_BLOCK) + align = owner->contentAlignment(); + break; + default: + // unchanged (use align) + break; + } + } + // Display-style insets should always be on a centred row if (Inset const * inset = par.getInset(row.pos())) { switch (inset->display()) { diff --git a/src/insets/Inset.h b/src/insets/Inset.h index e50caf7f7b..7d66434d73 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -17,6 +17,7 @@ #include "ColorCode.h" #include "InsetCode.h" +#include "Layout.h" #include "support/strfwd.h" #include "support/types.h" @@ -403,6 +404,8 @@ public: /// should we have a non-filled line before this inset? virtual DisplayType display() const { return Inline; } + /// + virtual LyXAlignment contentAlignment() const { return LYX_ALIGN_NONE; } /// should we break lines after this inset? virtual bool isLineSeparator() const { return false; } /// should paragraph indendation be ommitted in any case? diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index deface7ce1..b035fc3471 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -945,6 +945,7 @@ void Tabular::setAlignment(idx_type cell, LyXAlignment align, column_info[cellColumn(cell)].alignment = align; if (!onlycolumn) cellInfo(cell).alignment = align; + cellInset(cell).get()->setContentAlignment(align); } @@ -1423,6 +1424,8 @@ void Tabular::read(Lexer & lex) } getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn); getTokenValue(line, "alignment", cell_info[i][j].alignment); + setAlignment(cellIndex(i, j), cell_info[i][j].alignment, + cell_info[i][j].multicolumn); getTokenValue(line, "valignment", cell_info[i][j].valignment); getTokenValue(line, "topline", cell_info[i][j].top_line); getTokenValue(line, "bottomline", cell_info[i][j].bottom_line); @@ -2732,7 +2735,8 @@ Tabular::BoxType Tabular::useParbox(idx_type cell) const ///////////////////////////////////////////////////////////////////// InsetTableCell::InsetTableCell(Buffer & buf) - : InsetText(buf), isFixedWidth(false) + : InsetText(buf), isFixedWidth(false), + contentAlign(LYX_ALIGN_CENTER) {} diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 66862d68f1..c3efdb03ea 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -643,6 +643,8 @@ public: FuncStatus & status) const; /// void toggleFixedWidth(bool fw) { isFixedWidth = fw; } + /// + void setContentAlignment(LyXAlignment al) {contentAlign = al; } /// writes the contents of the cell as a string, optionally /// descending into insets docstring asString(bool intoInsets = true); @@ -676,9 +678,14 @@ private: // --rgh /// bool isFixedWidth; + // FIXME: Here the thoughts from the comment above also apply. + /// + LyXAlignment contentAlign; /// should paragraph indendation be omitted in any case? bool neverIndent() const { return true; } /// + LyXAlignment contentAlignment() const { return contentAlign; } + /// virtual bool usePlainLayout() const { return true; } /// virtual bool forcePlainLayout(idx_type = 0) const; -- 2.39.2