r16649 by jghali - merge trunk revisions up to r16646

scribus-commit scribus-commit at lists.scribus.net
Thu Jun 9 22:48:43 UTC 2011


Author: jghali
Date: Thu Jun  9 22:48:43 2011
New Revision: 16649

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16649
Log:
merge trunk revisions up to r16646

Modified:
    branches/ScribusOIF/scribus/canvasmode_edit.cpp
    branches/ScribusOIF/scribus/observable.h
    branches/ScribusOIF/scribus/pageitem_textframe.cpp
    branches/ScribusOIF/scribus/pdflib_core.cpp
    branches/ScribusOIF/scribus/plugins/import/ai/importai.cpp
    branches/ScribusOIF/scribus/plugins/import/cgm/importcgm.cpp
    branches/ScribusOIF/scribus/plugins/import/drw/importdrw.cpp
    branches/ScribusOIF/scribus/plugins/import/pct/importpct.cpp
    branches/ScribusOIF/scribus/plugins/import/shape/importshape.cpp
    branches/ScribusOIF/scribus/plugins/import/sml/importsml.cpp
    branches/ScribusOIF/scribus/plugins/import/wmf/wmfimport.cpp
    branches/ScribusOIF/scribus/plugins/import/wpg/importwpg.cpp
    branches/ScribusOIF/scribus/plugins/import/xar/importxar.cpp
    branches/ScribusOIF/scribus/plugins/import/xfig/importxfig.cpp
    branches/ScribusOIF/scribus/pslib.cpp
    branches/ScribusOIF/scribus/scribusdoc.cpp
    branches/ScribusOIF/scribus/scribusview.cpp
    branches/ScribusOIF/scribus/scribusview.h
    branches/ScribusOIF/scribus/text/sctext_shared.cpp
    branches/ScribusOIF/scribus/text/sctext_shared.h
    branches/ScribusOIF/scribus/text/storytext.cpp
    branches/ScribusOIF/scribus/text/storytext.h
    branches/ScribusOIF/scribus/text/storytext_shared.cpp
    branches/ScribusOIF/scribus/ui/about.cpp
    branches/ScribusOIF/scribus/ui/cupsoptions.cpp
    branches/ScribusOIF/scribus/util_printer.cpp

Modified: branches/ScribusOIF/scribus/canvasmode_edit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/canvasmode_edit.cpp
==============================================================================
--- branches/ScribusOIF/scribus/canvasmode_edit.cpp (original)
+++ branches/ScribusOIF/scribus/canvasmode_edit.cpp Thu Jun  9 22:48:43 2011
@@ -241,7 +241,7 @@
 		cPen.setCosmetic(true);
 
 		// normalize Current Position
-		textframe->itemText.setCursorPosition( qMax ( 0, qMin( textframe->itemText.cursorPosition(), textframe->itemText.length() ) ) );
+		textframe->itemText.normalizeCursorPosition();
 		int textCursorPos ( textframe->itemText.cursorPosition() );
 
 		bool cursorDirection(true); // true => LTR; false => RTL

Modified: branches/ScribusOIF/scribus/observable.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/observable.h
==============================================================================
--- branches/ScribusOIF/scribus/observable.h (original)
+++ branches/ScribusOIF/scribus/observable.h Thu Jun  9 22:48:43 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/ScribusOIF/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/pageitem_textframe.cpp
==============================================================================
--- branches/ScribusOIF/scribus/pageitem_textframe.cpp (original)
+++ branches/ScribusOIF/scribus/pageitem_textframe.cpp Thu Jun  9 22:48:43 2011
@@ -759,10 +759,10 @@
 	if (frameUnderflows())
 	{
 		itemText.setCursorPosition( itemText.length() );
-		m_Doc->view()->Deselect(true);
 		PageItem * jumpFrame = frameTextEnd();
 		if (jumpFrame)
 		{
+			m_Doc->view()->Deselect(true);
 			m_Doc->scMW()->selectItemsFromOutlines(jumpFrame);
 			m_Doc->scMW()->setTBvals(jumpFrame);
 			jumpFrame->update();
@@ -881,6 +881,8 @@
 		else if (kk == Qt::Key_Right) 
 			kk = Qt::Key_Left;
 	}
+
+	int oldLast = lastInFrame();
 	switch (kk)
 	{
 	case Qt::Key_Home:
@@ -1008,7 +1010,7 @@
 					{
 						view->Deselect(true);
 						// TODO position at the right place in previous frame
-						itemText.setCursorPosition( BackBox->lastInFrame() );
+						BackBox->itemText.setCursorPosition( BackBox->lastInFrame() );
 						m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 					}
 			}
@@ -1018,7 +1020,7 @@
 				if (BackBox != 0)
 				{
 					view->Deselect(true);
-					itemText.setCursorPosition( BackBox->lastInFrame() );
+					BackBox->itemText.setCursorPosition( BackBox->lastInFrame() );
 					m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 				}
 			}
@@ -1050,7 +1052,7 @@
 		{
 			int pos = itemText.cursorPosition();
 			itemText.setCursorPosition(-1, true);
-			if (pos > 0)
+			if ( pos > 0 )
 				ExpandSel(-1, oldPos);
 		}
 		else
@@ -1062,7 +1064,7 @@
 				if (BackBox != 0)
 				{
 					view->Deselect(true);
-					itemText.setCursorPosition( BackBox->lastInFrame() );
+					BackBox->itemText.setCursorPosition( BackBox->lastInFrame() );
 					m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 					//currItem = currItem->BackBox;
 				}
@@ -1149,7 +1151,7 @@
 			keyRepeat = false;
 			return;
 		}
-		cr = itemText.text(itemText.cursorPosition(), 1);
+		cr = itemText.text(1);
 		if (itemText.lengthOfSelection() == 0)
 			itemText.select(itemText.cursorPosition(), 1, true);
 		deleteSelectedTextFromFrame();
@@ -1189,12 +1191,17 @@
 //			m_Doc->chAbStyle(this, findParagraphStyle(m_Doc, itemText.paragraphStyle(qMax(CPos-1,0))));
 //			Tinput = false;
 		}
+		updateLayout();
+		if (oldLast != lastInFrame() && NextBox != 0 && !NextBox->textLayout->isValid())
+			NextBox->updateLayout();
 		if (itemText.cursorPosition() < firstInFrame())
 		{
 			itemText.setCursorPosition( firstInFrame() );
 			if (BackBox != 0)
 			{
 				view->Deselect(true);
+				if (!BackBox->textLayout->isValid())
+					BackBox->updateLayout();
 				itemText.setCursorPosition( BackBox->lastInFrame() );
 				m_Doc->scMW()->selectItemsFromOutlines(BackBox);
 				//currItem = currItem->BackBox;
@@ -1270,14 +1277,19 @@
 			doUpdate = true;
 		}
 		if (doUpdate)
-			update();
+		{
+			// 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->textLayout->isValid())
+				NextBox->updateLayout();
+		}
 		//check if cursor need to jump to next linked frame
-		if (lastInFrame() < (itemText.length() -2) && NextBox != 0)
+		if ((itemText.cursorPosition() > lastInFrame() + 1) && (lastInFrame() < (itemText.length() - 2)) && NextBox != 0)
 		{
 			view->Deselect(true);
-			//NextBox->CPos = CPos;
+			NextBox->update();
 			m_Doc->scMW()->selectItemsFromOutlines(NextBox);
-			NextBox->update();
 		}
 		break;
 	}

Modified: branches/ScribusOIF/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/pdflib_core.cpp
==============================================================================
--- branches/ScribusOIF/scribus/pdflib_core.cpp (original)
+++ branches/ScribusOIF/scribus/pdflib_core.cpp Thu Jun  9 22:48:43 2011
@@ -2003,10 +2003,7 @@
 								PutPage(tmpOut);
 							}
 							PutPage(SetClipPath(ite));
-							if (ite->fillRule)
-								PutPage("h\nf*\n");
-							else
-								PutPage("h\nf\n");
+							PutPage(ite->fillRule ? "h\nf*\n" : "h\nf\n");
 						}
 						PutPage("q\n");
 						if (ite->imageClip.size() != 0)
@@ -2177,20 +2174,14 @@
 							}
 							PutPage(tmpOut);
 							PutPage(SetClipPath(ite));
