r16638 by jghali - #10017 : jump when typing in text frame, provide a more elegant solution

scribus-commit scribus-commit at lists.scribus.net
Tue Jun 7 20:59:18 UTC 2011


Author: jghali
Date: Tue Jun  7 20:59:18 2011
New Revision: 16638

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16638
Log:
#10017 : jump when typing in text frame, provide a more elegant solution
- remove PageItem::CPos member, cursor position is now a shared member of StoryText and its position is updated mostly automatically when inserting or removing text in a StoryEditor
- add functions in StoryText for doing operations directly at current cursor position 
- complement object update api by updateLayout() : contrary to update(), updateLayout() will update layout immediately whereas update() will trigger layout() only in following paintEvent

Modified:
    branches/Version135/Scribus/scribus/canvasmode_edit.cpp
    branches/Version135/Scribus/scribus/canvasmode_legacy.cpp
    branches/Version135/Scribus/scribus/charselect.cpp
    branches/Version135/Scribus/scribus/gtaction.cpp
    branches/Version135/Scribus/scribus/observable.h
    branches/Version135/Scribus/scribus/pageitem.cpp
    branches/Version135/Scribus/scribus/pageitem.h
    branches/Version135/Scribus/scribus/pageitem_textframe.cpp
    branches/Version135/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
    branches/Version135/Scribus/scribus/propertiespalette.cpp
    branches/Version135/Scribus/scribus/scribus.cpp
    branches/Version135/Scribus/scribus/scribusdoc.cpp
    branches/Version135/Scribus/scribus/scribusview.cpp
    branches/Version135/Scribus/scribus/scribusview.h
    branches/Version135/Scribus/scribus/search.cpp
    branches/Version135/Scribus/scribus/storyeditor.cpp
    branches/Version135/Scribus/scribus/text/sctext_shared.cpp
    branches/Version135/Scribus/scribus/text/sctext_shared.h
    branches/Version135/Scribus/scribus/text/storytext.cpp
    branches/Version135/Scribus/scribus/text/storytext.h

Modified: branches/Version135/Scribus/scribus/canvasmode_edit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/canvasmode_edit.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/canvasmode_edit.cpp (original)
+++ branches/Version135/Scribus/scribus/canvasmode_edit.cpp Tue Jun  7 20:59:18 2011
@@ -187,12 +187,12 @@
 	{
 		// Debug
 // 		QString dbgString;
-// 		int lif(qMax(textframe->CPos , textframe->lastInFrame()));
+// 		int lif(qMax(textframe->itemText.cursorPosition() , textframe->lastInFrame()));
 // 		for(int ti(textframe->firstInFrame());ti < lif; ++ti)
 // 		{
-// 			if(ti == textframe->CPos )
+// 			if(ti == textframe->itemText.cursorPosition() )
 // 			{
-// 				dbgString += "["+QString::number(textframe->CPos)+"]";
+// 				dbgString += "["+QString::number(textframe->itemText.cursorPosition())+"]";
 // 			}
 // 			dbgString += textframe->itemText.text(ti);
 // 		}
@@ -206,8 +206,8 @@
 		QPen cPen ( Qt::black, 0.9 , Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin );
 
 		// normalize Current Position
-		textframe->CPos = qMax ( 0,qMin ( textframe->CPos, textframe->itemText.length() ) );
-		int textCursorPos ( textframe->CPos );
+		textframe->itemText.normalizeCursorPosition();
+		int textCursorPos ( textframe->itemText.cursorPosition() );
 
 		if ( textframe->lastInFrame() >= signed ( textframe->itemText.nrOfItems() )
 		        || textframe->itemText.length() == 0 )
@@ -429,7 +429,7 @@
 				if (m->modifiers() & Qt::ShiftModifier)
 				{//Double click with Ctrl+Shift in a frame to select few paragraphs
 					uint oldPar = currItem->itemText.nrOfParagraph(oldCp);
-					uint newPar = currItem->itemText.nrOfParagraph(currItem->CPos);
+					uint newPar = currItem->itemText.nrOfParagraph();
 					if (oldPar < newPar)
 					{
 						start = currItem->itemText.startOfParagraph(oldPar);
@@ -443,19 +443,19 @@
 				}
 				else
 				{//Double click with Ctrl in a frame to select a paragraph
-					oldCp = currItem->CPos;
+					oldCp = currItem->itemText.cursorPosition();
 					uint nrPar = currItem->itemText.nrOfParagraph(oldCp);
 					start = currItem->itemText.startOfParagraph(nrPar);
 					stop = currItem->itemText.endOfParagraph(nrPar);
 				}
 				currItem->itemText.deselectAll();
 				currItem->itemText.extendSelection(start, stop);
-				currItem->CPos = stop;
+				currItem->itemText.setCursorPosition(stop);
 			}
 			else
 			{	//Double click in a frame to select a word
-				oldCp = currItem->CPos;
-				currItem->CPos = currItem->itemText.selectWord(currItem->CPos);
+				oldCp = currItem->itemText.cursorPosition();
+				currItem->itemText.setCursorPosition( currItem->itemText.selectWord(currItem->itemText.cursorPosition()) );
 			}
 			currItem->HasSel = (currItem->itemText.lengthOfSelection() > 0);
 		}
@@ -511,14 +511,15 @@
 				//Make sure we dont go here if the old cursor position was not set
 				if (oldCp!=-1 && currItem->itemText.length() > 0)
 				{
-					if (currItem->CPos < oldCp)
-					{
-						currItem->itemText.select(currItem->CPos, oldCp - currItem->CPos);
+					int cPos = currItem->itemText.cursorPosition();
+					if (currItem->itemText.cursorPosition() < oldCp)
+					{
+						currItem->itemText.select(cPos, oldCp - cPos);
 						currItem->HasSel = true;
 					}
-					if (currItem->CPos > oldCp)
-					{
-						currItem->itemText.select(oldCp, currItem->CPos - oldCp);
+					if (currItem->itemText.cursorPosition() > oldCp)
+					{
+						currItem->itemText.select(oldCp, cPos - oldCp);
 						currItem->HasSel = true;
 					}
 				}
@@ -674,7 +675,7 @@
 				return;
 			}
 		}
