void AP_Dialog_Paragraph::_createPreviewFromGC(GR_Graphics * gc,
											   UT_uint32 width,
											   UT_uint32 height)
{
	UT_return_if_fail (gc);

	// g_free any attached preview
	DELETEP(m_paragraphPreview);

	// platform's runModal should have set this
	UT_return_if_fail (m_pFrame);

	AV_View * baseview = m_pFrame->getCurrentView();
	UT_return_if_fail (baseview);

	FV_View * view = static_cast<FV_View *> (baseview);

	FL_DocLayout * dl = view->getLayout();
	UT_return_if_fail (dl);

	fl_BlockLayout * bl = dl->findBlockAtPosition((PT_DocPosition) view->getPoint());
	UT_return_if_fail (bl);

	UT_GrowBuf gb;
	bool hadMem = bl->getBlockBuf(&gb);

	UT_UCSChar * tmp = NULL;
	if (hadMem && gb.getLength() > 0)
	{
		gb.truncate(NUM_CHARS_FOR_SAMPLE);
		UT_UCS4_cloneString(&tmp, (UT_UCSChar *) gb.getPointer(0));
	}
	else
	{
		const XAP_StringSet * pSS = m_pApp->getStringSet();

		// if the paragraph was empty, use our sample
		UT_UCS4_cloneString_char(&tmp, pSS->getValue(AP_STRING_ID_DLG_Para_PreviewSampleFallback));
	}

	m_paragraphPreview = new AP_Preview_Paragraph(gc, tmp, this);

	FREEP(tmp);

	UT_return_if_fail (m_paragraphPreview);

	m_paragraphPreview->setWindowSize(width, height);

	// TODO : any setup of the GC for drawing

}
void GR_Graphics::appendRenderedCharsToBuff(GR_RenderInfo & ri, UT_GrowBuf & buf) const
{
	UT_return_if_fail(ri.getType() == GRRI_XP);
	
	GR_XPRenderInfo & RI = (GR_XPRenderInfo &) ri;
	buf.append(reinterpret_cast<UT_GrowBufElement *>(RI.m_pChars),RI.m_iLength);
}
/*!
  Insert a span of text into the document
 \param b Buffer containing UCS text to insert

 Uses appropriate function for clipboard or file
 */