-							if (ite->fillRule)
-								PutPage("h\nf*\n");
-							else
-								PutPage("h\nf\n");
+							PutPage(ite->fillRule ? "h\nf*\n" : "h\nf\n");
 						}
 						else
 						{
 							if (ite->fillColor() != CommonStrings::None)
 							{
 								PutPage(SetClipPath(ite));
-								if (ite->fillRule)
-									PutPage("h\nf*\n");
-								else
-									PutPage("h\nf\n");
+								PutPage(ite->fillRule ? "h\nf*\n" : "h\nf\n");
 							}
 						}
 						PutPage("Q\n");
@@ -2269,20 +2260,14 @@
 								}
 								PutPage(tmpOut);
 								PutPage(SetClipPath(ite));
-								if (ite->fillRule)
-									PutPage("h\nf*\n");
-								else
-									PutPage("h\nf\n");
+								PutPage(ite->fillRule ? "h\nf*\n" : "h\nf\n");
 							}
 							else
 							{
 								if (ite->fillColor() != CommonStrings::None)
 								{
 									PutPage(SetClipPath(ite));
-									if (ite->fillRule)
-										PutPage("h\nf*\n");
-									else
-										PutPage("h\nf\n");
+									PutPage(ite->fillRule ? "h\nf*\n" : "h\nf\n");
 								}
 							}
 							PutPage("Q\n");
@@ -3671,18 +3656,12 @@
 					}
 					tmp += tmpOut;
 					tmp += SetClipPath(ite);
-					if (ite->fillRule)
-						tmp += "h\nf*\n";
-					else
-						tmp += "h\nf\n";
+					tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 				}
 				else
 				{
 					tmp += SetClipPath(ite);
-					if (ite->fillRule)
-						tmp += "h\nf*\n";
-					else
-						tmp += "h\nf\n";
+					tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 				}
 			}
 			tmp += "q\n";
@@ -3786,18 +3765,12 @@
 					}
 					tmp += tmpOut;
 					tmp += SetClipPath(ite);
-					if (ite->fillRule)
-						tmp += "h\nf*\n";
-					else
-						tmp += "h\nf\n";
+					tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 				}
 				else
 				{
 					tmp += SetClipPath(ite);
-					if (ite->fillRule)
-						tmp += "h\nf*\n";
-					else
-						tmp += "h\nf\n";
+					tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 				}
 			}
 			tmp += "q\n";
@@ -3956,20 +3929,14 @@
 				}
 				tmp += tmpOut;
 				tmp += SetClipPath(ite);
-				if (ite->fillRule)
-					tmp += "h\nf*\n";
-				else
-					tmp += "h\nf\n";
+				tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 			}
 			else
 			{
 				if (ite->fillColor() != CommonStrings::None)
 				{
 					tmp += SetClipPath(ite);
-					if (ite->fillRule)
-						tmp += "h\nf*\n";
-					else
-						tmp += "h\nf\n";
+					tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 				}
 			}
 			tmp += "Q\n";
@@ -4049,20 +4016,14 @@
 					}
 					tmp += tmpOut;
 					tmp += SetClipPath(ite);
-					if (ite->fillRule)
-						tmp += "h\nf*\n";
-					else
-						tmp += "h\nf\n";
+					tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 				}
 				else
 				{
 					if (ite->fillColor() != CommonStrings::None)
 					{
 						tmp += SetClipPath(ite);
-						if (ite->fillRule)
-							tmp += "h\nf*\n";
-						else
-							tmp += "h\nf\n";
+						tmp += (ite->fillRule ? "h\nf*\n" : "h\nf\n");
 					}
 				}
 				tmp += "Q\n";

Modified: branches/ScribusOIF/scribus/plugins/import/ai/importai.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/ai/importai.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/ai/importai.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/ai/importai.cpp Thu Jun  9 22:48:43 2011
@@ -424,6 +424,8 @@
 			importedColors.append(it.key());
 		}
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/cgm/importcgm.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/cgm/importcgm.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/cgm/importcgm.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/cgm/importcgm.cpp Thu Jun  9 22:48:43 2011
@@ -210,6 +210,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/drw/importdrw.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/drw/importdrw.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/drw/importdrw.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/drw/importdrw.cpp Thu Jun  9 22:48:43 2011
@@ -224,6 +224,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/pct/importpct.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/pct/importpct.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/pct/importpct.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/pct/importpct.cpp Thu Jun  9 22:48:43 2011
@@ -210,6 +210,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/shape/importshape.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/shape/importshape.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/shape/importshape.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/shape/importshape.cpp Thu Jun  9 22:48:43 2011
@@ -210,6 +210,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/sml/importsml.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/sml/importsml.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/sml/importsml.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/sml/importsml.cpp Thu Jun  9 22:48:43 2011
@@ -208,6 +208,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/wmf/wmfimport.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/wmf/wmfimport.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/wmf/wmfimport.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/wmf/wmfimport.cpp Thu Jun  9 22:48:43 2011
@@ -594,7 +594,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
-	m_Doc->view()->Deselect();
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;
 	if (!(flags & LoadSavePlugin::lfLoadAsPattern))

Modified: branches/ScribusOIF/scribus/plugins/import/wpg/importwpg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/wpg/importwpg.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/wpg/importwpg.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/wpg/importwpg.cpp Thu Jun  9 22:48:43 2011
@@ -570,6 +570,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/xar/importxar.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/xar/importxar.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/xar/importxar.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/xar/importxar.cpp Thu Jun  9 22:48:43 2011
@@ -315,6 +315,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/plugins/import/xfig/importxfig.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/plugins/import/xfig/importxfig.cpp
==============================================================================
--- branches/ScribusOIF/scribus/plugins/import/xfig/importxfig.cpp (original)
+++ branches/ScribusOIF/scribus/plugins/import/xfig/importxfig.cpp Thu Jun  9 22:48:43 2011
@@ -345,6 +345,8 @@
 			m_Doc->setPageOrientation(0);
 		m_Doc->setPageSize("Custom");
 	}
+	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
+		m_Doc->view()->Deselect();
 	Elements.clear();
 	m_Doc->setLoading(true);
 	m_Doc->DoDrawing = false;

Modified: branches/ScribusOIF/scribus/pslib.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/pslib.cpp
==============================================================================
--- branches/ScribusOIF/scribus/pslib.cpp (original)
+++ branches/ScribusOIF/scribus/pslib.cpp Thu Jun  9 22:48:43 2011
@@ -2067,6 +2067,7 @@
 			{
 				SetClipPath(&c->PoLine);
 				PS_closepath();
+				fillRule = c->fillRule;
 				if (c->GrType != 0)
 					HandleGradientFillStroke(c, gcr, false);
 				else

Modified: branches/ScribusOIF/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/scribusdoc.cpp
==============================================================================
--- branches/ScribusOIF/scribus/scribusdoc.cpp (original)
+++ branches/ScribusOIF/scribus/scribusdoc.cpp Thu Jun  9 22:48:43 2011
@@ -135,7 +135,7 @@
 		}
 	}
 	
-	void changed(Page* pg)
+	void changed(Page* pg, bool /*doLayout*/)
 	{
 		QRectF pagebox(pg->xOffset(), pg->yOffset(), pg->width(), pg->height());
 		doc->invalidateRegion(pagebox);
@@ -148,9 +148,11 @@
 		m_docChangeNeeded = true;
 	}
 	
-	void changed(PageItem* it)
+	void changed(PageItem* it, bool doLayout)
 	{
 		it->invalidateLayout();
+		if (doLayout)
+			it->layout();
 		doc->regionsChanged()->update(it->getVisualBoundingRect());
 		if (m_updateEnabled <= 0)
 		{
@@ -6952,7 +6954,7 @@
 				start = currItem->itemText.startOfSelection();
 				stop = currItem->itemText.endOfSelection();
 				if (start >= stop)
-					start = stop = qMax(0, qMin(currItem->itemText.length(), currItem->itemText.cursorPosition()));
+					start = stop = currItem->itemText.normalizedCursorPosition();
 			}
 			for (int pos=start; pos < stop; ++pos)
 			{
@@ -7006,7 +7008,7 @@
 				start = currItem->itemText.startOfSelection();
 				stop = currItem->itemText.endOfSelection();
 				if (start >= stop)
-					start = stop = qMax(0, qMin(currItem->itemText.length(), currItem->itemText.cursorPosition()));
+					start = stop = currItem->itemText.normalizedCursorPosition();
 			}
 			for (int pos=start; pos < stop; ++pos)
 			{
@@ -7070,7 +7072,7 @@
 				start = currItem->itemText.startOfSelection();
 				stop = currItem->itemText.endOfSelection();
 				if (start >= stop)
-					start = stop = qMax(0, qMin(currItem->itemText.length(), currItem->itemText.cursorPosition()));
+					start = stop = currItem->itemText.normalizedCursorPosition();
 			}
 			for (int pos=start; pos < stop; ++pos)
 			{
@@ -7126,7 +7128,7 @@
 				else
 				{
 					start = qMax(currItem->firstInFrame(), currItem->itemText.cursorPosition());
-					length = (start + 1) < currItem->itemText.length()? 1 : 0;
+					length = (start + 1) < currItem->itemText.length() ? 1 : 0;
 				}
 			}
 			currItem->itemText.applyCharStyle(start, qMax(0, length), newStyle);

Modified: branches/ScribusOIF/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/scribusview.cpp
==============================================================================
--- branches/ScribusOIF/scribus/scribusview.cpp (original)
+++ branches/ScribusOIF/scribus/scribusview.cpp Thu Jun  9 22:48:43 2011
@@ -460,7 +460,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);