-		oldP = currItem->CPos;
+		oldP = currItem->itemText.cursorPosition();
 		//CB Where we set the cursor for a click in text frame
 		if (currItem->asTextFrame())
 		{
@@ -700,33 +701,33 @@
 				{
 					if (currItem->itemText.lengthOfSelection() > 0)
 					{
-						if (currItem->CPos < (currItem->itemText.startOfSelection() + currItem->itemText.endOfSelection()) / 2)
+						if (currItem->itemText.cursorPosition() < (currItem->itemText.startOfSelection() + currItem->itemText.endOfSelection()) / 2)
 						{
 							if (m->modifiers() & Qt::ControlModifier)
-								currItem->CPos = currItem->itemText.startOfParagraph(currItem->itemText.nrOfParagraph(currItem->CPos));
+								currItem->itemText.setCursorPosition( currItem->itemText.startOfParagraph() );
 							oldP = currItem->itemText.startOfSelection();
 						}
 						else
 						{
 							if (m->modifiers() & Qt::ControlModifier)
-								currItem->CPos = currItem->itemText.endOfParagraph(currItem->itemText.nrOfParagraph(currItem->CPos));
+								currItem->itemText.setCursorPosition( currItem->itemText.endOfParagraph() );
 							oldP = currItem->itemText.endOfSelection();
 						}
-						currItem->asTextFrame()->itemText.extendSelection(oldP, currItem->CPos);
+						currItem->asTextFrame()->itemText.extendSelection(oldP, currItem->itemText.cursorPosition());
 						currItem->asTextFrame()->lastUndoAction = PageItem::NOACTION;
-						oldCp = currItem->CPos;
+						oldCp = currItem->itemText.cursorPosition();
 					}
 					else
 					{
 						int dir=1;
-						if (oldCp > currItem->CPos)
+						if (oldCp > currItem->itemText.cursorPosition())
 							dir=-1;
 						if (m->modifiers() & Qt::ControlModifier) //no selection but Ctrl+Shift+click still select paragraphs
 						{
 							if (dir == 1)
-								currItem->CPos = currItem->itemText.endOfParagraph(currItem->itemText.nrOfParagraph(currItem->CPos));
+								currItem->itemText.setCursorPosition( currItem->itemText.endOfParagraph() );
 							else
-								currItem->CPos = currItem->itemText.startOfParagraph(currItem->itemText.nrOfParagraph(currItem->CPos));
+								currItem->itemText.setCursorPosition( currItem->itemText.startOfParagraph() );
 						}
 						currItem->asTextFrame()->ExpandSel(dir, oldP);
 						currItem->asTextFrame()->lastUndoAction = PageItem::NOACTION;
@@ -735,7 +736,7 @@
 				}
 				else //>>CB
 				{
-					oldCp = currItem->CPos;
+					oldCp = currItem->itemText.cursorPosition();
 					currItem->itemText.deselectAll();
 					currItem->asTextFrame()->lastUndoAction = PageItem::NOACTION;
 					currItem->HasSel = false;

Modified: branches/Version135/Scribus/scribus/canvasmode_legacy.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/canvasmode_legacy.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/canvasmode_legacy.cpp (original)
+++ branches/Version135/Scribus/scribus/canvasmode_legacy.cpp Tue Jun  7 20:59:18 2011
@@ -120,10 +120,7 @@
 void LegacyMode::drawTextCursor(QPainter *p, PageItem_TextFrame* textframe)
 {
 	int x, y, y1;
-	if (textframe->CPos > textframe->itemText.length())
-	{
-		textframe->CPos = textframe->itemText.length();
-	}
+	textframe->itemText.normalizeCursorPosition();
 	if (textframe->lastInFrame() >= signed(textframe->itemText.nrOfItems()) 
 		|| textframe->itemText.length() == 0)
 	{
@@ -131,8 +128,8 @@
 		y = 0;
 		y1 = static_cast<int>(textframe->itemText.defaultStyle().charStyle().fontSize() / 10);
 	}
-	else if ( textframe->CPos > textframe->itemText.endOfItem(textframe->lastInFrame())
-			  || (textframe->CPos >= textframe->itemText.length() && textframe->itemText.text(textframe->itemText.length()-1) != SpecialChars::PARSEP) )
+	else if ( textframe->itemText.cursorPosition() > textframe->itemText.endOfItem(textframe->lastInFrame())
+			  || (textframe->itemText.cursorPosition() >= textframe->itemText.length() && textframe->itemText.text(textframe->itemText.length()-1) != SpecialChars::PARSEP) )
 	{
 		FRect bbox = textframe->itemText.boundingBox(qMax(0,qMin(textframe->lastInFrame(), textframe->itemText.length()-1)));
 		x = static_cast<int>(bbox.x() + bbox.width());
@@ -145,11 +142,11 @@
 	}
 	else
 	{
-		FRect bbox = textframe->itemText.boundingBox(qMax(0,qMin(textframe->CPos, textframe->itemText.length())));
+		FRect bbox = textframe->itemText.boundingBox( textframe->itemText.normalizedCursorPosition() );
 		x = static_cast<int>(bbox.x());
 		y = static_cast<int>(bbox.y());
 		if (bbox.height() <= 2) 
-			y1 = static_cast<int>(bbox.y() + textframe->itemText.charStyle(textframe->CPos).fontSize() / 30);
+			y1 = static_cast<int>(bbox.y() + textframe->itemText.charStyle().fontSize() / 30);
 		else
 			y1 = static_cast<int>(bbox.y() + bbox.height());
 	}
@@ -346,7 +343,7 @@
 					m_view->requestMode(modeNormal);
 					return;
 				}
-				int a=cItem->CPos;
+				int a = cItem->itemText.cursorPosition();
 				while(a>0)
 				{
 					if (cItem->itemText.text(a-1).isLetterOrNumber())
@@ -354,7 +351,7 @@
 					else
 						break;
 				}
-				int b=cItem->CPos;
+				int b = cItem->itemText.cursorPosition();
 				while(b<cItem->itemText.length())
 				{
 					if (cItem->itemText.text(b).isLetterOrNumber())
@@ -363,7 +360,7 @@
 						break;
 				}
 				oldCp = a;
-				cItem->CPos=b;
+				cItem->itemText.setCursorPosition(b);
 				cItem->ExpandSel(1, oldCp);
 //				m_view->slotDoCurs(true);
 			}
@@ -712,14 +709,15 @@
 				//Make sure we dont go here if the old cursor position was not set
 				if (oldCp!=-1 && currItem->itemText.length() > 0)
 				{
-					if (currItem->CPos < oldCp)
-					{
-						currItem->itemText.select(currItem->CPos, oldCp - currItem->CPos);
+					int cPos = currItem->itemText.cursorPosition();
+					if (currItem->itemText.cursorPosition() < oldCp)
+					{
+						currItem->itemText.select(cPos, oldCp - cPos);
 						currItem->HasSel = true;
 					}
-					if (currItem->CPos > oldCp)
-					{
-						currItem->itemText.select(oldCp, currItem->CPos - oldCp);
+					if (currItem->itemText.cursorPosition() > oldCp)
+					{
+						currItem->itemText.select(oldCp, cPos - oldCp);
 						currItem->HasSel = true;
 					}
 				}
@@ -1736,7 +1734,7 @@
 							return;
 						}
 					}
-					oldP = currItem->CPos;
+					oldP = currItem->itemText.cursorPosition();
 					//CB Where we set the cursor for a click in text frame
 					if (currItem->asTextFrame())
 					{
@@ -1754,14 +1752,14 @@
 						if (m->modifiers() & Qt::ShiftModifier)
 						{
 							int dir=1;
-							if (oldCp>currItem->CPos)
+							if (oldCp > currItem->itemText.cursorPosition())
 								dir=-1;
 							currItem->asTextFrame()->ExpandSel(dir, oldP);
 							oldCp = oldP;
 						}
 						else //>>CB
 						{
-							oldCp = currItem->CPos;
+							oldCp = currItem->itemText.cursorPosition();
 							currItem->itemText.deselectAll();
 							currItem->HasSel = false;
 						}
@@ -4019,7 +4017,7 @@
 		currItem = m_doc->m_Selection->itemAt(0);
 		if (currItem->asTextFrame())
 		{
-			if (oldCp == currItem->CPos)
+			if (oldCp == currItem->itemText.cursorPosition())
 			{
 				currItem->itemText.deselectAll();
 				currItem->HasSel = false;

Modified: branches/Version135/Scribus/scribus/charselect.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/charselect.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/charselect.cpp (original)
+++ branches/Version135/Scribus/scribus/charselect.cpp Tue Jun  7 20:59:18 2011
@@ -120,7 +120,7 @@
 	//CB: Avox please make text->insertchar(char) so none of this happens in gui code, and item can tell doc its changed so the view and mainwindow slotdocch are not necessary
 	QChar ch;
 	QString txtIns;
-	m_Item->oldCPos = m_Item->CPos;
+	m_Item->oldCPos = m_Item->itemText.cursorPosition();
 	for (int a=0; a<chToIns.length(); ++a)
 	{
 		ch = chToIns.at(a);
@@ -128,8 +128,7 @@
 			ch = QChar(13);
 		if (ch == QChar(9))
 			ch = QChar(32);
-		m_Item->itemText.insertChars(m_Item->CPos, ch, true);
-		m_Item->CPos += 1;
+		m_Item->itemText.insertChars(ch, true);
 		txtIns.append(ch);
 	}
 	if (m_Item->itemTextSaxed.isEmpty())
@@ -159,14 +158,13 @@
 		ch = QChar(13);
 	if (ch == QChar(9))
 		ch = QChar(32);
-	m_Item->oldCPos = m_Item->CPos;
-	m_Item->itemText.insertChars(m_Item->CPos, ch, true);
+	m_Item->oldCPos = m_Item->itemText.cursorPosition();
+	m_Item->itemText.insertChars(ch, true);
 	if (m_Item->itemTextSaxed.isEmpty())
 		m_Item->asTextFrame()->updateUndo(PageItem::INS, QString(ch));
 	else
 		m_Item->asTextFrame()->updateUndo(PageItem::REPSAX, m_Item->getTextSaxed(QString(ch)));
 	m_doc->updateFrameItems();
-	m_Item->CPos += 1;
 	m_doc->view()->DrawNew();
 	m_doc->changed();
 }

Modified: branches/Version135/Scribus/scribus/gtaction.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/gtaction.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/gtaction.cpp (original)
+++ branches/Version135/Scribus/scribus/gtaction.cpp Tue Jun  7 20:59:18 2011
@@ -94,7 +94,6 @@
 void gtAction::clearFrame()
 {
 	textFrame->itemText.clear();
-	textFrame->CPos = 0;
 }
 
 void gtAction::writeUnstyled(const QString& text)
@@ -109,12 +108,10 @@
 				while (nextItem != 0)
 				{
 					nextItem->itemText.clear();
-					nextItem->CPos = 0;
 					nextItem = nextItem->nextInChain();
 				}
 			}
 			it->itemText.clear();
-			it->CPos = 0;
 		}
 	}
 
@@ -147,12 +144,10 @@
 				while (nextItem != 0)
 				{
 					nextItem->itemText.clear();
-					nextItem->CPos = 0;
 					nextItem = nextItem->nextInChain();
 				}
 			}
 			it->itemText.clear();
-			it->CPos = 0;
 		}
 	}
 	int paragraphStyle = -1;

Modified: branches/Version135/Scribus/scribus/observable.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/observable.h
==============================================================================
--- branches/Version135/Scribus/scribus/observable.h (original)
+++ branches/Version135/Scribus/scribus/observable.h Tue Jun  7 20:59:18 2011
@@ -71,9 +71,11 @@
 template<class OBSERVED>
 struct Private_Memento : public UpdateMemento
 {
-	Private_Memento(OBSERVED data) : m_data(data) {};
+	Private_Memento(OBSERVED data) : m_data(data), m_layout(false) {};
+	Private_Memento(OBSERVED data, bool layout) : m_data(data), m_layout(layout) {};
 	
 	OBSERVED m_data;
+	bool     m_layout;
 };
 
 
@@ -84,7 +86,7 @@
 template<class OBSERVED>
 class SCRIBUS_API Observer {
 public:
-	virtual void changed(OBSERVED) = 0;
+	virtual void changed(OBSERVED, bool doLayout) = 0;
 	virtual ~Observer() {}
 };
 
@@ -124,6 +126,11 @@
 	    will take care of that.
 	 */
 	virtual void update(OBSERVED what);
+
+	/**
+		Same as update, except layout will be update immediately
+	 */
+	virtual void updateLayout(OBSERVED what);
 	
 	void connectObserver(Observer<OBSERVED>* o);
 	void disconnectObserver(Observer<OBSERVED>* o);
@@ -170,6 +177,11 @@
 	{ 
 		m_massObservable->update(dynamic_cast<OBSERVED*>(this)); 
 	}
+
+	virtual void updateLayout() 
+	{ 
+		m_massObservable->updateLayout(dynamic_cast<OBSERVED*>(this)); 
+	}
 	
 private:
 	MassObservable<OBSERVED*>* m_massObservable;
@@ -239,6 +251,15 @@
 	}
 }
 
+template<class OBSERVED>
+inline void MassObservable<OBSERVED>::updateLayout(OBSERVED what)
+{
+	Private_Memento<OBSERVED>* memento = new Private_Memento<OBSERVED>(what, true);
+	if (m_um == NULL || m_um->requestUpdate(this, memento))
+	{
+		updateNow(memento);
+	}
+}
 
 template<class OBSERVED>
 inline void MassObservable<OBSERVED>::updateNow(UpdateMemento* what)
@@ -246,7 +267,7 @@
 	Private_Memento<OBSERVED>* memento = dynamic_cast<Private_Memento<OBSERVED>*>(what);
 	foreach (Observer<OBSERVED>* obs, m_observers)
 	{
-		obs->changed(memento->m_data);
+		obs->changed(memento->m_data, memento->m_layout);
 	}
 	changedSignal->emitSignal(QVariant::fromValue(memento->m_data));
 	delete memento;

Modified: branches/Version135/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/pageitem.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem.cpp (original)
+++ branches/Version135/Scribus/scribus/pageitem.cpp Tue Jun  7 20:59:18 2011
@@ -134,7 +134,6 @@
 	BBoxH(other.BBoxH),
 	CurX(other.CurX),
 	CurY(other.CurY),
