Am Mittwoch, 30. November 2005 13:49 schrieb Georg Baum:

> So this means the patch works. What needs to be done before it can be
> applied? Maybe change InsetTabular::setFont to a virtual function for 
all
> insets that does nothing in other insets?

Ping! (updated patch attached)


Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog
--- lyx-1.4-clean/src/insets/ChangeLog	2005-12-03 18:46:34.000000000 +0100
+++ lyx-1.4-cvs/src/insets/ChangeLog	2005-12-04 20:12:15.541852456 +0100
@@ -1,3 +1,7 @@
+2005-12-04  Georg Baum  <[EMAIL PROTECTED]>
+
+	* insettabular.[Ch] (setFont): new, changes the font of all cells
+
 2005-11-02  Martin Vermeer  <[EMAIL PROTECTED]>
 
 	* insetbox.C (metrics): fix width problems (bug 2137)
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insettabular.C lyx-1.4-cvs/src/insets/insettabular.C
--- lyx-1.4-clean/src/insets/insettabular.C	2005-11-17 20:45:02.000000000 +0100
+++ lyx-1.4-cvs/src/insets/insettabular.C	2005-11-26 21:25:27.206710208 +0100
@@ -1050,6 +1050,21 @@ bool InsetTabular::getStatus(LCursor & c
 }
 
 