Modified: branches/ScribusOIF/scribus/scribusview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/scribusview.h
==============================================================================
--- branches/ScribusOIF/scribus/scribusview.h (original)
+++ branches/ScribusOIF/scribus/scribusview.h Thu Jun  9 22:48:43 2011
@@ -212,7 +212,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/ScribusOIF/scribus/text/sctext_shared.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/text/sctext_shared.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/sctext_shared.cpp (original)
+++ branches/ScribusOIF/scribus/text/sctext_shared.cpp Thu Jun  9 22:48:43 2011
@@ -59,7 +59,6 @@
 {
 	if (this != &other) 
 	{
-		cursorPosition = other.cursorPosition;
 		defaultStyle   = other.defaultStyle;
 		trailingStyle  = other.trailingStyle;
 		pstyleContext  = other.pstyleContext;
@@ -83,6 +82,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/ScribusOIF/scribus/text/sctext_shared.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/text/sctext_shared.h
==============================================================================
--- branches/ScribusOIF/scribus/text/sctext_shared.h (original)
+++ branches/ScribusOIF/scribus/text/sctext_shared.h Thu Jun  9 22:48:43 2011
@@ -21,7 +21,7 @@
 	StyleContextProxy pstyleContext;
 	uint refs;
 	uint len;
-	uint  cursorPosition;
+	uint cursorPosition;
 	ParagraphStyle trailingStyle;
 	ScText_Shared(const StyleContext* pstyles);	
 

Modified: branches/ScribusOIF/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/text/storytext.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/storytext.cpp (original)
+++ branches/ScribusOIF/scribus/text/storytext.cpp Thu Jun  9 22:48:43 2011
@@ -116,6 +116,25 @@
 	return *this;
 }
 
+int StoryText::cursorPosition() const
+{
+	return data->cursorPosition();
+}
+
+void StoryText::setCursorPosition(int pos, bool relative)
+{
+	data->setCursorPosition(pos, relative);
+}
+
+void StoryText::normalizeCursorPosition()
+{
+	data->setCursorPosition( qMax(0, qMin(data->cursorPosition(), data->length())) );
+}
+
+int StoryText::normalizedCursorPosition()
+{
+	return qMax(0, qMin(data->cursorPosition(), data->length()));
+}
 
 void StoryText::clear()
 {
@@ -277,7 +296,7 @@
 		// 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;
+		if ((i + 1 ) <= d->cursorPosition && d->cursorPosition > 0) d->cursorPosition -= 1;
 	}
 */
 	if (selFirst > selLast)
@@ -425,16 +444,6 @@
 	invalidate(pos, pos + 1);
 }
 
-int StoryText::cursorPosition() const
-{
-	return data->cursorPosition();
-}
-
-void StoryText::setCursorPosition(int pos, bool relative)
-{
-	data->setCursorPosition(pos, relative);
-}
-
 void StoryText::hyphenateWord(int pos, uint len, char* hyphens, bool doUpdate)
 {
 	assert(pos >= 0);
@@ -592,6 +601,11 @@
 		return paragraphStyle(pos).charStyle();
 	
 	return data->charStyle(pos);
+}
+
+const ParagraphStyle & StoryText::paragraphStyle() const
+{
+	return paragraphStyle(data->cursorPosition());
 }
 
 const ParagraphStyle & StoryText::paragraphStyle(int pos) const

Modified: branches/ScribusOIF/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/text/storytext.h
==============================================================================
--- branches/ScribusOIF/scribus/text/storytext.h (original)
+++ branches/ScribusOIF/scribus/text/storytext.h Thu Jun  9 22:48:43 2011
@@ -98,28 +98,42 @@
 	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);
 
-	int  cursorPosition() const;
-	void setCursorPosition(int pos, bool relative = false);
-
 	void hyphenateWord(int pos, uint len, char* hyphens, bool doUpdate = true);
 	void selfHyphenateWord(int pos, uint len);
 	
  	virtual int length() const;
+	// Get char at current cursor position
 	virtual QChar   text() const;
+	// Get char at specific position
  	virtual QChar   text(int pos) const;
+	// Get text with len chars at specific position
  	virtual QString text(int pos, uint len) const;
+	// Get word at specific position
 	virtual QString wordAt(int pos) const;
 	virtual TextFlags& charAttributes(int pos);
 	virtual const TextFlags& charAttributes(int pos) const;
@@ -136,8 +150,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
+	virtual const ParagraphStyle& paragraphStyle() const;
+	// Get paragraph style at specific position
  	virtual const ParagraphStyle& paragraphStyle(int pos) const;
  	const ParagraphStyle& defaultStyle() const;
  	void setDefaultStyle(const ParagraphStyle& style);