-	CPos(other.CPos),
 	itemText(other.itemText),
 	isBookmark(other.isBookmark),
 	HasSel(other.HasSel),
@@ -331,7 +330,6 @@
 	FrameType = 0;
 	CurX = 0;
 	CurY = 0;
-	CPos = 0;
 	oldCPos = 0;
 	Extra = 0;
 	TExtra = 0;
@@ -942,8 +940,8 @@
 /// returns the style at the current charpos
 const ParagraphStyle& PageItem::currentStyle() const
 {
-	if (frameDisplays(CPos))
-		return itemText.paragraphStyle(CPos);
+	if (frameDisplays(itemText.cursorPosition()))
+		return itemText.paragraphStyle();
 	else
 		return itemText.defaultStyle();
 }
@@ -951,8 +949,8 @@
 /// returns the style at the current charpos for changing
 ParagraphStyle& PageItem::changeCurrentStyle()
 {
-	if (frameDisplays(CPos))
-		return const_cast<ParagraphStyle&>(itemText.paragraphStyle(CPos));
+	if (frameDisplays(itemText.cursorPosition()))
+		return const_cast<ParagraphStyle&>(itemText.paragraphStyle());
 	else
 		return const_cast<ParagraphStyle&>(itemText.defaultStyle());
 }
@@ -960,8 +958,8 @@
 /// returns the style at the current charpos
 const CharStyle& PageItem::currentCharStyle() const
 {
-	if (frameDisplays(CPos))
-		return itemText.charStyle(CPos);
+	if (frameDisplays(itemText.cursorPosition()))
+		return itemText.charStyle();
 	else
 		return itemText.defaultStyle().charStyle();
 }
@@ -3931,7 +3929,7 @@
 				itemText.select(SelStart, story->length());
 				HasSel = true;
 			}
-			CPos = itemText.endOfSelection();
+			itemText.setCursorPosition( itemText.endOfSelection() );
 			delete story;
 		}
 		else { qDebug() << "UNDO buffer EMPTY";}
@@ -3969,7 +3967,6 @@
 		itemText.insert(pos,*story);
 		itemText.select(pos, story->length());
 		HasSel = true;
-		CPos = pos + story->length();
 		delete story;
 	}
 	else if (action == INSSAX || action == DELSAX)
@@ -3994,7 +3991,6 @@
 		{
 			//undo for DELSAX, redo for INSSAX
 			itemText.insert(pos, *story);
-			CPos = pos + story->length();
 		}
 		delete story;
 	}
@@ -4010,7 +4006,6 @@
 		else
 		{
 			itemText.insertChars(pos, str, true);
-			CPos = pos + str.length();
 		}
 	}
 	// after Undo or Redo new actions should create new undoStates
@@ -4045,9 +4040,9 @@
 			LenOldSel = itemText.lengthOfSelection();
 			if (LenOldSel > 0)
 				StartOldSel = itemText.startOfSelection();
-			if (CPos >= itemText.length())
+			if (itemText.cursorPosition() >= itemText.length())
 				return  "";
-			itemText.select(CPos,1);
+			itemText.select(itemText.cursorPosition(), 1);
 			HasSel = true;
 		}
 		//is SELECTION

Modified: branches/Version135/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/pageitem.h
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem.h (original)
+++ branches/Version135/Scribus/scribus/pageitem.h Tue Jun  7 20:59:18 2011
@@ -464,8 +464,6 @@
 	double CurX;
   /** Zeichen Y-Position */
 	double CurY;
-  /** Cursorposition */
-	int CPos;
   /** Text des Elements */
 	StoryText itemText;
   // for itemText undo purpose