bool IE_Imp_Text::_insertSpan(UT_GrowBuf &b)
{
	UT_uint32 iLength = b.getLength();
	const UT_UCS4Char * pData = (const UT_UCS4Char *)b.getPointer(0);

	// handle block direction if needed ...
	if(pData && m_bBlockDirectionPending)
	{
		const UT_UCS4Char * p = pData;

		// we look for the first strong character
		for(UT_uint32 i = 0; i < iLength; i++, p++)
		{
			UT_BidiCharType type = UT_bidiGetCharType(*p);

			if(UT_BIDI_IS_STRONG(type))
			{
				m_bBlockDirectionPending = false;

				// set 'dom-dir' property of the block ...
				const gchar * propsArray[3];
				propsArray[0] = "props";
				propsArray[1] = NULL;
				propsArray[2] = NULL;

				UT_String props("dom-dir:");
				
				if(UT_BIDI_IS_RTL(type))
					props += "rtl;text-align:right";
				else
					props += "ltr;text-align:left";

				propsArray[1] = props.c_str();
				
				// we need to modify the existing formatting ...
				if(m_pBlock == NULL)
				{
					PL_StruxDocHandle sdh = NULL;
					if(getDoc()->getStruxOfTypeFromPosition(getDocPos(), PTX_Block,&sdh))
					{
						m_pBlock = static_cast<pf_Frag_Strux *>(const_cast<void *>(sdh));
					}
				}
				appendStruxFmt(m_pBlock, static_cast<const gchar **>(&propsArray[0]));
			
				// if this is the first data in the block and the first
				// character is LRM or RLM followed by a strong character,
				// then we will remove it
				if(m_bFirstBlockData && i==0 && iLength > 1 && (*p == UCS_LRM || *p == UCS_RLM))
				{
					UT_BidiCharType next_type = UT_bidiGetCharType(*(p+1));
					if(UT_BIDI_IS_STRONG(next_type))
					{
						pData++;
						iLength--;
					}
				}
				
				break;
			}
		}
	}
	
	bool bRes = appendSpan (pData, iLength);
	b.truncate(0);
	m_bFirstBlockData = false;
	return bRes;
}
bool fp_FieldTableSumCols::calculateValue(void)
{
	FV_View * pView = _getView();
	pf_Frag_Strux* tableSDH= NULL;
	UT_sint32 numRows =0;
	UT_sint32 numCols = 0;
	bUseCurrency = false;
	cCurrency = '$';
	pf_Frag_Strux* sdh = getBlock()->getStruxDocHandle();
	PD_Document * pDoc = getBlock()->getDocument();
	if(pDoc->isPieceTableChanging())
	{
		return false;
	}
	if(getLine() == NULL)
	{
		return false;
	}
	fp_Container * pCol = getLine()->getColumn();
	if(pCol == NULL)
	{
		return false;
	}
	fp_ShadowContainer * pShad =NULL;
	fl_HdrFtrShadow * pShadL = NULL;
	if(pCol->getContainerType() == FP_CONTAINER_COLUMN_SHADOW)
	{
		pShad = static_cast<fp_ShadowContainer *>(pCol);
		pShadL = pShad->getShadow();
	}
	PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1;
	pDoc->getStruxOfTypeFromPosition(pos,PTX_SectionTable,&tableSDH);
	pDoc-> getRowsColsFromTableSDH(tableSDH, pView->isShowRevisions(), pView->getRevisionLevel(), &numRows, &numCols);

	UT_UTF8String sValF;
	if(!pView->isInTable(pos))
	{
		sValF = "???";
		return _setValue(sValF.ucs4_str().ucs4_str());
	}

	fl_CellLayout * pCell = NULL;
	UT_sint32 myLeft,myRight,myTop,myBot;
	pView->getCellParams(pos,&myLeft,&myRight,&myTop,&myBot);
	UT_sint32 col = 0;
	UT_sint32 row = myTop;
	UT_sint32 lastCol = -1;
	double dSum = 0.0;
	for(col = 0; col < numCols; col++)
	{
		pf_Frag_Strux* sdhCell = pDoc->getCellSDHFromRowCol(tableSDH,true,99999,row,col);
		UT_sint32 i = getBlock()->getDocLayout()->getLID();
		fl_ContainerLayout* fmtCell = pDoc->getNthFmtHandle(sdhCell,i);
		pCell = static_cast<fl_CellLayout *>(fmtCell);
		if(pCell->getLeftAttach() == lastCol)
		{
			continue;
		}
		if((pCell->getTopAttach() == myTop) && (pCell->getLeftAttach() == myLeft))
		{
			continue;
		}
		UT_GrowBuf grText;
		pCell->appendTextToBuf(grText);
		if(grText.getLength() == 0)
		{
			fl_ContainerLayout * pC = pCell->getFirstLayout();
			while(pC)
			{
				if(pC->getContainerType() == FL_CONTAINER_BLOCK)
				{
					fl_BlockLayout * pBL = static_cast<fl_BlockLayout *>(pC);
					if(pShadL)
					{
						pBL = static_cast<fl_BlockLayout *>(pShadL->findMatchingContainer(pBL));
					}
					if(pBL == NULL)
					{
						continue;
					}
					fp_Run * pRun = pBL->getFirstRun();
					while(pRun)
					{
						if(pRun->getType() == FPRUN_FIELD)
						{
							fp_FieldRun * pFRun = static_cast<fp_FieldRun *>(pRun);
							const  UT_UCS4Char * szVal = pFRun->getValue(); 
							sValF.clear();
							sValF.appendUCS4(szVal);
							dSum += dGetVal(sValF.utf8_str());
							pRun = NULL;
							pC = NULL;
							break;
						}
						pRun = pRun->getNextRun();
					}
				}
				if(pC)
				{
					pC = pC->getNext();
				}
			}
		}
		else
		{
			sValF.clear();
			sValF.appendUCS4(reinterpret_cast<const UT_UCS4Char *>(grText.getPointer(0)),grText.getLength());
			dSum += dGetVal(sValF.utf8_str());
		}
		lastCol = col;
	}
	sFormatDouble(sValF,dSum);
	return _setValue(sValF.ucs4_str().ucs4_str());
}