Modified: branches/ScribusOIF/scribus/text/storytext_shared.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/text/storytext_shared.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/storytext_shared.cpp (original)
+++ branches/ScribusOIF/scribus/text/storytext_shared.cpp Thu Jun  9 22:48:43 2011
@@ -1,713 +1,713 @@
-/*
- *  storytext_shared.cpp
- *  ScribusProject
- *
- *  Created by Andreas Vox on 30.11.09.
- *  Copyright 2009 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "storytext_shared.h"
-
-#include <QDebug>
-#include <QString>
-#include "text/specialchars.h"
-#include "pageitem.h"
-#include "scribusdoc.h"
-
-class StoryText;
-
-ParagraphData::ParagraphData()
-{
-	style = ParagraphStyle();
-	text = QString("");
-	charAttr.clear();
-}
-
-ParagraphData& ParagraphData::operator=(const ParagraphData& o)
-{
-	style = o.style;;
-	text = o.text;
-	charAttr = o.charAttr;
-	return *this;
-}
-	
-Storytext_Shared::Storytext_Shared() : QSharedData(), doc(NULL) 
-{
-	uint i0 = pars.insert(0);
-	ParagraphData p0;
-	paragraphs.insert(i0, p0);
-	
-	uint r0 = runs.insert(0);
-	CharStyle c0;
-	charstyles.insert(r0, c0);
-}
-
-Storytext_Shared::Storytext_Shared(const Storytext_Shared& other) : QSharedData(other),
-
-	doc(other.doc), 
-	
-	pars(other.pars),
-	paragraphs(other.paragraphs),
-	
-	runs(other.runs),
-	charstyles(other.charstyles),
-	
-	tags(other.tags),
-	xml(other.xml),
-	
-	objs(other.objs),
-	objects(objects)
-{
-	// TODO: fix style contexts
-	undoList.clear();	
-}
-
-ScribusDoc* Storytext_Shared::document() const
-{
-	return doc;
-}
-
-void Storytext_Shared::setDocument(ScribusDoc* doc)
-{
-	this->doc = doc;
-	const StyleContext* pcon = NULL;
-	const StyleContext* chcon = NULL;
-	if (doc != NULL)
-	{
-		pcon = &(doc->paragraphStyles());
-		chcon = &(doc->charStyles());
-	}
-	for (int p=0; p < paragraphs.count(); ++p)
-	{
-		paragraphs[p].style.setContext(pcon);
-	}
-	for (int i=0; i < charstyles.count(); ++i)
-	{
-		charstyles[i].setContext(chcon);
-	}
-	//FIXME: update stuff assert(0);
-}
-
-
-int  Storytext_Shared::cursorPosition()
-{
-	return this->cursorPos;
-}
-
-
-void Storytext_Shared::setCursorPosition(int pos, bool relative)
-{
+/*
+ *  storytext_shared.cpp
+ *  ScribusProject
+ *
+ *  Created by Andreas Vox on 30.11.09.
+ *  Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "storytext_shared.h"
+
+#include <QDebug>
+#include <QString>
+#include "text/specialchars.h"
+#include "pageitem.h"
+#include "scribusdoc.h"
+
+class StoryText;
+
+ParagraphData::ParagraphData()
+{
+	style = ParagraphStyle();
+	text = QString("");
+	charAttr.clear();
+}
+
+ParagraphData& ParagraphData::operator=(const ParagraphData& o)
+{
+	style = o.style;;
+	text = o.text;
+	charAttr = o.charAttr;
+	return *this;
+}
+	
+Storytext_Shared::Storytext_Shared() : QSharedData(), doc(NULL) 
+{
+	uint i0 = pars.insert(0);
+	ParagraphData p0;
+	paragraphs.insert(i0, p0);
+	
+	uint r0 = runs.insert(0);
+	CharStyle c0;
+	charstyles.insert(r0, c0);
+}
+
+Storytext_Shared::Storytext_Shared(const Storytext_Shared& other) : QSharedData(other),
+
+	doc(other.doc), 
+	
+	pars(other.pars),
+	paragraphs(other.paragraphs),
+	
+	runs(other.runs),
+	charstyles(other.charstyles),
+	
+	tags(other.tags),
+	xml(other.xml),
+	
+	objs(other.objs),
+	objects(objects)
+{
+	// TODO: fix style contexts
+	undoList.clear();	
+}
+
+ScribusDoc* Storytext_Shared::document() const
+{
+	return doc;
+}
+
+void Storytext_Shared::setDocument(ScribusDoc* doc)
+{
+	this->doc = doc;
+	const StyleContext* pcon = NULL;
+	const StyleContext* chcon = NULL;
+	if (doc != NULL)
+	{
+		pcon = &(doc->paragraphStyles());
+		chcon = &(doc->charStyles());
+	}
+	for (int p=0; p < paragraphs.count(); ++p)
+	{
+		paragraphs[p].style.setContext(pcon);
+	}
+	for (int i=0; i < charstyles.count(); ++i)
+	{
+		charstyles[i].setContext(chcon);
+	}
+	//FIXME: update stuff assert(0);
+}
+
+
+int  Storytext_Shared::cursorPosition()
+{
+	return this->cursorPos;
+}
+
+
+void Storytext_Shared::setCursorPosition(int pos, bool relative)
+{
 	if (relative)
-		pos += this->cursorPos;
-	this->cursorPos = qMin(qMax(pos, 0), this->length());
-}
-
-
-int Storytext_Shared::length() const
-{
-	return pars.offset(pars.count());
-}
-
-
-QChar Storytext_Shared::text(int pos) const
-{
-	assert( pos >= 0 && pos < length());
-
-	int idx = pars[pos];
-	return paragraphs[idx].text[pos - pars.offset(idx)];
-}
-
-
-QString Storytext_Shared::text(int pos, uint len) const
-{
-	//assert( pos >= 0 && pos + signed(len) <= length());
-	// correct values rather than assert, could lead to artifacts but well, it's better than a crash.
-	if(0 == len)
-		return QString();
-	int cpos(qMax(0, pos));
-	int clen(len);
-	if(cpos + len > length())
-		clen = length() - cpos ;
-	int idx1 = pars[cpos];
-	int idx2 = pars[cpos + clen - 1];
-	//qDebug() << "text(" << pos << "," << len << ") from" << idx1 << "," << idx2;
-	if (idx1 == idx2)
-		return paragraphs[idx1].text.mid(cpos - pars.offset(idx1), clen);
-	else
-	{
-		//for (int j=idx1; j <= idx2; ++j)
-		//	qDebug() << "text() par" << j << paragraphs[j].text << "\n\n___";
-		
-		QString result = paragraphs[idx1].text.mid(cpos - pars.offset(idx1));
-		for (int i = idx1 + 1; i < idx2; ++i)
-			result.append(paragraphs[i].text);
-		result.append(paragraphs[idx2].text.left(cpos + clen - pars.offset(idx2)));
-		//qDebug() << result.length() << result;
-		assert(result.length() == signed(clen));
-		return result;
-	}
-}
-
-
-TextFlags& Storytext_Shared::charAttributes(int pos)
-{
-	assert( pos >= 0 && pos < length());
-	
-	int idx = pars[pos];
-	return paragraphs[idx].charAttr[pos - pars.offset(idx)];
-}
-
-
-const TextFlags& Storytext_Shared::charAttributes(int pos) const
-{
-	assert( pos >= 0 && pos < length());
-
-	int idx = pars[pos];
-	return paragraphs[idx].charAttr[pos - pars.offset(idx)];
-}
-
-
-
-int Storytext_Shared::xmlStart(int pos) const
-{
-	uint tg = tags[pos];
-	return tg <= tags.count()? tags.offset(tg) : -1;
-}
-
-int Storytext_Shared::xmlEnd(int pos) const
-{
-	uint strt = tags[pos];
-	if (strt < tags.count())
-		return tags.offset(xml[strt].matchingTagIndex);
-	else
-		return -1;
-}
-
-const QMap<QString, QString> Storytext_Shared::xmlAttributes(int pos) const
-{
-	if (text(pos) == SpecialChars::START_TAG || text(pos) == SpecialChars::EMPTY_TAG)
-	{
-		uint idx = tags[pos];
-		return idx < tags.count()? xml[idx].attr : QMap<QString,QString>();
-	}
-	else
-	{
-		return QMap<QString,QString>();
-	}
-}
-
-QString Storytext_Shared::xmlName(int pos) const
-{
-	if (text(pos) == SpecialChars::START_TAG || text(pos) == SpecialChars::EMPTY_TAG)
-	{
-		uint idx = tags[pos];
-		return idx < tags.count()? xml[idx].name : QString("?");
-	}
-	else
-	{
-		return QString();
-	}
-}
-
-
-
-InlineFrame Storytext_Shared::object(int pos) const
-{
-	int idx = objs[pos];
-	if (idx < objects.count())
-		return objects[idx];
-	else
-		return InlineFrame(NULL);
-}
-
-
-const CharStyle& Storytext_Shared::charStyle(int pos) const
-{
-	assert( pos >= 0 && pos < length() );
-
-	int idx = runs[pos];
-	return charstyles[idx];
-}
-
-
-const ParagraphStyle& Storytext_Shared::paragraphStyle(int pos) const
-{
-	int idx = pars[pos];
-	return paragraphs[idx].style;
-}
-
-
-uint Storytext_Shared::nrOfParagraphs() const
-{
-	return pars.count();
-}
-
-uint Storytext_Shared::nrOfParagraph(int pos) const
-{
-	return pars[pos];
-}
-
-
-int Storytext_Shared::startOfParagraph(uint index) const
-{
-	return pars.offset(index);
-}
-
-
-int Storytext_Shared::endOfParagraph(uint index) const
-{
-	return pars.end(index);
-}
-
-
-uint Storytext_Shared::nrOfRuns() const
-{
-	return runs.count();
-}
-
-
-int Storytext_Shared::startOfRun(uint index) const
-{
-	return runs.offset(index);
-}
-
-
-int Storytext_Shared::endOfRun(uint index) const
-{
-	return runs.end(index);
-}
-
-
-void Storytext_Shared::replaceChars(QString txt, int pos, uint len)
-{
-	uint idx = pars[pos];
-	for (int i = 0; i < txt.length(); ++i)
-	{
-		int c = txt[i].unicode();
-		if (c < 32 && c != 13)
-			qDebug() << "replaceChars: found non printable" << txt[i].unicode() << "at" << i;
-	}
-	
-	
-	uint idx2 = pars[pos+len];
-	for (uint p = idx2; p > idx; )
-	{
-		--p;
-		joinPar(p);
-	}
-	
-	assert(pars.offset(idx) <= pos && pos <= pars.end(idx));	
-
-	uint r1 = runs[pos];
-	uint r2 = runs[pos+len];
-	for (uint r= r2; r > r1; )
-	{
-		--r;
-		joinRun(r);
-	}
-	
-	//qDebug() << "replaceChars:" << txt << "\n\n_____" << pos << len << "in par" << idx;
-
-	ParagraphData& par(paragraphs[idx]);
-	
-	assert (par.text.length() == par.charAttr.count());
-	assert (par.text.length() == pars.length(idx));
-	
-	if (txt.length() > 0 || len > 0)
-	{
-		par.text.replace(pos - pars.offset(idx), len, txt);
-	}
-	if (len > 0)
-	{
-		par.charAttr.remove(pos - pars.offset(idx), len);
-	}
-	if (txt.length() > 0)
-	{
-		par.charAttr.insert(pos - pars.offset(idx), txt.length(), 0);
-	}
-	adjust(pos, txt.length() - len);
-	
-	int pos2 = pos + txt.length();
-	for (int i = pos; i < pos2; ++i)
-	{
-		if (text(i) == SpecialChars::PARSEP)
-			splitPar(i, false);
-	}
-
-	if (this->cursorPos >= pos)
-	{
-		this->cursorPos = qMax(pos, this->cursorPos - (int) len)+ txt.length();
-	}
-}
-
-
-void Storytext_Shared::insertTag(QString name, int pos, uint len)
-{
-	uint end = newTag(pos+len, SpecialChars::END_TAG);
-	uint start = newTag(pos, SpecialChars::START_TAG);
-	xml[start].name = name;
-	xml[start].matchingTagIndex = end;
-	xml[end].matchingTagIndex = start;
-}
-
-
-void Storytext_Shared::insertEmptyTag(QString name, int pos)
-{
-	uint start = newTag(pos, SpecialChars::EMPTY_TAG);
-	xml[start].name = name;
-	xml[start].matchingTagIndex = start;
-}
-
-
-void Storytext_Shared::setXmlAttributes(int pos, QMap<QString, QString> attr)
-{
-	if (text(pos) == SpecialChars::START_TAG)
-	{
-		uint idx = tags[pos];
-		xml[idx].attr = attr;
-	}
-}
-
-
-void Storytext_Shared::insertObject(InlineFrame obj, int pos)
-{
-	uint idx = objs.insert(pos);
-	objects.insert((int)idx, obj);
-	insertChar(pos, SpecialChars::OBJECT);
-}
-	
-
-void Storytext_Shared::clear(int start, int end)
-{
-	if (end < 0)
-		end = length();
-		
-	//FIXME: remove objects and tags
-	replaceChars(QString(""), start, end - start);
-}
-
-
-void Storytext_Shared::insert(int pos, const Storytext_Shared& other, int start, int end)
-{
-	if (end < 0)
-		end = other.length();
-
-	uint firstRun = splitRun(pos);
-	
-	uint idx1 = other.pars[start];
-	uint idx2 = other.pars[end];
-	uint destPar = pars[pos];
-	if (idx1 != idx2)
-	{
-		destPar = splitPar(pos, false);
-		replaceChars(other.text(start, end-start), pos, 0);
-		int p = pos;
-		for (uint i = 0; i < idx2 - idx1; ++i)
-		{
-			const ParagraphData& par( other.paragraphs[idx1 + i] );
-			paragraphs[destPar + i].style = par.style;
-		}
-	}
-	else
-	{
-		replaceChars(other.text(start, end-start), pos, 0);
-	}
-	for (int i=pos; i < pos + end-start; ++i)
-	{
-		if (text(i) == SpecialChars::OBJECT)
-		{
-			qDebug() << "insert Object at" << i; 
-			uint idx = objs.insert(pos);
-			objects.insert((int)idx, other.object(i - pos + start));
-		}
-		else if (text(i) == SpecialChars::START_TAG ||
-			text(i) ==  SpecialChars::END_TAG ||
-			text(i) ==  SpecialChars::EMPTY_TAG)
-		{
-			qDebug() << "insert XML tag" << text(i).unicode() << "at" << i; 
-			uint idxSrc = other.tags[i - pos + start];
-			uint idx = tags.insert(pos);
-			xml.insert((int)idx, other.xml[idxSrc]);
-		}
-	}
-	idx1 = other.runs[start];
-	idx2 = other.runs[end];
-	for (uint r=idx1; r < idx2; ++r)
-	{
-		int len = other.runs.length(r);
-		qDebug() << "other.runs" << r << "of" << other.charstyles.count() << "len" << len << "@" << pos;
-		setStyle(other.charstyles[r], pos, len);
-		pos += len;
-	}
-}
-
-
-void Storytext_Shared::setStyle(const CharStyle& style, int pos, uint len)
-{
-	uint idx1 = splitRun(pos);
-	uint idx2 = splitRun(pos+len);
-	qDebug() << "setStyle" << idx1 << idx2 << "of" << charstyles.count() << "@" << pos << ".." << len;
-	charstyles[idx1] = style;
-	for (uint i = idx1 + 1; i < idx2; ++i)
-		charstyles.removeAt(idx1 + 1);
-}
-
-void Storytext_Shared::setStyle(const ParagraphStyle& style, int pos, uint len)
-{
-	uint idx1 = pars[pos];
-	uint idx2 = pars[pos+len];
-	if (pars.offset(idx2) < pos + (signed) len)
-		++idx2;
-	for (uint i = idx1; i < idx2; ++i)
-		paragraphs[i].style = style;
-}
-
-void Storytext_Shared::applyStyle(const CharStyle& style, int pos, uint len)
-{
-	uint idx1 = splitRun(pos);
-	uint idx2 = splitRun(pos+len);
-	for (uint i = idx1; i < idx2; ++i)
-		charstyles[i].applyCharStyle(style);
-}
-
-void Storytext_Shared::applyStyle(const ParagraphStyle& style, int pos, uint len)
-{
-	uint idx1 = pars[pos];
-	uint idx2 = pars[pos+len];
-	if (pars.offset(idx2) < pos + (signed) len)
-		++idx2;
-	for (uint i = idx1; i < idx2; ++i)
-		paragraphs[i].style.applyStyle(style);	
-}
-
-void Storytext_Shared::eraseStyle(const CharStyle& style, int pos, uint len)
-{
-	uint idx1 = splitRun(pos);
-	uint idx2 = splitRun(pos+len);
-	for (uint i = idx1; i < idx2; ++i)
-		charstyles[i].eraseCharStyle(style);
-}
-
-void Storytext_Shared::eraseStyle(const ParagraphStyle& style, int pos, uint len)
-{
-	uint idx1 = pars[pos];
-	uint idx2 = pars[pos+len];
-	if (pars.offset(idx2) < pos + (signed) len)
-		++idx2;
-	for (uint i = idx1; i < idx2; ++i)
-		paragraphs[i].style.eraseStyle(style);
-}
-
-
-void Storytext_Shared::getNamedResources(ResourceCollection& lists) const
-{
-	for (int i=0; i < length(); ++i)
-	{
-		if (text(i) == SpecialChars::PARSEP)
-			paragraphStyle(i).getNamedResources(lists);
-		else if (text(i) == SpecialChars::OBJECT)
-			object(i).getItem()->getNamedResources(lists);
-		else
-			charStyle(i).getNamedResources(lists);
-	}
-	
-}
-
-void Storytext_Shared::replaceNamedResources(ResourceCollection& newNames)
-{
-	int len = length();
-	
-	if (len == 0)
-		return;
-	/*
-	 //	ScText* itText;
-	 for (int i=0; i < len; ++i) {
-	 itText = d->at(i);
-	 if (itText->parstyle)
-	 itText->parstyle->replaceNamedResources(newNames);
-	 else
-	 itText->replaceNamedResources(newNames);
-	 }
-	 */
-	invalidate(0, len);	
-	
-}
-	
-
-
-// positioning
-int Storytext_Shared::nextChar(int pos) const
-{
-	// skips tags, objects and parseps
-	return -1; 
-}
-
-int Storytext_Shared::prevChar(int pos) const
-{
-	// skips tags, objects and parseps
-	return -1;
-}
-
-int Storytext_Shared::nextWord(int pos) const
-{
-	// using charAttr
-	return -1; 
-}
-
-int Storytext_Shared::prevWord(int pos) const
-{
-	// using charAttr
-	return -1; 
-}
-
-int Storytext_Shared::nextPattern(int pos, const QRegExp& pat) const
-{
-	// returns pos of a match or -1. pat.pos() indices will be relative to paragraph start
-	return -1;
-}
-
-int Storytext_Shared::prevPattern(int pos, const QRegExp& pat) const
-{
-	// returns pos of a match or -1. pat.pos() indices will be relative to paragraph start
-	return -1;
-}
-
-int Storytext_Shared::nextParagraph(int pos) const
-{
-	uint idx = pars[pos] + 1;
-	if (idx < pars.count())
-		return pars.offset(idx);
-	return -1;
-}
-
-int Storytext_Shared::prevParagraph(int pos) const
-{
-	int idx = pars[pos] - 1;
-	if (idx >= 0)
-		return pars.offset(idx);
-	else
-		return -1;
-}
-	
-	
-
-uint Storytext_Shared::newTag(int pos, QChar ch)
-{
-	insertChar(pos, ch);
-	int idx = tags.insert(pos);
-	xml.insert(idx, XML_Tag(ch));
-	return idx;
-}
-
-
-void Storytext_Shared::insertChar(int pos, QChar ch)
-{
-	int idx = pars[pos];
-	
-	ParagraphData& par(paragraphs[idx]);
-	par.text.insert(pos - pars.offset(idx), ch);
-	par.charAttr.insert(pos, 1, 0);
-	adjust(pos, 1);
-
+		pos += this->cursorPos;
+	this->cursorPos = qMin(qMax(pos, 0), this->length());
+}
+
+
+int Storytext_Shared::length() const
+{
+	return pars.offset(pars.count());
+}
+
+
+QChar Storytext_Shared::text(int pos) const
+{
+	assert( pos >= 0 && pos < length());
+
+	int idx = pars[pos];
+	return paragraphs[idx].text[pos - pars.offset(idx)];
+}
+
+
+QString Storytext_Shared::text(int pos, uint len) const
+{
+	//assert( pos >= 0 && pos + signed(len) <= length());
+	// correct values rather than assert, could lead to artifacts but well, it's better than a crash.
+	if(0 == len)
+		return QString();
+	int cpos(qMax(0, pos));
+	int clen(len);
+	if(cpos + len > length())
+		clen = length() - cpos ;
+	int idx1 = pars[cpos];
+	int idx2 = pars[cpos + clen - 1];
+	//qDebug() << "text(" << pos << "," << len << ") from" << idx1 << "," << idx2;
+	if (idx1 == idx2)
+		return paragraphs[idx1].text.mid(cpos - pars.offset(idx1), clen);
+	else
+	{
+		//for (int j=idx1; j <= idx2; ++j)
+		//	qDebug() << "text() par" << j << paragraphs[j].text << "\n\n___";
+		
+		QString result = paragraphs[idx1].text.mid(cpos - pars.offset(idx1));
+		for (int i = idx1 + 1; i < idx2; ++i)
+			result.append(paragraphs[i].text);
+		result.append(paragraphs[idx2].text.left(cpos + clen - pars.offset(idx2)));
+		//qDebug() << result.length() << result;
+		assert(result.length() == signed(clen));
+		return result;
+	}
+}
+
+
+TextFlags& Storytext_Shared::charAttributes(int pos)
+{
+	assert( pos >= 0 && pos < length());
+	
+	int idx = pars[pos];
+	return paragraphs[idx].charAttr[pos - pars.offset(idx)];
+}
+
+
+const TextFlags& Storytext_Shared::charAttributes(int pos) const
+{
+	assert( pos >= 0 && pos < length());
+
+	int idx = pars[pos];
+	return paragraphs[idx].charAttr[pos - pars.offset(idx)];
+}
+
+
+
+int Storytext_Shared::xmlStart(int pos) const
+{
+	uint tg = tags[pos];
+	return tg <= tags.count()? tags.offset(tg) : -1;
+}
+
+int Storytext_Shared::xmlEnd(int pos) const
+{
+	uint strt = tags[pos];
+	if (strt < tags.count())
+		return tags.offset(xml[strt].matchingTagIndex);
+	else
+		return -1;
+}
+
+const QMap<QString, QString> Storytext_Shared::xmlAttributes(int pos) const
+{
+	if (text(pos) == SpecialChars::START_TAG || text(pos) == SpecialChars::EMPTY_TAG)
+	{
+		uint idx = tags[pos];
+		return idx < tags.count()? xml[idx].attr : QMap<QString,QString>();
+	}
+	else
+	{
+		return QMap<QString,QString>();
+	}
+}
+
+QString Storytext_Shared::xmlName(int pos) const
+{
+	if (text(pos) == SpecialChars::START_TAG || text(pos) == SpecialChars::EMPTY_TAG)
+	{
+		uint idx = tags[pos];
+		return idx < tags.count()? xml[idx].name : QString("?");
+	}
+	else
+	{
+		return QString();
+	}
+}
+
+
+
+InlineFrame Storytext_Shared::object(int pos) const
+{
+	int idx = objs[pos];
+	if (idx < objects.count())
+		return objects[idx];
+	else
+		return InlineFrame(NULL);
+}
+
+
+const CharStyle& Storytext_Shared::charStyle(int pos) const
+{
+	assert( pos >= 0 && pos < length() );
+
+	int idx = runs[pos];
+	return charstyles[idx];
+}
+
+
+const ParagraphStyle& Storytext_Shared::paragraphStyle(int pos) const
+{
+	int idx = pars[pos];
+	return paragraphs[idx].style;
+}
+
+
+uint Storytext_Shared::nrOfParagraphs() const
+{
+	return pars.count();
+}
+
+uint Storytext_Shared::nrOfParagraph(int pos) const
+{
+	return pars[pos];
+}
+
+
+int Storytext_Shared::startOfParagraph(uint index) const
+{
+	return pars.offset(index);
+}
+
+
+int Storytext_Shared::endOfParagraph(uint index) const
+{
+	return pars.end(index);
+}
+
+
+uint Storytext_Shared::nrOfRuns() const
+{
+	return runs.count();
+}
+
+
+int Storytext_Shared::startOfRun(uint index) const
+{
+	return runs.offset(index);
+}
+
+
+int Storytext_Shared::endOfRun(uint index) const
+{
+	return runs.end(index);
+}
+
+
+void Storytext_Shared::replaceChars(QString txt, int pos, uint len)
+{
+	uint idx = pars[pos];
+	for (int i = 0; i < txt.length(); ++i)
+	{
+		int c = txt[i].unicode();
+		if (c < 32 && c != 13)
+			qDebug() << "replaceChars: found non printable" << txt[i].unicode() << "at" << i;
+	}
+	
+	
+	uint idx2 = pars[pos+len];
+	for (uint p = idx2; p > idx; )
+	{
+		--p;
+		joinPar(p);
+	}
+	
+	assert(pars.offset(idx) <= pos && pos <= pars.end(idx));	
+
+	uint r1 = runs[pos];
+	uint r2 = runs[pos+len];
+	for (uint r= r2; r > r1; )
+	{
+		--r;
+		joinRun(r);
+	}
+	
+	//qDebug() << "replaceChars:" << txt << "\n\n_____" << pos << len << "in par" << idx;
+
+	ParagraphData& par(paragraphs[idx]);
+	
+	assert (par.text.length() == par.charAttr.count());
+	assert (par.text.length() == pars.length(idx));
+	
+	if (txt.length() > 0 || len > 0)
+	{
+		par.text.replace(pos - pars.offset(idx), len, txt);
+	}
+	if (len > 0)
+	{
+		par.charAttr.remove(pos - pars.offset(idx), len);
+	}
+	if (txt.length() > 0)
+	{
+		par.charAttr.insert(pos - pars.offset(idx), txt.length(), 0);
+	}
+	adjust(pos, txt.length() - len);
+	
+	int pos2 = pos + txt.length();
+	for (int i = pos; i < pos2; ++i)
+	{
+		if (text(i) == SpecialChars::PARSEP)
+			splitPar(i, false);
+	}
+
+	if (this->cursorPos >= pos)
+	{
+		this->cursorPos = qMax(pos, this->cursorPos - (int) len)+ txt.length();
+	}
+}
+
+
+void Storytext_Shared::insertTag(QString name, int pos, uint len)
+{
+	uint end = newTag(pos+len, SpecialChars::END_TAG);
+	uint start = newTag(pos, SpecialChars::START_TAG);
+	xml[start].name = name;
+	xml[start].matchingTagIndex = end;
+	xml[end].matchingTagIndex = start;
+}
+
+
+void Storytext_Shared::insertEmptyTag(QString name, int pos)
+{
+	uint start = newTag(pos, SpecialChars::EMPTY_TAG);
+	xml[start].name = name;
+	xml[start].matchingTagIndex = start;
+}
+
+
+void Storytext_Shared::setXmlAttributes(int pos, QMap<QString, QString> attr)
+{
+	if (text(pos) == SpecialChars::START_TAG)
+	{
+		uint idx = tags[pos];
+		xml[idx].attr = attr;
+	}
+}
+
+
+void Storytext_Shared::insertObject(InlineFrame obj, int pos)
+{
+	uint idx = objs.insert(pos);
+	objects.insert((int)idx, obj);
+	insertChar(pos, SpecialChars::OBJECT);
+}
+	
+
+void Storytext_Shared::clear(int start, int end)
+{
+	if (end < 0)
+		end = length();
+		
+	//FIXME: remove objects and tags
+	replaceChars(QString(""), start, end - start);
+}
+
+
+void Storytext_Shared::insert(int pos, const Storytext_Shared& other, int start, int end)
+{
+	if (end < 0)
+		end = other.length();
+
+	uint firstRun = splitRun(pos);
+	
+	uint idx1 = other.pars[start];
+	uint idx2 = other.pars[end];
+	uint destPar = pars[pos];
+	if (idx1 != idx2)
+	{
+		destPar = splitPar(pos, false);
+		replaceChars(other.text(start, end-start), pos, 0);
+		int p = pos;
+		for (uint i = 0; i < idx2 - idx1; ++i)
+		{
+			const ParagraphData& par( other.paragraphs[idx1 + i] );
+			paragraphs[destPar + i].style = par.style;
+		}
+	}
+	else
+	{
+		replaceChars(other.text(start, end-start), pos, 0);
+	}
+	for (int i=pos; i < pos + end-start; ++i)
+	{
+		if (text(i) == SpecialChars::OBJECT)
+		{
+			qDebug() << "insert Object at" << i; 
+			uint idx = objs.insert(pos);
+			objects.insert((int)idx, other.object(i - pos + start));
+		}
+		else if (text(i) == SpecialChars::START_TAG ||
+			text(i) ==  SpecialChars::END_TAG ||
+			text(i) ==  SpecialChars::EMPTY_TAG)
+		{
+			qDebug() << "insert XML tag" << text(i).unicode() << "at" << i; 
+			uint idxSrc = other.tags[i - pos + start];
+			uint idx = tags.insert(pos);
+			xml.insert((int)idx, other.xml[idxSrc]);
+		}
+	}
+	idx1 = other.runs[start];
+	idx2 = other.runs[end];
+	for (uint r=idx1; r < idx2; ++r)
+	{
+		int len = other.runs.length(r);
+		qDebug() << "other.runs" << r << "of" << other.charstyles.count() << "len" << len << "@" << pos;
+		setStyle(other.charstyles[r], pos, len);
+		pos += len;
+	}
+}
+
+
+void Storytext_Shared::setStyle(const CharStyle& style, int pos, uint len)
+{
+	uint idx1 = splitRun(pos);
+	uint idx2 = splitRun(pos+len);
+	qDebug() << "setStyle" << idx1 << idx2 << "of" << charstyles.count() << "@" << pos << ".." << len;
+	charstyles[idx1] = style;
+	for (uint i = idx1 + 1; i < idx2; ++i)
+		charstyles.removeAt(idx1 + 1);
+}
+
+void Storytext_Shared::setStyle(const ParagraphStyle& style, int pos, uint len)
+{
+	uint idx1 = pars[pos];
+	uint idx2 = pars[pos+len];
+	if (pars.offset(idx2) < pos + (signed) len)
+		++idx2;
+	for (uint i = idx1; i < idx2; ++i)
+		paragraphs[i].style = style;
+}
+
+void Storytext_Shared::applyStyle(const CharStyle& style, int pos, uint len)
+{
+	uint idx1 = splitRun(pos);
+	uint idx2 = splitRun(pos+len);
+	for (uint i = idx1; i < idx2; ++i)
+		charstyles[i].applyCharStyle(style);
+}
+
+void Storytext_Shared::applyStyle(const ParagraphStyle& style, int pos, uint len)
+{
+	uint idx1 = pars[pos];
+	uint idx2 = pars[pos+len];
+	if (pars.offset(idx2) < pos + (signed) len)
+		++idx2;
+	for (uint i = idx1; i < idx2; ++i)
+		paragraphs[i].style.applyStyle(style);	
+}
+
+void Storytext_Shared::eraseStyle(const CharStyle& style, int pos, uint len)
+{
+	uint idx1 = splitRun(pos);
+	uint idx2 = splitRun(pos+len);
+	for (uint i = idx1; i < idx2; ++i)
+		charstyles[i].eraseCharStyle(style);
+}
+
+void Storytext_Shared::eraseStyle(const ParagraphStyle& style, int pos, uint len)
+{
+	uint idx1 = pars[pos];
+	uint idx2 = pars[pos+len];
+	if (pars.offset(idx2) < pos + (signed) len)
+		++idx2;
+	for (uint i = idx1; i < idx2; ++i)
+		paragraphs[i].style.eraseStyle(style);
+}
+
+
+void Storytext_Shared::getNamedResources(ResourceCollection& lists) const
+{
+	for (int i=0; i < length(); ++i)
+	{
+		if (text(i) == SpecialChars::PARSEP)
+			paragraphStyle(i).getNamedResources(lists);
+		else if (text(i) == SpecialChars::OBJECT)
+			object(i).getItem()->getNamedResources(lists);
+		else
+			charStyle(i).getNamedResources(lists);
+	}
+	
+}
+
+void Storytext_Shared::replaceNamedResources(ResourceCollection& newNames)
+{
+	int len = length();
+	
+	if (len == 0)
+		return;
+	/*
+	 //	ScText* itText;
+	 for (int i=0; i < len; ++i) {
+	 itText = d->at(i);
+	 if (itText->parstyle)
+	 itText->parstyle->replaceNamedResources(newNames);
+	 else
+	 itText->replaceNamedResources(newNames);
+	 }
+	 */
+	invalidate(0, len);	
+	
+}
+	
+
+
+// positioning
+int Storytext_Shared::nextChar(int pos) const
+{
+	// skips tags, objects and parseps
+	return -1; 
+}
+
+int Storytext_Shared::prevChar(int pos) const
+{
+	// skips tags, objects and parseps
+	return -1;
+}
+
+int Storytext_Shared::nextWord(int pos) const
+{
+	// using charAttr
+	return -1; 
+}
+
+int Storytext_Shared::prevWord(int pos) const
+{
+	// using charAttr
+	return -1; 
+}
+
+int Storytext_Shared::nextPattern(int pos, const QRegExp& pat) const
+{
+	// returns pos of a match or -1. pat.pos() indices will be relative to paragraph start
+	return -1;
+}
+
+int Storytext_Shared::prevPattern(int pos, const QRegExp& pat) const
+{
+	// returns pos of a match or -1. pat.pos() indices will be relative to paragraph start
+	return -1;
+}
+
+int Storytext_Shared::nextParagraph(int pos) const
+{
+	uint idx = pars[pos] + 1;
+	if (idx < pars.count())
+		return pars.offset(idx);
+	return -1;
+}
+
+int Storytext_Shared::prevParagraph(int pos) const
+{
+	int idx = pars[pos] - 1;
+	if (idx >= 0)
+		return pars.offset(idx);
+	else
+		return -1;
+}
+	
+	
+
+uint Storytext_Shared::newTag(int pos, QChar ch)
+{
+	insertChar(pos, ch);
+	int idx = tags.insert(pos);
+	xml.insert(idx, XML_Tag(ch));
+	return idx;
+}
+
+
+void Storytext_Shared::insertChar(int pos, QChar ch)
+{
+	int idx = pars[pos];
+	
+	ParagraphData& par(paragraphs[idx]);
+	par.text.insert(pos - pars.offset(idx), ch);
+	par.charAttr.insert(pos, 1, 0);
+	adjust(pos, 1);
+
 	if (cursorPos >= pos)
-		cursorPos += 1;
-}
-
-void Storytext_Shared::removeChar(int pos)
-{
-	int idx = pars[pos];
-	
-	ParagraphData& par(paragraphs[idx]);
-	par.text.remove(pos - pars.offset(idx), 1);
-	par.charAttr.remove(pos);
-	adjust(pos, -1);
-
-	if (cursorPos >= (pos + 1) && cursorPos > 0)
-		cursorPos -= 1;
-}
-
-
-void Storytext_Shared::adjust(int pos, int delta)
-{
-	runs.adjust(pos, delta);
-	pars.adjust(pos, delta);
-	objs.adjust(pos, delta);
-	tags.adjust(pos, delta);
-}
-
-uint Storytext_Shared::splitRun(int pos)
-{
-	uint idx = runs[pos];
-	if (runs.offset(idx) == pos)
-		return idx;
-	
-	uint idx2 = runs.insert(pos);
-	charstyles.insert(idx2, charstyles[idx]);
-	return idx2;
-}
-
-
-void Storytext_Shared::joinRun(uint idx)
-{
-	runs.remove(idx);
-	charstyles.removeAt(idx);
-}
-
-uint Storytext_Shared::splitPar(int pos, bool insertSep)
-{
-	uint idx = pars[pos];
-	if (runs.offset(idx) == pos)
-		return idx;
-	
-	if (insertSep)
-		insertChar(pos, SpecialChars::PARSEP);
-
-	splitRun(pos+1);
-	uint idx2 = pars.insert(pos + 1) + 1;
-	paragraphs.insert(idx2, ParagraphData(paragraphs[idx]));
-	
-	int len1 = pos + 1 - pars.offset(idx);
-	int len2 = paragraphs[idx].text.length() - len1;
-	//qDebug() << "splitPar0:" << idx << paragraphs[idx].text << idx2 << paragraphs[idx2].text;
-	//qDebug() << "remove(" << len1 << len2 << ")" << 
-	paragraphs[idx].text.remove(len1, len2);
-	paragraphs[idx].charAttr.remove(len1, len2);
-	//qDebug() << "splitPar1:" << paragraphs[idx].text << paragraphs[idx2].text;
-	//qDebug() << "remove(" << 0 << len1 << ")" << 
-	paragraphs[idx2].text.remove(0, len1);
-	paragraphs[idx2].charAttr.remove(0, len1);
-	//qDebug() << "splitPar2:" << paragraphs[idx].text << paragraphs[idx2].text;
-	//for (int j=0; j < pars.count(); ++j)
-	//	qDebug() << "par" << j << paragraphs[j].text << pars.offset(j);
-	//qDebug() << "par end" << pars.count() << pars.offset(pars.count());
-
-	return idx2;
-}
-
-void Storytext_Shared::joinPar(uint idx)
-{
-	assert( idx + 1 < pars.count() );
-	
-	int len = paragraphs[idx].text.length();
-	paragraphs[idx+1].text.insert(0, paragraphs[idx].text);
-	
-	QVector<TextFlags>& caDest(paragraphs[idx+1].charAttr);
-	QVector<TextFlags>& caSrc(paragraphs[idx].charAttr);
-	caDest.insert(caDest.begin(), len, 0);
-	for (int i=0; i < len; ++i)
-		caDest.replace(i, caSrc.at(i));
-									  
-	paragraphs.removeAt(idx);
-	pars.remove(idx);
-	
-	//for (int j=0; j < pars.count(); ++j)
-	//	qDebug() << "par" << j << paragraphs[j].text << pars.offset(j);
-	//qDebug() << "par end" << pars.count() << pars.offset(pars.count());
-	
-}
-
-void Storytext_Shared::invalidate(int startPos, int endPos)
-{
-	//FIXME!
-}
+		cursorPos += 1;
+}
+
+void Storytext_Shared::removeChar(int pos)
+{
+	int idx = pars[pos];
+	
+	ParagraphData& par(paragraphs[idx]);
+	par.text.remove(pos - pars.offset(idx), 1);
+	par.charAttr.remove(pos);
+	adjust(pos, -1);
+
+	if (cursorPos >= (pos + 1) && cursorPos > 0)
+		cursorPos -= 1;
+}
+
+
+void Storytext_Shared::adjust(int pos, int delta)
+{
+	runs.adjust(pos, delta);
+	pars.adjust(pos, delta);
+	objs.adjust(pos, delta);
+	tags.adjust(pos, delta);
+}
+
+uint Storytext_Shared::splitRun(int pos)
+{
+	uint idx = runs[pos];
+	if (runs.offset(idx) == pos)
+		return idx;
+	
+	uint idx2 = runs.insert(pos);
+	charstyles.insert(idx2, charstyles[idx]);
+	return idx2;
+}
+
+
+void Storytext_Shared::joinRun(uint idx)
+{
+	runs.remove(idx);
+	charstyles.removeAt(idx);
+}
+
+uint Storytext_Shared::splitPar(int pos, bool insertSep)
+{
+	uint idx = pars[pos];
+	if (runs.offset(idx) == pos)
+		return idx;
+	
+	if (insertSep)
+		insertChar(pos, SpecialChars::PARSEP);
+
+	splitRun(pos+1);
+	uint idx2 = pars.insert(pos + 1) + 1;
+	paragraphs.insert(idx2, ParagraphData(paragraphs[idx]));
+	
+	int len1 = pos + 1 - pars.offset(idx);
+	int len2 = paragraphs[idx].text.length() - len1;
+	//qDebug() << "splitPar0:" << idx << paragraphs[idx].text << idx2 << paragraphs[idx2].text;
+	//qDebug() << "remove(" << len1 << len2 << ")" << 
+	paragraphs[idx].text.remove(len1, len2);
+	paragraphs[idx].charAttr.remove(len1, len2);
+	//qDebug() << "splitPar1:" << paragraphs[idx].text << paragraphs[idx2].text;
+	//qDebug() << "remove(" << 0 << len1 << ")" << 
+	paragraphs[idx2].text.remove(0, len1);
+	paragraphs[idx2].charAttr.remove(0, len1);
+	//qDebug() << "splitPar2:" << paragraphs[idx].text << paragraphs[idx2].text;
+	//for (int j=0; j < pars.count(); ++j)
+	//	qDebug() << "par" << j << paragraphs[j].text << pars.offset(j);
+	//qDebug() << "par end" << pars.count() << pars.offset(pars.count());
+
+	return idx2;
+}
+
+void Storytext_Shared::joinPar(uint idx)
+{
+	assert( idx + 1 < pars.count() );
+	
+	int len = paragraphs[idx].text.length();
+	paragraphs[idx+1].text.insert(0, paragraphs[idx].text);
+	
+	QVector<TextFlags>& caDest(paragraphs[idx+1].charAttr);
+	QVector<TextFlags>& caSrc(paragraphs[idx].charAttr);
+	caDest.insert(caDest.begin(), len, 0);
+	for (int i=0; i < len; ++i)
+		caDest.replace(i, caSrc.at(i));
+									  
+	paragraphs.removeAt(idx);
+	pars.remove(idx);
+	
+	//for (int j=0; j < pars.count(); ++j)
+	//	qDebug() << "par" << j << paragraphs[j].text << pars.offset(j);
+	//qDebug() << "par end" << pars.count() << pars.offset(pars.count());
+	
+}
+
+void Storytext_Shared::invalidate(int startPos, int endPos)
+{
+	//FIXME!
+}