Modified: branches/Version135/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem_textframe.cpp (original)
+++ branches/Version135/Scribus/scribus/pageitem_textframe.cpp Tue Jun  7 20:59:18 2011
@@ -923,9 +923,11 @@
 {
 // 	qDebug()<<"==Layout==" << itemName() ;
 // 	printBacktrace(24);
-	if (BackBox != 0 && BackBox->invalid) {
+	if (BackBox != NULL && BackBox->invalid) {
 //		qDebug("textframe: len=%d, going back", itemText.length());
-		invalid = false;
+		// Why that invalid = false here? Calling prevInChain->layout() does
+		// not ensure that this box will be layouted
+		// invalid = false;
 		PageItem_TextFrame* prevInChain = dynamic_cast<PageItem_TextFrame*>(BackBox);
 		while (prevInChain && prevInChain->invalid)
 		{
@@ -943,7 +945,7 @@
 //		qDebug() << QString("textframe: len=%1, invalid=%2 OnMasterPage=%3: no relayout").arg(itemText.length()).arg(invalid).arg(OnMasterPage);
 		return;
 	}
-	if (invalid && BackBox == 0)
+	if (invalid && BackBox == NULL)
 		firstChar = 0;
 	
 //	qDebug() << QString("textframe(%1,%2): len=%3, start relayout at %4").arg(Xpos).arg(Ypos).arg(itemText.length()).arg(firstInFrame());
@@ -2189,7 +2191,7 @@
 	MaxChars = itemText.length();
 	invalid = false;
 //	pf2.end();
-	if (NextBox != 0)
+	if (NextBox != NULL) 
 	{
 		PageItem_TextFrame* nextFrame = dynamic_cast<PageItem_TextFrame*>(NextBox);
 		if (nextFrame != NULL)
@@ -2209,14 +2211,14 @@
 	{
 		next->invalid = true;
 		next->firstChar = MaxChars;
-		if (CPos > signed(MaxChars))
-		{
-			int nCP = CPos;
+		if (itemText.cursorPosition() > signed(MaxChars))
+		{
+			int nCP = itemText.cursorPosition();
 //			CPos = MaxChars;
 			if (m_Doc->appMode == modeEdit)
 			{
 				//							OwnPage->Deselect(true);
-				next->CPos = qMax(nCP, signed(MaxChars));
+				next->itemText.setCursorPosition( qMax(nCP, signed(MaxChars)) );
 				//							Doc->currentPage = NextBox->OwnPage;
 				//							NextBox->OwnPage->SelectItemNr(NextBox->ItemNr);
 //				qDebug("textframe: len=%d, leaving relayout in editmode && Tinput", itemText.length());
@@ -2670,7 +2672,6 @@
 	nextItem->asTextFrame()->updateUndo(); //for undo
 	while (nextItem != 0)
 	{
-		nextItem->CPos = 0;
 		nextItem->invalid = true;
 		nextItem = nextItem->nextInChain();
 	}
@@ -2680,12 +2681,11 @@
 {
 	if (frameUnderflows())
 	{
-		CPos = itemText.length();
-		m_Doc->view()->Deselect(true);
+		itemText.setCursorPosition( itemText.length() );
 		PageItem * jumpFrame = frameTextEnd();
 		if (jumpFrame)
 		{
-			jumpFrame->CPos = CPos;
+			m_Doc->view()->Deselect(true);
 			m_Doc->scMW()->selectItemsFromOutlines(jumpFrame);
 			m_Doc->scMW()->setTBvals(jumpFrame);
 			jumpFrame->update();
@@ -2707,11 +2707,11 @@
 				jumpFrame->handleModeEditKey(k, keyRepeat);
 				jumpFrame->layout();
 				break;
-				}
+			}
 			return;
 		}
 	}
-	int oldPos = CPos; // 15-mar-2004 jjsa for cursor movement with Shift + Arrow key
+	int oldPos = itemText.cursorPosition(); // 15-mar-2004 jjsa for cursor movement with Shift + Arrow key
 	int kk = k->key();
 	int as = k->text()[0].unicode();
 	QString uc = k->text();
@@ -2791,9 +2791,8 @@
 					qDebug() << "SPACE conv?";
 					lastUndoAction = PageItem::NOACTION;
 				}
-				oldCPos = CPos;
-				itemText.insertChars(CPos, QString(QChar(conv)), true);
-				CPos += 1;
+				oldCPos = itemText.cursorPosition();
+				itemText.insertChars(QString(QChar(conv)), true);
 				if (itemTextSaxed.isEmpty())
 					updateUndo(INS, QString(QChar(conv)));
 				else
@@ -2820,13 +2819,13 @@
 		else if (kk == Qt::Key_Right) 
 			kk = Qt::Key_Left;
 	}
+
 	int oldLast = lastInFrame();
-	int tempCPos;
 	switch (kk)
 	{
 	case Qt::Key_Home:
 		// go to begin of line
-		if ( (pos = CPos) == firstInFrame() )
+		if ( (pos = itemText.cursorPosition()) == firstInFrame() )
 			break; // at begin of frame
 		len = lastInFrame();
 		if ( pos >= len )
@@ -2840,7 +2839,7 @@
 			//Control Home for start of frame text
 			pos = itemText.startOfFrame(pos);
 		}
-		CPos = pos;
+		itemText.setCursorPosition(pos);
 		if ( buttonModifiers & Qt::ShiftModifier )
 			ExpandSel(-1, oldPos);
 //		if ( this->itemText.lengthOfSelection() > 0 )
@@ -2850,16 +2849,16 @@
 	case Qt::Key_End:
 		// go to end of line
 		len = lastInFrame();
-		if ( CPos >= len )
+		if ( itemText.cursorPosition() >= len )
 			break; // at end of frame
 		if ( (buttonModifiers & Qt::ControlModifier) == 0 )
 		{
-			CPos = itemText.endOfLine(CPos);
+			itemText.setCursorPosition( itemText.endOfLine(itemText.cursorPosition()) );
 		}
 		else
 		{
 			//Control End for end of frame text
-			CPos = itemText.endOfFrame(CPos);
+			itemText.setCursorPosition( itemText.endOfFrame(itemText.cursorPosition()) );
 		}
 		if ( buttonModifiers & Qt::ShiftModifier )
 			ExpandSel(1, oldPos);
@@ -2872,30 +2871,29 @@
 		{
 			// go to end of paragraph
 			len = itemText.length();
-			CPos = itemText.nextParagraph(CPos);
+			itemText.setCursorPosition(itemText.nextParagraph(itemText.cursorPosition()));
 			if ( buttonModifiers & Qt::ShiftModifier )
 				ExpandSel(1, oldPos);
 		}
 		else
 		{
-			if (CPos <= lastInFrame())
-			{
-				CPos = itemText.nextLine(CPos);
+			if (itemText.cursorPosition() <= lastInFrame())
+			{
+				itemText.setCursorPosition(itemText.nextLine(itemText.cursorPosition()));
 				if ( buttonModifiers & Qt::ShiftModifier )
 				{
 					if ( buttonModifiers & Qt::AltModifier )
-						CPos = lastInFrame()+1;
+						itemText.setCursorPosition(lastInFrame() + 1);
 					ExpandSel(1, oldPos);
 				}
 				else 
-					if ((itemText.lines() > 0) && (oldPos >= itemText.line(itemText.lines()-1).firstItem) && (CPos >= lastInFrame()) && (NextBox != 0))
+					if ((itemText.lines() > 0) && (oldPos >= itemText.line(itemText.lines()-1).firstItem) && (itemText.cursorPosition() >= lastInFrame()) && (NextBox != 0))
 					{
-						if (NextBox->frameDisplays(CPos))
+						if (NextBox->frameDisplays(itemText.cursorPosition()))
 						{
 							view->Deselect(true);
 							// we position the cursor at the beginning of the next frame
 							// TODO position at the right place in next frame
-							NextBox->CPos = lastInFrame() + 1;
 							m_Doc->scMW()->selectItemsFromOutlines(NextBox);
 						}
 					}
@@ -2907,7 +2905,6 @@
 					if (NextBox->frameDisplays(lastInFrame()+1))
 					{
 						view->Deselect(true);
-						NextBox->CPos = lastInFrame()+1;
 						m_Doc->scMW()->selectItemsFromOutlines(NextBox);
 					}
 				}
@@ -2920,42 +2917,42 @@
 	case Qt::Key_Up:
 		if (buttonModifiers & Qt::ControlModifier)
 		{
-			if ( (pos = CPos) == firstInFrame() )
+			if ( (pos = itemText.cursorPosition()) == firstInFrame() )
 				break; // at begin of frame
 			len = itemText.length();
-			CPos = itemText.prevParagraph(CPos);
+			itemText.setCursorPosition( itemText.prevParagraph(itemText.cursorPosition()) );
 			if ( buttonModifiers & Qt::ShiftModifier )
 				ExpandSel(-1, oldPos);
 		}
 		else
 		{
-			if (CPos > firstInFrame())
-			{
-				if (CPos > lastInFrame() || CPos >= itemText.length())
-					CPos = lastInFrame();
-				CPos = itemText.prevLine(CPos);
+			if (itemText.cursorPosition() > firstInFrame())
+			{
+				if (itemText.cursorPosition() > lastInFrame() || itemText.cursorPosition() >= itemText.length())
+					itemText.setCursorPosition( lastInFrame() );
+				itemText.setCursorPosition( itemText.prevLine(itemText.cursorPosition()) );
 				if ( buttonModifiers & Qt::ShiftModifier )
 				{
 					if ( buttonModifiers & Qt::AltModifier )
-						CPos = firstInFrame();
+						itemText.setCursorPosition( firstInFrame() );
 					ExpandSel(-1, oldPos);
 				}
 				else
-					if ((itemText.lines() > 0) && (oldPos <= itemText.line(0).lastItem) && (CPos == firstInFrame()) && (BackBox != 0))
+					if ((itemText.lines() > 0) && (oldPos <= itemText.line(0).lastItem) && (itemText.cursorPosition() == firstInFrame()) && (BackBox != 0))
 					{
 						view->Deselect(true);
 						// TODO position at the right place in previous frame
-						BackBox->CPos = BackBox->lastInFrame();
+						BackBox->itemText.setCursorPosition( BackBox->lastInFrame() );
 						m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 					}
 			}
 			else
 			{
-				CPos = firstInFrame();
+				itemText.setCursorPosition( firstInFrame() );
 				if (BackBox != 0)
 				{
 					view->Deselect(true);
-					BackBox->CPos = BackBox->lastInFrame();
+					BackBox->itemText.setCursorPosition( BackBox->lastInFrame() );
 					m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 				}
 			}
@@ -2965,29 +2962,29 @@
 		m_Doc->scMW()->setTBvals(this);
 		break;
 	case Qt::Key_PageUp:
-		if (CPos == firstInFrame() && BackBox != 0)
+		if (itemText.cursorPosition() == firstInFrame() && BackBox != 0)
 		{
 			view->Deselect(true);
-			BackBox->CPos = BackBox->firstInFrame();
+			BackBox->itemText.setCursorPosition( BackBox->firstInFrame() );
 			m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 			//currItem = currItem->BackBox;
 		}
 		else
-			CPos = itemText.startOfFrame(CPos);
+			itemText.setCursorPosition( itemText.startOfFrame(itemText.cursorPosition()) );
 		if ( buttonModifiers & Qt::ShiftModifier )
 			ExpandSel(-1, oldPos);
 		m_Doc->scMW()->setTBvals(this);
 		break;
 	case Qt::Key_PageDown:
-		if (!frameDisplays(itemText.length()-1) && CPos >= lastInFrame() && NextBox != 0)
+		if (!frameDisplays(itemText.length()-1) && itemText.cursorPosition() >= lastInFrame() && NextBox != 0)
 		{
 			view->Deselect(true);
-			NextBox->CPos = NextBox->lastInFrame();
+			NextBox->itemText.setCursorPosition( NextBox->lastInFrame() );
 			m_Doc->scMW()->selectItemsFromOutlines(NextBox);
 			//currItem = currItem->BackBox;
 		}
 		else
-			CPos = itemText.endOfFrame(CPos);
+			itemText.setCursorPosition( itemText.endOfFrame(itemText.cursorPosition()) );
 		if ( buttonModifiers & Qt::ShiftModifier )
 			ExpandSel(1, oldPos);
 		m_Doc->scMW()->setTBvals(this);
@@ -3001,47 +2998,46 @@
 		}
 		else if ( buttonModifiers & Qt::ShiftModifier )
 		{
-			--CPos;
-			if ( CPos < 0 )
-				CPos = 0;
-			else
+			int pos = itemText.cursorPosition();
+			itemText.setCursorPosition(-1, true);
+			if ( pos > 0 )
 				ExpandSel(-1, oldPos);
 		}
 		else
 		{
-			--CPos;
-			if (CPos < firstInFrame())
-			{
-				CPos = firstInFrame();
+			itemText.setCursorPosition(-1, true);
+			if (itemText.cursorPosition() < firstInFrame())
+			{
+				itemText.setCursorPosition( firstInFrame() );
 				if (BackBox != 0)
 				{
 					view->Deselect(true);
-					BackBox->CPos = BackBox->lastInFrame();
+					BackBox->itemText.setCursorPosition( BackBox->lastInFrame() );
 					m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 					//currItem = currItem->BackBox;
 				}
 			}
 		}
-		if ((CPos > 0) && (CPos >= lastInFrame())) // I do not see how its possible, may be dead code - pm
-		{
-			CPos = lastInFrame();
+		if ((itemText.cursorPosition() > 0) && (itemText.cursorPosition() >= lastInFrame())) // I do not see how its possible, may be dead code - pm
+		{
+			itemText.setCursorPosition( lastInFrame() );
 //			if (itemText.charStyle(CPos-1).effects() & ScStyle_SuppressSpace)
 //			{
 //				--CPos;
-				while ((CPos > 1) && (itemText.charStyle(CPos).effects() & ScStyle_SuppressSpace) && (itemText.charStyle(CPos - 1).effects() & ScStyle_SuppressSpace))
-				{
-					--CPos;
-					if (CPos == 0)
+				while ((itemText.cursorPosition() > 1) && (itemText.charStyle().effects() & ScStyle_SuppressSpace) && (itemText.charStyle(itemText.cursorPosition() - 1).effects() & ScStyle_SuppressSpace))
+				{
+					itemText.setCursorPosition(-1, true);
+					if (itemText.cursorPosition() == 0)
 						break;
 				}
 //			}
 		}
 		else
 		{
-			while ((CPos > 1) && (itemText.charStyle(CPos).effects() & ScStyle_SuppressSpace) && (itemText.charStyle(CPos - 1).effects() & ScStyle_SuppressSpace))
-			{
-				--CPos;
-				if (CPos == 0)
+			while ((itemText.cursorPosition() > 1) && (itemText.charStyle().effects() & ScStyle_SuppressSpace) && (itemText.charStyle(itemText.cursorPosition() - 1).effects() & ScStyle_SuppressSpace))
+			{
+				itemText.setCursorPosition(-1, true);
+				if (itemText.cursorPosition() == 0)
 					break;
 			}
 		}
@@ -3058,25 +3054,23 @@
 		}
 		else if ( buttonModifiers & Qt::ShiftModifier )
 		{
-			++CPos;
-			if ( CPos > itemText.length() )
-				--CPos;
-			else
+			int pos = itemText.cursorPosition();
+			itemText.setCursorPosition(1, true);
+			if ( pos < itemText.length() )
 				ExpandSel(1, oldPos);
 		}
 		else
 		{
-			++CPos; // new position within text ?
-			if (CPos > lastInFrame())
+			itemText.setCursorPosition(1, true); // new position within text ?
+			if (itemText.cursorPosition() > lastInFrame())
 			{
 //				--CPos;
-				CPos = lastInFrame() + 1;
+				itemText.setCursorPosition(lastInFrame() + 1);
 				if (NextBox != 0)
 				{
-					if (NextBox->frameDisplays(CPos))
+					if (NextBox->frameDisplays(itemText.cursorPosition()))
 					{
 						view->Deselect(true);
-						NextBox->CPos = CPos;
 						m_Doc->scMW()->selectItemsFromOutlines(NextBox);
 						//currItem = currItem->NextBox;
 					}
@@ -3088,7 +3082,7 @@
 		m_Doc->scMW()->setTBvals(this);
 		break;
 	case Qt::Key_Delete:
-		if (CPos == itemText.length())
+		if (itemText.cursorPosition() == itemText.length())
 		{
 			if (itemText.lengthOfSelection() > 0)
 			{
@@ -3101,13 +3095,6 @@
 //				view->RefreshItem(this);
 			}
 			keyRepeat = false;
-			if (oldLast != lastInFrame() && NextBox != 0)
-			{
-				tempCPos = CPos;
-				NextBox->update();
-				NextBox->layout();
-				CPos = tempCPos;
-			}
 			return;
 		}
 		if (itemText.length() == 0)
@@ -3115,46 +3102,17 @@
 			keyRepeat = false;
 			return;
 		}
-		cr = itemText.text(CPos,1);
+		cr = itemText.text(1);
 		if (itemText.lengthOfSelection() == 0)
 		{
-			itemText.select(CPos, 1, true);
+			itemText.select(itemText.cursorPosition(), 1, true);
 			HasSel = true;
 		}
 		oldCPos = itemText.startOfSelection();
 		itemTextSaxed = getItemTextSaxed(PageItem::SELECTION);
 		deleteSelectedTextFromFrame();
 		updateUndo(DELSAX);
-		invalidateLayout();
-		tempCPos = CPos;
 		update();
-		layout();
-		CPos = tempCPos;
-		if (oldLast != lastInFrame() && NextBox != 0)
-		{
-			tempCPos = CPos;
-			NextBox->update();
-			NextBox->layout();
-			CPos = tempCPos;
-		}
-		if (CPos > lastInFrame() && NextBox != 0)
-		{
-			lastUndoAction = PageItem::NOACTION;
-			view->Deselect(true);
-			NextBox->update();
-			NextBox->layout();
-			NextBox->CPos = CPos;
-			m_Doc->scMW()->selectItemsFromOutlines(NextBox);
-		}
-		else if (CPos < firstInFrame() && BackBox != 0)
-		{
-			lastUndoAction = PageItem::NOACTION;
-			view->Deselect(true);
-			BackBox->update();
-			BackBox->layout();
-			BackBox->CPos = CPos;
-			m_Doc->scMW()->selectItemsFromOutlines(BackBox);
-		}
 //		Tinput = false;
 		if ((cr == QChar(13)) && (itemText.length() != 0))
 		{
@@ -3165,7 +3123,7 @@
 //		view->RefreshItem(this);
 		break;
 	case Qt::Key_Backspace:
-		if (CPos == 0)
+		if (itemText.cursorPosition()  == 0)
 		{
 			if (itemText.lengthOfSelection() > 0)
 			{
@@ -3176,22 +3134,15 @@
 				m_Doc->scMW()->setTBvals(this);
 				update();
 			}
-			if (oldLast != lastInFrame() && NextBox != 0)
-			{
-				tempCPos =CPos;
-				NextBox->update();
-				NextBox->layout();
-				CPos = tempCPos;
-			}
 			break;
 		}
 		if (itemText.length() == 0)
 			break;
-		cr = itemText.text(qMax(CPos-1,0),1);
+		cr = itemText.text(qMax(itemText.cursorPosition() - 1,0),1);
 		if (itemText.lengthOfSelection() == 0)
 		{
-			--CPos;
-			itemText.select(CPos, 1, true);
+			itemText.setCursorPosition(-1, true);
+			itemText.select(itemText.cursorPosition(), 1, true);
 			HasSel = true;
 		}
 		oldCPos = itemText.startOfSelection();
@@ -3201,34 +3152,27 @@
 //		Tinput = false;
 		if ((cr == QChar(13)) && (itemText.length() != 0))
 		{
-//			m_Doc->chAbStyle(this, findParagraphStyle(m_Doc, itemText.paragraphStyle(qMax(CPos-1,0))));
+//			m_Doc->chAbStyle(this, findParagraphStyle(m_Doc, itemText.paragraphStyle(qMax(itemText.cursorPosition()-1,0))));
 //			Tinput = false;
 		}
-		tempCPos = CPos;
-		update();
-		layout();
-		CPos = tempCPos;
-		if (oldLast != lastInFrame() && NextBox != 0)
-		{
-			tempCPos = CPos;
-			NextBox->update();
-			NextBox->layout();
-			CPos = tempCPos;
-		}
-		if (CPos < firstInFrame())
-		{
-			CPos = firstInFrame();
+		updateLayout();
+		if (oldLast != lastInFrame() && NextBox != 0 && NextBox->invalid)
+			NextBox->updateLayout();
+		if (itemText.cursorPosition() < firstInFrame())
+		{
+			itemText.setCursorPosition(firstInFrame());
 			if (BackBox != 0)
 			{
 				lastUndoAction = PageItem::NOACTION;
 				view->Deselect(true);
-				BackBox->update();
-				BackBox->layout();
-				BackBox->CPos = BackBox->lastInFrame();
+				if (BackBox->invalid)
+					BackBox->updateLayout();
+				BackBox->itemText.setCursorPosition( BackBox->lastInFrame() );
 				m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 			}
 		}
 		m_Doc->scMW()->setTBvals(this);
+		update();
 //		view->RefreshItem(this);
 		break;
 	default:
@@ -3267,9 +3211,8 @@
 		//if ((kk == Qt::Key_Tab) || ((kk == Qt::Key_Return) && (buttonState & Qt::ShiftButton)))
 		if (kk == Qt::Key_Tab)
 		{
-			oldCPos = CPos;
-			itemText.insertChars(CPos, QString(SpecialChars::TAB), true);
-			CPos += 1;
+			oldCPos = itemText.cursorPosition();
+			itemText.insertChars(QString(SpecialChars::TAB), true);
 			lastUndoAction = PageItem::NOACTION;
 			if (itemTextSaxed.isEmpty())
 				updateUndo(INS, QString(SpecialChars::TAB));
@@ -3284,20 +3227,19 @@
 			if (uc[0] == QChar(32) || uc[0] == QChar(13))
 				lastUndoAction = PageItem::NOACTION;
 			if (lastUndoAction != PageItem::INS)
-				oldCPos = CPos;
-			itemText.insertChars(CPos, uc, true);
-			CPos += 1;
+				oldCPos = itemText.cursorPosition();
+			itemText.insertChars(uc, true);
 			if (itemTextSaxed.isEmpty())
 				updateUndo(INS, uc);
 			else
 				updateUndo(REPSAX, getTextSaxed(uc));
-			if ((m_Doc->docHyphenator->AutoCheck) && (CPos > 1))
+			if ((m_Doc->docHyphenator->AutoCheck) && (itemText.cursorPosition() > 1))
 			{
 				Twort = "";
 				Tcoun = 0;
-				for (int hych = CPos-1; hych > -1; hych--)
-				{
-					Tcha = itemText.text(hych,1);
+				for (int hych = itemText.cursorPosition()-1; hych > -1; hych--)
+				{
+					Tcha = itemText.text(hych, 1);
 					if (Tcha[0] == ' ')
 					{
 						Tcoun = hych+1;
@@ -3317,31 +3259,19 @@
 		}
 		if (doUpdate)
 		{
-			tempCPos = CPos;
-			update();
-			layout();
-			CPos = tempCPos;
-			if (oldLast != lastInFrame() && NextBox != 0)
-			{
-				tempCPos = CPos;
-				NextBox->update();
-				NextBox->layout();
-				CPos = tempCPos;
-			}
+			// update layout immediately, we need MaxChars to be correct to detect 
+			// if we need to move to next frame or not
+			updateLayout();
+			if (oldLast != lastInFrame() && NextBox != 0 && NextBox->invalid)
+				NextBox->updateLayout();
 		}
 		//check if cursor need to jump to next linked frame
-		int Last = lastInFrame();
-		int Len = itemText.length();
-		if (CPos > lastInFrame()+1 && lastInFrame() < (itemText.length() -2) && NextBox != 0)
+		if ((itemText.cursorPosition() > lastInFrame() + 1) && (lastInFrame() < (itemText.length() - 2)) && NextBox != 0)
 		{
 			lastUndoAction = PageItem::NOACTION;
 			view->Deselect(true);
-			tempCPos = CPos;
 			NextBox->update();
-			NextBox->layout();
 			m_Doc->scMW()->selectItemsFromOutlines(NextBox);
-			NextBox->CPos = tempCPos;
-			view->DrawNew();
 		}
 		break;
 	}
@@ -3357,7 +3287,7 @@
 void PageItem_TextFrame::deleteSelectedTextFromFrame()
 {
 	if (itemText.lengthOfSelection() > 0) {
-		CPos = itemText.startOfSelection();
+		itemText.setCursorPosition( itemText.startOfSelection() );
 		itemText.removeSelection();
 		HasSel = false;
 	}
@@ -3377,13 +3307,13 @@
 	if ( dir > 0 && oldPos < len )
 	{
 		wasSpace = itemText.text(oldPos).isSpace();
-		CPos=oldPos+1;
-		while (CPos<len)
-		{
-			isSpace = itemText.text(CPos).isSpace();
+		itemText.setCursorPosition(oldPos + 1);
+		while (itemText.cursorPosition() < len)
+		{
+			isSpace = itemText.text().isSpace();
 			if (wasSpace && !isSpace)
 				break;
-			++CPos;
+			itemText.setCursorPosition(1, true);
 			wasSpace=isSpace;
 			
 		}
@@ -3400,17 +3330,17 @@
 	}
 	else if ( dir < 0 && oldPos > 0 )
 	{
-		CPos=oldPos-1;
-		wasSpace = itemText.text(CPos).isSpace();
-		while (CPos>0)
-		{
-			isSpace = itemText.text(CPos).isSpace();
+		itemText.setCursorPosition(oldPos - 1);
+		wasSpace = itemText.text().isSpace();
+		while (itemText.cursorPosition() > 0)
+		{
+			isSpace = itemText.text().isSpace();
 			if (!wasSpace && isSpace)
 			{
-				++CPos;
+				itemText.setCursorPosition(1, true);
 				break;
 			}
-			--CPos;
+			itemText.setCursorPosition(-1, true);
 			wasSpace=isSpace;
 			
 		}
@@ -3449,19 +3379,19 @@
 	// preventing it to be less than 0 here.
 	int end = qMax(0,itemText.endOfSelection());
 	
-	if (oldPos >= end && CPos < start)
+	if (oldPos >= end && itemText.cursorPosition() < start)
 	{
 		itemText.deselectAll();
-		itemText.select(CPos, start - CPos);
-	}
-	else if (oldPos <= start && CPos > end)
+		itemText.select(itemText.cursorPosition(), start - itemText.cursorPosition());
+	}
+	else if (oldPos <= start && itemText.cursorPosition() > end)
 	{
 		itemText.deselectAll();
-		itemText.select(end, CPos - end);
+		itemText.select(end, itemText.cursorPosition() - end);
 	}
 	else
 	{
-		itemText.extendSelection(oldPos, CPos);
+		itemText.extendSelection(oldPos, itemText.cursorPosition());
 	}
 	HasSel = (itemText.lengthOfSelection() > 0);
 	if (HasSel)
@@ -3475,7 +3405,7 @@
 		//CB Replace with direct call for now //emit  HasNoTextSel();
 		m_Doc->scMW()->DisableTxEdit();
 	}
-	cursorBiasBackward = (oldPos > CPos);
+	cursorBiasBackward = (oldPos > itemText.cursorPosition());
 
 // 	layoutWeakLock = true;
 // 	update();
@@ -3497,8 +3427,8 @@
 	else
 	{
 		//extend selection to whole paragraph
-		StartSel = itemText.startOfParagraph(itemText.nrOfParagraph(CPos));
-		LenSel = itemText.endOfParagraph(itemText.nrOfParagraph(CPos)) - StartSel;
+		StartSel = itemText.startOfParagraph();
+		LenSel = itemText.endOfParagraph() - StartSel;
 	}
 	itemText.select(StartSel, LenSel);
 	HasSel = true;
@@ -3516,8 +3446,8 @@
 	else
 	{
 		//extend selection to whole paragraph
-		selStart  = itemText.startOfParagraph(itemText.nrOfParagraph(CPos));
-		selLength = itemText.endOfParagraph(itemText.nrOfParagraph(CPos)) - selStart;
+		selStart  = itemText.startOfParagraph();
+		selLength = itemText.endOfParagraph() - selStart;
 	}
 	if (includeEOL)
 		selLength += 1;
@@ -3821,7 +3751,7 @@
 			expandParaSelection(true);
 			action = PARAMSEL;
 		}
-		if (CPos >= itemText.length() && itemTextSaxed.isEmpty() && action == PARAMFULL && m_Doc->appMode == modeEdit)
+		if (itemText.cursorPosition() >= itemText.length() && itemTextSaxed.isEmpty() && action == PARAMFULL && m_Doc->appMode == modeEdit)
 		{ 
 			//case when cursor is after last character without selection and nothing was and will be done
 			//changes will be ignored
@@ -3883,7 +3813,7 @@
 			}
 			if (action == PARAMSEL)
 			{
-				ss->set("STEXT_CPOS",CPos);
+				ss->set("STEXT_CPOS", itemText.cursorPosition());
 				ss->set("STEXT_SELSTART", itemText.startOfSelection());
 				ss->set("STEXT_SELLEN", itemText.lengthOfSelection());
 			}

Modified: branches/Version135/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp (original)
+++ branches/Version135/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp Tue Jun  7 20:59:18 2011
@@ -262,7 +262,6 @@
 	Daten.replace(QChar('\n') , SpecialChars::PARSEP);
 	PyMem_Free(Text);
 	currItem->itemText.clear();
-	currItem->CPos = 0;
 	for (int a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a)
 	{
 		ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a;
@@ -304,7 +303,6 @@
 	if (pos == -1)
 		pos = it->itemText.length();
 	it->itemText.insertChars(pos, Daten);
-	it->CPos = pos + Daten.length();
 	it->Dirty = true;
 	if (ScCore->primaryMainWindow()->doc->DoDrawing)
 	{
@@ -612,7 +610,6 @@
 	else
 	{
 		it->itemText.clear();
-		it->CPos = 0;
 		for (int a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a)
 		{
 			ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a;

Modified: branches/Version135/Scribus/scribus/propertiespalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/propertiespalette.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/propertiespalette.cpp (original)
+++ branches/Version135/Scribus/scribus/propertiespalette.cpp Tue Jun  7 20:59:18 2011
@@ -4287,8 +4287,8 @@
 		if (doc->appMode == modeEdit)
 		{
 			//selected parapgraph(s) only
-			selStart = (itemText.lengthOfSelection() > 0) ? itemText.startOfSelection() : CurItem->CPos;
-			selEnd   = (itemText.lengthOfSelection() > 0) ? itemText.endOfSelection() : CurItem->CPos;
+			selStart = (itemText.lengthOfSelection() > 0) ? itemText.startOfSelection() : CurItem->itemText.cursorPosition();
+			selEnd   = (itemText.lengthOfSelection() > 0) ? itemText.endOfSelection() : CurItem->itemText.cursorPosition();
 			selStart = itemText.startOfParagraph( itemText.nrOfParagraph(selStart) );
 			selEnd   = itemText.endOfParagraph  ( itemText.nrOfParagraph(selEnd) );
 		}

Modified: branches/Version135/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/scribus.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/scribus.cpp (original)
+++ branches/Version135/Scribus/scribus/scribus.cpp Tue Jun  7 20:59:18 2011
@@ -1115,13 +1115,12 @@
 							currItem->asTextFrame()->deleteSelectedTextFromFrame();
 						}
 						else
-							currItem->oldCPos = currItem->CPos;
-						currItem->itemText.insertChars(currItem->CPos, QString(QChar(unicodevalue)), true);
+							currItem->oldCPos = currItem->itemText.cursorPosition();
+						currItem->itemText.insertChars(QString(QChar(unicodevalue)), true);
 						if (currItem->itemTextSaxed.isEmpty())
 							currItem->asTextFrame()->updateUndo(PageItem::INS, QString(QChar(unicodevalue)));
 						else
 							currItem->asTextFrame()->updateUndo(PageItem::REPSAX, currItem->getTextSaxed(QString(QChar(unicodevalue))));
-						currItem->CPos += 1;
 //						currItem->Tinput = true;
 						currItem->update();
 					}
@@ -1129,16 +1128,15 @@
 					{
 						// this code is currently dead since unicodeSmartHyphen
 						// doesnt have unicodevalue == -1 any more
-						if (currItem->CPos-1>0)
+						if (currItem->itemText.cursorPosition() - 1 > 0)
 						{
 #if 0
-							StyleFlag fl = currItem->itemText.item(qMax(currItem->CPos-1,0))->effects();
+							StyleFlag fl = currItem->itemText.item(qMax(currItem->itemText.cursorPosition()-1,0))->effects();
 							fl |= ScStyle_HyphenationPossible;
 							currItem->itemText.item(qMax(currItem->CPos-1,0))->setEffects(fl);
 #else
-							currItem->itemText.insertChars(currItem->CPos, QString(SpecialChars::SHYPHEN), true);
-							currItem->oldCPos = currItem->CPos;
-							currItem->CPos += 1;
+							currItem->oldCPos = currItem->itemText.cursorPosition() ;
+							currItem->itemText.insertChars(QString(SpecialChars::SHYPHEN), true);
 							currItem->asTextFrame()->updateUndo(PageItem::INS, QString(SpecialChars::SHYPHEN));
 #endif
 //							currItem->Tinput = true;
@@ -5152,11 +5150,8 @@
 				currItem->deleteSelectedTextFromFrame();
 			}
 
-			if (currItem->CPos < 0)
-				currItem->CPos = 0;
-			if (currItem->CPos > currItem->itemText.length())
-				currItem->CPos = currItem->itemText.length();
-			currItem->oldCPos = currItem->CPos;
+			currItem->itemText.normalizeCursorPosition();
+			currItem->oldCPos = currItem->itemText.cursorPosition();
 			if (ScMimeData::clipboardHasScribusText())
 			{
 				Serializer dig(*doc);
@@ -5169,15 +5164,14 @@
 
 				StoryText* story = dig.result<StoryText>();
 
-				currItem->itemText.insert(currItem->CPos, *story);
+				currItem->itemText.insert(*story);
 
 				//for text undo, select inserted text for saxing it
-				currItem->itemText.select(currItem->CPos,story->length());
+				currItem->itemText.select(currItem->oldCPos, story->length());
 				currItem->HasSel = true;
 				//if itemTextSaxed is not empty there was selection
 				currItem->updateUndo(currItem->itemTextSaxed.isEmpty() ? PageItem::INSSAX : PageItem::REPSAX,currItem->getItemTextSaxed(PageItem::SELECTION));
-
-				currItem->CPos += story->length();
+				currItem->itemText.deselectAll();
 
 				delete story;
 			}
@@ -5259,11 +5253,10 @@
 				doc->maxCanvasCoordinate = maxSize;
 				if (outlinePalette->isVisible())
 					outlinePalette->BuildTree();
-				currItem->itemText.insertObject(currItem->CPos, currItem3);
-				currItem->CPos += 1;
+				currItem->itemText.insertObject(currItem3);
 				undoManager->setUndoEnabled(true);
 				//for text undo, select inserted text for saxing it
-				currItem->itemText.select(currItem->oldCPos,currItem->CPos - currItem->oldCPos);
+				currItem->itemText.select(currItem->oldCPos, currItem->itemText.cursorPosition() - currItem->oldCPos);
 				currItem->HasSel = true;
 				//if itemTextSaxed is not empty there was selection
 				currItem->updateUndo(currItem->itemTextSaxed.isEmpty() ? PageItem::INSSAX : PageItem::REPSAX,currItem->getItemTextSaxed(PageItem::SELECTION));
@@ -5274,9 +5267,10 @@
 				QString text = QApplication::clipboard()->text(QClipboard::Clipboard);
 				text = text.replace("\r\n", SpecialChars::PARSEP);
 				text = text.replace('\n', SpecialChars::PARSEP);
-				currItem->itemText.insertChars(currItem->CPos, text, true);
+				int cursorPos = currItem->itemText.cursorPosition();
+				currItem->itemText.insertChars(cursorPos, text, true);
 				//for text undo, select inserted text for saxing it
-				currItem->itemText.select(currItem->CPos,text.length());
+				currItem->itemText.select(cursorPos, text.length());
 				currItem->HasSel = true;
 				//if itemTextSaxed is not empty there was selection
 				if (currItem->itemTextSaxed.isEmpty())
@@ -6521,7 +6515,7 @@
 //					return;
 //				}
 				setTBvals(currItem);
-				currItem->CPos = 0;
+				currItem->itemText.setCursorPosition(0);
 			}
 			scrActions["editPaste"]->setEnabled(false);
 			charPalette->setEnabled(true, currItem);
@@ -9244,7 +9238,7 @@
 {
 	PageItem *currItem = doc->m_Selection->itemAt(0);
 	view->requestMode(modeEdit);
-	currItem->CPos = 0;
+	currItem->itemText.setCursorPosition(0);
 	SearchReplace* dia = new SearchReplace(this, doc, currItem);
 	connect(dia, SIGNAL(NewFont(const QString&)), this, SLOT(SetNewFont(const QString&)));
 	connect(dia, SIGNAL(NewAbs(int)), this, SLOT(setAbsValue(int)));

Modified: branches/Version135/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/scribusdoc.cpp (original)
+++ branches/Version135/Scribus/scribus/scribusdoc.cpp Tue Jun  7 20:59:18 2011
@@ -128,7 +128,7 @@
 		}
 	}
 	
-	void changed(Page* pg)
+	void changed(Page* pg, bool /*layout*/)
 	{
 		QRectF pagebox(pg->xOffset(), pg->yOffset(), pg->width(), pg->height());
 		doc->invalidateRegion(pagebox);
@@ -141,9 +141,11 @@
 		m_docChangeNeeded = true;
 	}
 	
-	void changed(PageItem* it)
+	void changed(PageItem* it, bool layout)
 	{
 		it->invalidateLayout();
+		if (layout)
+			it->layout();
 		doc->regionsChanged()->update(it->getBoundingRect());
 		if (m_updateEnabled <= 0)
 		{
@@ -6022,7 +6024,7 @@
 				start = currItem->itemText.startOfSelection();
 				stop = currItem->itemText.endOfSelection();
 				if (start >= stop)
-					start = stop = qMax(0, qMin(currItem->itemText.length(), currItem->CPos));
+					start = stop = currItem->itemText.normalizedCursorPosition();
 			}
 			for (int pos=start; pos < stop; ++pos)
 			{
@@ -6076,7 +6078,7 @@
 				start = currItem->itemText.startOfSelection();
 				stop = currItem->itemText.endOfSelection();
 				if (start >= stop)
-					start = stop = qMax(0, qMin(currItem->itemText.length(), currItem->CPos));
+					start = stop = currItem->itemText.normalizedCursorPosition();
 			}
 			for (int pos=start; pos < stop; ++pos)
 			{
@@ -6140,7 +6142,7 @@
 				start = currItem->itemText.startOfSelection();
 				stop = currItem->itemText.endOfSelection();
 				if (start >= stop)
-					start = stop = qMax(0, qMin(currItem->itemText.length(), currItem->CPos));
+					start = stop = currItem->itemText.normalizedCursorPosition();
 			}
 			for (int pos=start; pos < stop; ++pos)
 			{
@@ -6195,7 +6197,7 @@
 				}
 				else
 				{
-					start = qMax(currItem->firstInFrame(), currItem->CPos);
+					start = qMax(currItem->firstInFrame(), currItem->itemText.cursorPosition());
 					length = (start + 1) < currItem->itemText.length()? 1 : 0;
 				}
 			}
@@ -6254,7 +6256,7 @@
 				}
 				else
 				{
-					start = qMax(currItem->firstInFrame(), currItem->CPos);
+					start = qMax(currItem->firstInFrame(), currItem->itemText.cursorPosition());
 					length = (start + 1) < currItem->itemText.length()? 1 : 0;
 				}
 			}
@@ -6312,7 +6314,7 @@
 				}
 				else
 				{
-					start = qMax(currItem->firstInFrame(), currItem->CPos);
+					start = qMax(currItem->firstInFrame(), currItem->itemText.cursorPosition());
 					length = (start + 1) < currItem->itemText.length()? 1 : 0;
 				}
 			}

Modified: branches/Version135/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/scribusview.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/scribusview.cpp (original)
+++ branches/Version135/Scribus/scribus/scribusview.cpp Tue Jun  7 20:59:18 2011
@@ -448,7 +448,7 @@
 	}
 }
 
-void ScribusView::changed(QRectF re)
+void ScribusView::changed(QRectF re, bool)
 {
 	double scale = m_canvas->scale();
 	int newCanvasWidth = qRound((Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()) * scale);
@@ -993,7 +993,7 @@
 						txt.replace(QRegExp("\r"), QChar(13));
 						txt.replace(QRegExp("\n"), QChar(13));
 						txt.replace(QRegExp("\t"), QChar(9));
-						b->itemText.insertChars(b->CPos, txt, true);
+						b->itemText.insertChars(txt, true);
 						if (Doc->docHyphenator->AutoCheck)
 							Doc->docHyphenator->slotHyphenate(b);
 						b->invalidateLayout();
@@ -1699,21 +1699,21 @@
 			if(currItem->reversed())
 			{ //handle Right to Left writing
 				FPoint point(currItem->width()-(pf.x() - currItem->xPos()), pf.y() - currItem->yPos());
-				currItem->CPos = currItem->itemText.length() == 0 ? 0 :
-					currItem->itemText.screenToPosition(point);
+				currItem->itemText.setCursorPosition( currItem->itemText.length() == 0 ? 0 :
+					currItem->itemText.screenToPosition(point) );
 			}
 			else
 			{
 				FPoint point(pf.x() - currItem->xPos(), pf.y() - currItem->yPos());
-				currItem->CPos = currItem->itemText.length() == 0 ? 0 :
-					currItem->itemText.screenToPosition(point);
+				currItem->itemText.setCursorPosition( currItem->itemText.length() == 0 ? 0 :
+					currItem->itemText.screenToPosition(point) );
 			}
 
 			if (currItem->itemText.length() > 0)
 			{
-				int b=qMin(currItem->CPos-1, currItem->itemText.length());
-				if (b<0)
-					b=0;
+				int b = qMin(currItem->itemText.cursorPosition() - 1, currItem->itemText.length());
+				if (b < 0)
+					b = 0;
 				Doc->currentStyle.charStyle() = currItem->itemText.charStyle(b);
 				emit ItemTextStrike(Doc->currentStyle.charStyle().strikethruOffset(), Doc->currentStyle.charStyle().strikethruWidth());
 				emit ItemTextUnderline(Doc->currentStyle.charStyle().underlineOffset(), Doc->currentStyle.charStyle().underlineWidth());

Modified: branches/Version135/Scribus/scribus/scribusview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/scribusview.h
==============================================================================
--- branches/Version135/Scribus/scribus/scribusview.h (original)
+++ branches/Version135/Scribus/scribus/scribusview.h Tue Jun  7 20:59:18 2011
@@ -233,7 +233,7 @@
 	void setScale(const double newScale);
 	double scale() const;
 
-	virtual void changed(QRectF re);
+	virtual void changed(QRectF re, bool);
 
 	void updateCanvas(QRectF box = QRectF());
 	void updateCanvas(double x, double y, double width, double height) { updateCanvas(QRectF(x,y,width,height)); }

Modified: branches/Version135/Scribus/scribus/search.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/search.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/search.cpp (original)
+++ branches/Version135/Scribus/scribus/search.cpp Tue Jun  7 20:59:18 2011
@@ -397,7 +397,7 @@
 	if (sText.length() > 0)
 		found = false;
 	int inde = 0;
-	uint as = Item->CPos;
+	uint as = Item->itemText.cursorPosition();
 	ReplStart = as;
 	int a;
 	if (SMode)
@@ -466,7 +466,7 @@
 					DoReplace->setEnabled(true);
 					AllReplace->setEnabled(true);
 				}
-				Item->CPos = a+1;
+				Item->itemText.setCursorPosition(a+1);
 				if (SText->isChecked())
 				{
 					if (inde == 0)
@@ -513,7 +513,7 @@
 			DoReplace->setEnabled(false);
 			AllReplace->setEnabled(false);
 			QMessageBox::information(this, tr("Search/Replace"), tr("Search finished"), CommonStrings::tr_OK);
-			Item->CPos = 0;
+			Item->itemText.setCursorPosition(0);
 			NotFound = false;
 		}
 	}
@@ -657,14 +657,12 @@
 					for (cx = cs; cx < repl.length(); ++cx)
 						Item->itemText.insertChars(ReplStart+cx, repl.mid(cx,1), true); 
 					// FIXME:NLS also replace styles!!
-					Item->CPos = ReplStart+cx;
 				}
 				else
 				{
 					for (cs = 0; cs < repl.length(); ++cs)
 						Item->itemText.replaceChar(ReplStart+cs, repl[cs]);
 					Item->itemText.removeChars(ReplStart+cs, sear.length() - cs);
-					Item->CPos = ReplStart+cs;
 				}
 			}
 		}

Modified: branches/Version135/Scribus/scribus/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/storyeditor.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/storyeditor.cpp (original)
+++ branches/Version135/Scribus/scribus/storyeditor.cpp Tue Jun  7 20:59:18 2011
@@ -564,7 +564,6 @@
 
 void SEditor::saveItemText(PageItem *currItem)
 {
-	currItem->CPos = 0;
 	currItem->itemText.clear();
 	currItem->itemText.setDefaultStyle(StyledText.defaultStyle());
 	currItem->itemText.append(StyledText);
@@ -629,11 +628,11 @@
 	updateAll();
 	int npars = currItem->itemText.nrOfParagraphs();
 	SelParaStart = 0;
-	while (currItem->CPos >= (SelCharStart = currItem->itemText.endOfParagraph(SelParaStart))
+	while (currItem->itemText.cursorPosition() >= (SelCharStart = currItem->itemText.endOfParagraph(SelParaStart))
 		   && SelParaStart < npars)
 		++SelParaStart;
-	if (currItem->CPos < SelCharStart)
-		SelCharStart = currItem->CPos;
+	if (currItem->itemText.cursorPosition() < SelCharStart)
+		SelCharStart = currItem->itemText.cursorPosition();
 	SelCharStart -= currItem->itemText.startOfParagraph(SelParaStart);
 	StoredSel = false;
 	//qDebug() << "SE::loadItemText: cursor";
@@ -2861,7 +2860,6 @@
 			}
 		}
 		nb2->itemText.clear();
-			nb2->CPos = 0;
 			nb2->Dirty = false;
 			nb2 = nb2->nextInChain();
 		}

Modified: branches/Version135/Scribus/scribus/text/sctext_shared.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/text/sctext_shared.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/text/sctext_shared.cpp (original)
+++ branches/Version135/Scribus/scribus/text/sctext_shared.cpp Tue Jun  7 20:59:18 2011
@@ -19,7 +19,7 @@
 ScText_Shared::ScText_Shared(const StyleContext* pstyles) : QList<ScText*>(), 
 	defaultStyle(), 
 	pstyleContext(NULL),
-	refs(1), len(0), trailingStyle()
+	refs(1), len(0), cursorPosition(0), trailingStyle()
 {
 	pstyleContext.setDefaultStyle( & defaultStyle );
 	defaultStyle.setContext( pstyles );
@@ -32,7 +32,8 @@
 ScText_Shared::ScText_Shared(const ScText_Shared& other) : QList<ScText*>(), 
 	defaultStyle(other.defaultStyle), 
 	pstyleContext(other.pstyleContext),
-	refs(1), len(0), trailingStyle(other.trailingStyle)
+	refs(1), len(0), cursorPosition(other.cursorPosition),
+	trailingStyle(other.trailingStyle)
 {
 	pstyleContext.setDefaultStyle( &defaultStyle );
 	trailingStyle.setContext( &pstyleContext );
@@ -58,15 +59,16 @@
 	while(!this->isEmpty())
 		delete this->takeFirst(); 
 	QList<ScText*>::clear();
+	cursorPosition = 0;
 }
 
 ScText_Shared& ScText_Shared::operator= (const ScText_Shared& other) 
 {
 	if (this != &other) 
 	{
-		defaultStyle = other.defaultStyle;
-		trailingStyle = other.trailingStyle;
-		pstyleContext = other.pstyleContext;
+		defaultStyle   = other.defaultStyle;
+		trailingStyle  = other.trailingStyle;
+		pstyleContext  = other.pstyleContext;
 		pstyleContext.setDefaultStyle( &defaultStyle );
 		defaultStyle.setContext( other.defaultStyle.context() );
 		trailingStyle.setContext( &pstyleContext );
@@ -87,6 +89,7 @@
 			}
 		}
 		len = count();
+		cursorPosition = other.cursorPosition;
 		pstyleContext.invalidate();
 //			qDebug() << QString("StoryText::copy: %1 align=%2 %3").arg(trailingStyle.parentStyle()->name())
 //				   .arg(trailingStyle.alignment()).arg((uint)trailingStyle.context());

Modified: branches/Version135/Scribus/scribus/text/sctext_shared.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/text/sctext_shared.h
==============================================================================
--- branches/Version135/Scribus/scribus/text/sctext_shared.h (original)
+++ branches/Version135/Scribus/scribus/text/sctext_shared.h Tue Jun  7 20:59:18 2011
@@ -21,6 +21,7 @@
 	StyleContextProxy pstyleContext;
 	uint refs;
 	uint len;
+	uint cursorPosition;
 	ParagraphStyle trailingStyle;
 	ScText_Shared(const StyleContext* pstyles);	
 

Modified: branches/Version135/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/text/storytext.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/text/storytext.cpp (original)
+++ branches/Version135/Scribus/scribus/text/storytext.cpp Tue Jun  7 20:59:18 2011
@@ -163,6 +163,27 @@
 	return *this;
 }
 
+int StoryText::cursorPosition() const
+{
+	return d->cursorPosition;
+}
+
+void StoryText::setCursorPosition(int pos, bool relative)
+{
+	if (relative)
+		pos += d->cursorPosition;
+	d->cursorPosition = qMin((uint) qMax(pos, 0), d->len);
+}
+
+void StoryText::normalizeCursorPosition()
+{
+	d->cursorPosition = qMax((uint) 0, qMin(d->cursorPosition, d->len));
+}
+
+int StoryText::normalizedCursorPosition()
+{
+	return (int) qMax((uint) 0, qMin(d->cursorPosition, d->len));
+}
 
 void StoryText::clear()
 {
@@ -180,6 +201,10 @@
 	invalidateAll();
 }
 
+void StoryText::insert(const StoryText& other, bool onlySelection)
+{
+	insert(d->cursorPosition, other, onlySelection);
+}
 
 void StoryText::insert(int pos, const StoryText& other, bool onlySelection)
 {
@@ -313,15 +338,22 @@
 		// consistent in functions such as select()
 		if (i <= selLast) --selLast;
 		if (i < selFirst) --selFirst;
+		if ((i + 1 ) <= d->cursorPosition && d->cursorPosition > 0) d->cursorPosition -= 1;
 	}
 
 	d->len = d->count();
+	d->cursorPosition = qMin(d->cursorPosition, d->len);
 	if (selFirst > selLast)
 	{
 		selFirst =  0;
 		selLast  = -1;
 	}
 	invalidate(pos, length());
+}
+
+void StoryText::insertChars(QString txt, bool applyNeighbourStyle) //, const CharStyle & charstyle)
+{
+	insertChars(d->cursorPosition, txt, applyNeighbourStyle);
 }
 
 void StoryText::insertChars(int pos, QString txt, bool applyNeighbourStyle) //, const CharStyle & charstyle)
@@ -354,6 +386,9 @@
 		if (item->ch == SpecialChars::PARSEP) {
 //			qDebug() << QString("new PARSEP %2 at %1").arg(pos).arg(paragraphStyle(pos).name());
 			insertParSep(pos + i);
+		}
+		if (d->cursorPosition >= (pos + i)) {
+			d->cursorPosition += 1;
 		}
 	}
 
@@ -409,6 +444,9 @@
 			if (item->ch == SpecialChars::PARSEP) {
 				insertParSep(index);
 			}
+			if (d->cursorPosition >= index) {
+				d->cursorPosition += 1;
+			}
 			++inserted;
 		}
 	}
@@ -461,6 +499,11 @@
 	invalidate(pos, pos + len);
 }
 
+void StoryText::insertObject(PageItem* ob)
+{
+	insertObject(d->cursorPosition, ob);
+}
+
 void StoryText::insertObject(int pos, PageItem* ob)
 {
 	if (pos < 0)
@@ -475,6 +518,11 @@
 int StoryText::length() const
 {
 	return d->len;
+}
+
+QChar StoryText::text() const
+{
+	return text(d->cursorPosition);
 }
 
 QChar StoryText::text(int pos) const
@@ -553,6 +601,10 @@
 	return that->d->at(pos)->embedded.getItem();
 }
 
+const CharStyle & StoryText::charStyle() const
+{
+	return charStyle(d->cursorPosition);
+}
 
 const CharStyle & StoryText::charStyle(int pos) const
 {
@@ -575,6 +627,11 @@
 	
 	StoryText* that = const_cast<StoryText *>(this);
 	return dynamic_cast<const CharStyle &> (*that->d->at(pos));
+}
+
+const ParagraphStyle & StoryText::paragraphStyle() const
+{
+	return paragraphStyle(d->cursorPosition);
 }
 
 const ParagraphStyle & StoryText::paragraphStyle(int pos) const
@@ -873,6 +930,10 @@
 	replaceNamedResources(newnames);
 }
 
+uint StoryText::nrOfParagraph() const
+{
+	return nrOfParagraph(d->cursorPosition);
+}
 
 uint StoryText::nrOfParagraph(int pos) const
 {
@@ -903,6 +964,11 @@
 	return lastWasPARSEP ? result : result + 1;
 }
 
+int StoryText::startOfParagraph() const
+{
+	return startOfParagraph(nrOfParagraph());
+}
+
 int StoryText::startOfParagraph(uint index) const
 {
 	if (index == 0)
@@ -915,6 +981,11 @@
 			return i + 1;
 	}
 	return length();
+}
+
+int StoryText::endOfParagraph() const
+{
+	return endOfParagraph(nrOfParagraph());
 }
 
 int StoryText::endOfParagraph(uint index) const

Modified: branches/Version135/Scribus/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16638&path=/branches/Version135/Scribus/scribus/text/storytext.h
==============================================================================
--- branches/Version135/Scribus/scribus/text/storytext.h (original)
+++ branches/Version135/Scribus/scribus/text/storytext.h Tue Jun  7 20:59:18 2011
@@ -102,19 +102,39 @@
 	virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
 	virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
 	
+	int  cursorPosition() const;
+	void setCursorPosition(int pos, bool relative = false);
+	void normalizeCursorPosition();
+	int  normalizedCursorPosition();
+
  	void clear();
 	StoryText copy() const;
+	// Insert chars from another StoryText object at current cursor position
+	void insert(const StoryText& other, bool onlySelection = false);
+	// Insert chars from another StoryText object at specific position
 	void insert(int pos, const StoryText& other, bool onlySelection = false);
+	// Append chars from another StoryText object
 	void append(const StoryText& other) { insert(length(), other, false); }
+	// Remove len chars at specific position
  	void removeChars(int pos, uint len);
+	// Insert chars at current cursor position
+	void insertChars(QString txt, bool applyNeighbourStyle = false);
+	// Insert chars ar specific position
  	void insertChars(int pos, QString txt, bool applyNeighbourStyle = false);
+	// Insert inline object at current cursor position
+	void insertObject(PageItem* obj);
+	// Insert object at specific position
  	void insertObject(int pos, PageItem* obj);
  	void replaceChar(int pos, QChar ch);
 
 	void hyphenateWord(int pos, uint len, char* hyphens);
 	
  	int length() const;
- 	QChar text(int pos) const;
+	// Get char at current cursor position
+	QChar   text() const;
+	// Get char at specific position
+ 	QChar   text(int pos) const;
+	// Get text with len chars at specific position
  	QString text(int pos, uint len) const;
 
 	bool hasObject(int pos) const;
@@ -129,7 +149,13 @@
 	int nextFramePos(int c);
 	int prevFramePos(int c);
 	
+	// Get charstyle at current cursor position
+	const CharStyle& charStyle() const;
+	// Get charstyle at specific position
  	const CharStyle& charStyle(int pos) const;
+	// Get paragraph style at current cursor position
+	const ParagraphStyle& paragraphStyle() const;
+	// Get paragraph style at specific position
  	const ParagraphStyle& paragraphStyle(int pos) const;
  	const ParagraphStyle& defaultStyle() const;
  	void setDefaultStyle(const ParagraphStyle& style);
@@ -146,8 +172,11 @@
 	void replaceNamedResources(ResourceCollection& newNames);
 	
  	uint nrOfParagraphs() const;
- 	int startOfParagraph(uint index) const;
- 	int endOfParagraph(uint index) const;
+	int  startOfParagraph() const;
+ 	int  startOfParagraph(uint index) const;
+	int  endOfParagraph() const;
+ 	int  endOfParagraph(uint index) const;
+	uint nrOfParagraph() const;
 	uint nrOfParagraph(int pos) const;
 
  	uint nrOfRuns() const;




More information about the scribus-commit mailing list