+void InsetTabular::setFont(LCursor & cur, LyXFont const & font)
+{
+	idx_type const cells = nargs();
+	for (idx_type i = 0; i < cells; ++i) {
+		cur.push(*(cell(i).get()));
+		// select all
+		cur.resetAnchor();
+		cell(i)->getText(0)->cursorBottom(cur);
+		cur.setSelection();
+		cell(i)->getText(0)->setFont(cur, font, false, false);
+		cur.pop();
+	}
+}
+
+
 int InsetTabular::latex(Buffer const & buf, ostream & os,
 			OutputParams const & runparams) const
 {
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insettabular.h lyx-1.4-cvs/src/insets/insettabular.h
--- lyx-1.4-clean/src/insets/insettabular.h	2005-11-17 20:45:02.000000000 +0100
+++ lyx-1.4-cvs/src/insets/insettabular.h	2005-11-26 20:55:13.000000000 +0100
@@ -36,6 +36,7 @@
 #include "tabular.h"
 
 class FuncStatus;
+class LCursor;
 class LyXLex;
 class Painter;
 class BufferView;
@@ -76,6 +77,9 @@ public:
 	bool noFontChange() const { return true; }
 	///
 	bool display() const { return tabular.isLongTabular(); }
+	/// Set the font of the complete tabular without undo.
+	/// Selection or individual cells can be changed via lfuns.
+	void setFont(LCursor &, LyXFont const &);
 	///
 	int latex(Buffer const &, std::ostream &,
 		  OutputParams const &) const;
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/ChangeLog lyx-1.4-cvs/src/ChangeLog
--- lyx-1.4-clean/src/ChangeLog	2005-12-03 18:45:48.000000000 +0100
+++ lyx-1.4-cvs/src/ChangeLog	2005-12-04 20:16:43.504116000 +0100
@@ -1,3 +1,9 @@
+2005-12-04  Georg Baum  <[EMAIL PROTECTED]>
+
+	* lyxtext.h, text2.C (setCharFont): add LCursor argument
+	* text2.C (setCharFont): set font of tabulars, too
+	* lyxtext.h, text2.C (setFont): add bool recordUndo argument
+
 2005-12-01  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* rowpainter.C (paintFirst): fix centering of
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/lyxtext.h lyx-1.4-cvs/src/lyxtext.h
--- lyx-1.4-clean/src/lyxtext.h	2005-10-26 20:58:49.000000000 +0200
+++ lyx-1.4-cvs/src/lyxtext.h	2005-11-26 21:09:27.968536576 +0100
@@ -66,10 +66,7 @@ public:
 	///
 	LyXFont getLabelFont(Paragraph const & par) const;
 	///
-	void setCharFont(pit_type pit, pos_type pos, LyXFont const & font);
-	///
-	void setCharFont(pit_type pit, pos_type pos, LyXFont const & font,
-		bool toggleall);
+	void setCharFont(LCursor & cur, pit_type, pos_type, LyXFont const &);
 
 	/// what you expect when pressing <enter> at cursor position
 	void breakParagraph(LCursor & cur, bool keep_layout = false);
@@ -92,7 +89,8 @@ public:
 	bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
 
 	/// Set font over selection paragraphs and rebreak.
-	void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
+	void setFont(LCursor & cur, LyXFont const &, bool toggleall = false,
+	             bool recordUndo = true);
 
 	/// rebreaks the given par
 	bool redoParagraph(pit_type pit);
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/text2.C lyx-1.4-cvs/src/text2.C
--- lyx-1.4-clean/src/text2.C	2005-10-26 20:58:56.000000000 +0200
+++ lyx-1.4-cvs/src/text2.C	2005-11-26 21:19:57.356855008 +0100
@@ -50,6 +50,7 @@
 #include "frontends/LyXView.h"
 
 #include "insets/insetenv.h"
+#include "insets/insettabular.h"
 
 #include "support/textutils.h"
 
@@ -243,7 +244,8 @@ LyXFont LyXText::getLabelFont(Paragraph 
 }
 
 
-void LyXText::setCharFont(pit_type pit, pos_type pos, LyXFont const & fnt)
+void LyXText::setCharFont(LCursor & cur, pit_type pit, pos_type pos,
+		LyXFont const & fnt)
 {
 	LyXFont font = fnt;
 	LyXLayout_ptr const & layout = pars_[pit].layout();
@@ -273,6 +275,17 @@ void LyXText::setCharFont(pit_type pit, 
 	// Now, reduce font against full layout font
 	font.reduce(layoutfont);
 
+	// fix bug 1973
+	// FIXME: Is this needed for other insets as well?
+	if (pars_[pit].isInset(pos)) {
+		InsetBase * inset = pars_[pit].getInset(pos);
+		if (inset->lyxCode() == InsetBase::TABULAR_CODE) {
+			cur.push(*inset);
+			static_cast<InsetTabular *>(inset)->setFont(cur, font);
+			cur.pop();
+		}
+	}
+
 	pars_[pit].setFont(pos, font);
 }
 
@@ -426,7 +439,8 @@ void LyXText::changeDepth(LCursor & cur,
 
 
 // set font over selection
-void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
+void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall,
+		bool recordUndo)
 {
 	BOOST_ASSERT(this == cur.text());
 	// if there is no selection just set the current_font
@@ -454,7 +468,8 @@ void LyXText::setFont(LCursor & cur, LyX
 	}
 
 	// Ok, we have a selection.
-	recordUndoSelection(cur);
+	if (recordUndo)
+		recordUndoSelection(cur);
 
 	DocIterator dit = cur.selectionBegin();
 	DocIterator ditend = cur.selectionEnd();
@@ -469,7 +484,7 @@ void LyXText::setFont(LCursor & cur, LyX
 		if (dit.pos() != dit.lastpos()) {
 			LyXFont f = getFont(dit.paragraph(), dit.pos());
 			f.update(font, params.language, toggleall);
-			setCharFont(dit.pit(), dit.pos(), f);
+			setCharFont(cur, dit.pit(), dit.pos(), f);
 		}
 	}
 }
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/text.C lyx-1.4-cvs/src/text.C
--- lyx-1.4-clean/src/text.C	2005-11-17 20:44:38.000000000 +0100
+++ lyx-1.4-cvs/src/text.C	2005-11-26 21:12:08.000000000 +0100
@@ -1138,11 +1138,11 @@ void LyXText::insertChar(LCursor & cur, 
 				     || par.isSeparator(cur.pos() - 2)
 				     || par.isNewline(cur.pos() - 2))
 				  ) {
-					setCharFont(pit, cur.pos() - 1, current_font);
+					setCharFont(cur, pit, cur.pos() - 1, current_font);
 				} else if (contains(number_seperators, c)
 				     && cur.pos() >= 2
 				     && getFont(par, cur.pos() - 2).number() == LyXFont::ON) {
-					setCharFont(pit, cur.pos() - 1, current_font);
+					setCharFont(cur, pit, cur.pos() - 1, current_font);
 				}
 			}
 		}

Reply via email to