Modified: branches/ScribusOIF/scribus/ui/about.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/ui/about.cpp
==============================================================================
--- branches/ScribusOIF/scribus/ui/about.cpp (original)
+++ branches/ScribusOIF/scribus/ui/about.cpp Thu Jun  9 22:48:43 2011
@@ -112,8 +112,8 @@
 	buildID = new QLabel( tab );
 	buildID->setAlignment(Qt::AlignCenter);
 	buildID->setTextInteractionFlags(Qt::TextSelectableByMouse);
-	QString BUILD_DAY = "23";
-	QString BUILD_MONTH = CommonStrings::may;
+	QString BUILD_DAY = "07";
+	QString BUILD_MONTH = CommonStrings::june;
 	QString BUILD_YEAR = "2011";
 	QString BUILD_TIME = "";
 	QString BUILD_TZ = "";

Modified: branches/ScribusOIF/scribus/ui/cupsoptions.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/ui/cupsoptions.cpp
==============================================================================
--- branches/ScribusOIF/scribus/ui/cupsoptions.cpp (original)
+++ branches/ScribusOIF/scribus/ui/cupsoptions.cpp Thu Jun  9 22:48:43 2011
@@ -42,6 +42,7 @@
 #include "scconfig.h"
 #ifdef HAVE_CUPS
 #include <cups/cups.h>
+#include <cups/ppd.h>
 #endif
 #include "util_icon.h"
 

Modified: branches/ScribusOIF/scribus/util_printer.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16649&path=/branches/ScribusOIF/scribus/util_printer.cpp
==============================================================================
--- branches/ScribusOIF/scribus/util_printer.cpp (original)
+++ branches/ScribusOIF/scribus/util_printer.cpp Thu Jun  9 22:48:43 2011
@@ -9,6 +9,7 @@
 
 #if defined( HAVE_CUPS )
  #include <cups/cups.h>
+ #include <cups/ppd.h>
 #elif defined(_WIN32)
  #include <windows.h>
  #include <winspool.h>




More information about the scribus-commit mailing list