/*!
 * This method makes a union of the current rectangle with the one in the 
 * parameter list. This rectangle is the smallest one that covers both
 * rectangles.
 */
void UT_Rect::unionRect(const UT_Rect * pRect)
{
	UT_sint32 fx1,fx2,fy1,fy2;
	fx1 = UT_MIN(left,pRect->left);
	fx2 = UT_MAX(left+width,pRect->left + pRect->width);
	fy1 = UT_MIN(top,pRect->top);
	fy2 = UT_MAX(top+height,pRect->top + pRect->height);
	left = fx1;
	width = fx2 - fx1;
	top = fy1;
	height = fy2 - fy1;
}
Example #2
0
/**
 * Code from Dom Lachowicz and/or Robert Staudinger.
 */
UT_Error ODi_Abi_Data::_loadStream (GsfInfile* oo,
                                   const char* stream,
                                   UT_ByteBuf& buf ) {
    guint8 const *data = NULL;
    size_t len = 0;
    static const size_t BUF_SZ = 4096;
  
    buf.truncate (0);
    GsfInput * input = gsf_infile_child_by_name(oo, stream);

    if (!input)
        return UT_ERROR;
  
    if (gsf_input_size (input) > 0) {
        while ((len = gsf_input_remaining (input)) > 0) {
            len = UT_MIN (len, BUF_SZ);
            if (NULL == (data = gsf_input_read (input, len, NULL))) {
                g_object_unref (G_OBJECT (input));
                return UT_ERROR;
            }
            buf.append ((const UT_Byte *)data, len);
        }
    }
  
    g_object_unref (G_OBJECT (input));
    return UT_OK;
}
Example #3
0
/*!
 * This method looks to see if there is a list at the current point. If so
 * fill the dialog with that stuff, otherwise fill the dialog with the uncustomized
 * values corresponding to m_NewListType.
 */
void AP_Dialog_Lists::PopulateDialogData(void)
{
	m_isListAtPoint = getBlock()->isListItem();
	if(m_isListAtPoint == true)
	{
		fillDialogFromBlock();
	}
	else
	{
		//	m_NewListType = NOT_A_LIST;
		fillUncustomizedValues();
	}
	if(m_isListAtPoint == true)
	{
		const UT_UCSChar * tmp1 =  getBlock()->getListLabel();
		if(tmp1 != NULL)
		{
			UT_sint32 cnt = UT_MIN(UT_UCS4_strlen(tmp1),80);
			UT_sint32 i;
			for(i =0; i<=cnt; i++)
				m_curListLabel[i] = *tmp1++;
		}
		m_curListLevel = getBlock()->getLevel();
		m_curStartValue = getAutoNum()->getStartValue32();
		m_iStartValue = getAutoNum()->getStartValue32();
		m_DocListType = getAutoNum()->getType();
	}
	else
	{
		m_DocListType = NOT_A_LIST;
		m_curStartValue = 1;
	}
}
bool pf_Frag_Text::_isContentEqual(const pf_Frag & f2) const
{
	if(!pf_Frag::_isContentEqual(f2))
		return false;

	// NB: this we are asked to strictly compare 2 frags
	if(getLength() != f2.getLength())
		return false;

	pf_Frag * pf2 = const_cast<pf_Frag *>(&f2);
	
	PD_DocIterator t1(* (m_pPieceTable->getDocument()), getPos());
	PD_DocIterator t2(* (pf2->getPieceTable()->getDocument()), f2.getPos());

	UT_uint32 iLen = UT_MIN(getLength(), f2.getLength());
	UT_uint32 i = 0;
	
	while(i < iLen && t1.getStatus() == UTIter_OK && t2.getStatus() == UTIter_OK)
	{
		if(t1.getChar() != t2.getChar())
			return false;

		++i;
		++t1;
		++t2;
	}

	return true;
}
UT_Confidence_t IE_ImpSniffer::recognizeContents (GsfInput * input)
{
	char szBuf[4097] = "";  // 4096+nul ought to be enough
	UT_uint32 iNumbytes = UT_MIN(4096, gsf_input_size(input));
	gsf_input_read(input, iNumbytes, (guint8 *)(szBuf));
	szBuf[iNumbytes] = '\0';

	return recognizeContents(szBuf, iNumbytes);
}
void GR_Graphics::polygon(UT_RGBColor& c,UT_Point *pts,UT_uint32 nPoints)
{
    UT_sint32 minX,maxX,minY,maxY,x,y;
    minX = maxX = pts[0].x;
    minY = maxY = pts[0].y;
    for(UT_uint32 i = 0;i < nPoints - 1;i++){
        minX = UT_MIN(minX,pts[i].x);
        maxX = UT_MAX(maxX,pts[i].x);
        minY = UT_MIN(minY,pts[i].y);
        maxY = UT_MAX(maxY,pts[i].y);
    }
    for(x = minX;x <= maxX;x++){
        for(y = minY;y <= maxY;y++){
            if(_PtInPolygon(pts,nPoints,x,y)){
                fillRect(c,x,y,1,1);
            }
        }
    }
 }
/*!
  Detect encoding of text file
 \param fp File

 Supports UTF-8 and UCS-2 big and little endian
 CJK encodings could be added
 */
UT_Error IE_Imp_Text::_recognizeEncoding(GsfInput * fp)
{
	char szBuf[4096];  // 4096 ought to be enough
	UT_sint32 iNumbytes;

	iNumbytes = UT_MIN(4096, gsf_input_remaining(fp));
	gsf_input_read(fp, iNumbytes, (guint8 *)szBuf);
	gsf_input_seek(fp, 0, G_SEEK_SET);

	return _recognizeEncoding(szBuf, iNumbytes);
}
bool fp_FieldListLabelRun::calculateValue(void)
{
	UT_UCSChar sz_ucs_FieldValue[FPFIELD_MAX_LENGTH + 1];
	UT_uint32 i = 0;
	UT_UCSChar *  listlabel = NULL;
	if(getBlock()->isContainedByTOC())
	{
		xxx_UT_DEBUGMSG(("!!!!!!------!!!! ListLabel in TOC!!!! \n"));
//
// First Find the block in the document.
//
		pf_Frag_Strux* sdh = getBlock()->getStruxDocHandle();
		PD_Document * pDoc = getBlock()->getDocument();
		PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1;
		FL_DocLayout * pLayout = getBlock()->getDocLayout();
		fl_BlockLayout * pBlockInDoc = pLayout->findBlockAtPosition(pos);
		if(pBlockInDoc == NULL)
		{
			sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' ');
			sz_ucs_FieldValue[1] = 0;
			return _setValue(sz_ucs_FieldValue);
		}
		i = 0;
		listlabel = pBlockInDoc->getListLabel();

	}
	else
	{
		i = 0;
		listlabel = getBlock()->getListLabel();
	}
	if(listlabel == NULL)
	{
		sz_ucs_FieldValue[0] = 0;
	}
	else
	{
		//
		// This code is here because UT_UCS_copy_char is broken
		//
		i = 0;
		UT_uint32 len = UT_MIN( UT_UCS4_strlen(listlabel),FPFIELD_MAX_LENGTH + 1)  ;
		for(i=0; i<=len;i++)
		{
			sz_ucs_FieldValue[i] =  *listlabel++;
		}
//		sz_ucs_FieldValue[len] = 0;
//		m_sFieldValue[0] =  0; // Force an update!!!
	}
	return _setValue(sz_ucs_FieldValue);
}
Example #9
0
/*!
 * Little convienence method to get the List label from the FakeAutoNum used in the
 * Preview.
 */
UT_UCSChar * AP_Dialog_Lists::getListLabel(UT_sint32 itemNo)
{
	UT_ASSERT_HARMLESS(itemNo < 4);
	static UT_UCSChar lab[80];
	const UT_UCSChar * tmp  = m_pFakeAuto->getLabel(m_pFakeSdh[itemNo]);
	if(tmp == NULL)
	{
		return NULL;
	}
	UT_sint32 cnt = UT_MIN(UT_UCS4_strlen(tmp),80);
	UT_sint32 i;
	for(i =0; i<= cnt; i++)
		lab[i] = *tmp++;
	return lab;
}
Example #10
0
void fp_AnnotationRun::_draw(dg_DrawArgs* pDA)
{
        if(!displayAnnotations())
	  return;
	if(!m_bIsStart)
	  return;

	GR_Graphics * pG = pDA->pG;

	UT_sint32 xoff = 0, yoff = 0;
	GR_Painter painter(pG);

	// need screen locations of this run

	getLine()->getScreenOffsets(this, xoff, yoff);

	UT_sint32 iYdraw =  pDA->yoff - getAscent()-1;

	UT_uint32 iRunBase = getBlock()->getPosition() + getBlockOffset();

//
// Sevior was here
//		UT_sint32 iFillTop = iYdraw;
	UT_sint32 iFillTop = iYdraw+1;
	UT_sint32 iFillHeight = getAscent() + getDescent();

	FV_View* pView = _getView();
	UT_uint32 iSelAnchor = pView->getSelectionAnchor();
	UT_uint32 iPoint = pView->getPoint();

	UT_uint32 iSel1 = UT_MIN(iSelAnchor, iPoint);
	UT_uint32 iSel2 = UT_MAX(iSelAnchor, iPoint);

	UT_ASSERT(iSel1 <= iSel2);
	bool bIsInTOC = getBlock()->isContainedByTOC();
	if (
	    isInSelectedTOC() || (!bIsInTOC && (
						/* pView->getFocus()!=AV_FOCUS_NONE && */
						(iSel1 <= iRunBase)
						&& (iSel2 > iRunBase)))
	    )
	{
	    UT_RGBColor color(_getView()->getColorSelBackground());			
	    pG->setColor(_getView()->getColorAnnotation(this));
	    painter.fillRect(color, pDA->xoff, iFillTop, getWidth(), iFillHeight);

	}
	else
        {
	    Fill(getGraphics(),pDA->xoff, iFillTop, getWidth(), iFillHeight);
	    pG->setColor(_getColorFG());
	}
	pG->setFont(_getFont());
	pG->setColor(_getView()->getColorAnnotation(this));
	UT_DEBUGMSG(("Drawing string m_sValue %s \n",m_sValue.utf8_str()));
	painter.drawChars(m_sValue.ucs4_str().ucs4_str(), 0,m_sValue.ucs4_str().size(), pDA->xoff,iYdraw, NULL);
//
// Draw underline/overline/strikethough
//
	UT_sint32 yTopOfRun = pDA->yoff - getAscent()-1; // Hack to remove
	                                                 //character dirt
	drawDecors( xoff, yTopOfRun,pG);

}
Example #11
0
bool pt_PieceTable::changeSpanFmt(PTChangeFmt ptc,
									 PT_DocPosition dpos1,
									 PT_DocPosition dpos2,
									 const gchar ** attributes,
								  const gchar ** properties)
{
	// if dpos1 == dpos2 we are inserting a fmt mark; this must be chanelled throught
	// the non-revision branch ...
	if(m_pDocument->isMarkRevisions() && dpos1 != dpos2)
	{
		const gchar name[] = "revision";
		const gchar * pRevision = NULL;

		// we cannot retrieve the start and end fragments here and
		// then work between them in a loop using getNext() because
		// processing might result in merging of fargments. so we have
		// to use the doc position to keep track of where we are and
		// retrieve the fragments afresh in each step of the loop
		// Tomas, Dec 29, 2004

		bool bRet = false;
		while(dpos1 < dpos2)
		{
			// first retrive the starting and ending fragments
			pf_Frag * pf1, * pf2;
			PT_BlockOffset Offset1, Offset2;

			if(!getFragsFromPositions(dpos1,dpos2, &pf1, &Offset1, &pf2, &Offset2) ||
			   pf1->getType() == pf_Frag::PFT_EndOfDoc)
				return bRet;
			else
				bRet = true;
			
			// get attributes for this fragement
			const PP_AttrProp * pAP;
			pRevision = NULL;
			
			if(_getSpanAttrPropHelper(pf1, &pAP))
			{
				pAP->getAttribute(name, pRevision);
			}
			
			PP_RevisionAttr Revisions(pRevision);


			// if the request is for removal of fmt, in the revision mode, we still
			// have to add these props (the removal is indicated by their emptiness)
			// as we cannot rely on callers to set these correctly, we have to emtpy
			// them ourselves
			const gchar ** attrs = attributes;
			const gchar ** props = properties;
							
			if(ptc == PTC_RemoveFmt)
			{
				attrs = UT_setPropsToNothing(attributes);
				props = UT_setPropsToNothing(properties);
			}
			
			Revisions.addRevision(m_pDocument->getRevisionId(),PP_REVISION_FMT_CHANGE,attrs,props);

			if(attrs != attributes)
				delete[] attrs;
							
			if(props != properties)
				delete[] props;
			
			const gchar * ppRevAttrib[3];
			ppRevAttrib[0] = name;
			ppRevAttrib[1] = Revisions.getXMLstring();
			ppRevAttrib[2] = NULL;

			PT_DocPosition dposEnd = UT_MIN(dpos2,dpos1 + pf1->getLength());

			if(!_realChangeSpanFmt(PTC_AddFmt, dpos1, dposEnd, ppRevAttrib,NULL, false))
				return false;

			dpos1 = dposEnd;
		}

		return true;
	}
	else
	{
		return _realChangeSpanFmt(ptc, dpos1, dpos2, attributes, properties, false);
	}
}
Example #12
0
bool pt_PieceTable::_realChangeSpanFmt(PTChangeFmt ptc,
									   PT_DocPosition dpos1,
									   PT_DocPosition dpos2,
									   const gchar ** attributes,
									   const gchar ** properties,
									   bool bRevisionDelete)
{
	// apply a span-level formatting change to the given region.

	UT_return_val_if_fail (m_pts==PTS_Editing,false);
    _tweakFieldSpan(dpos1,dpos2);
//
// Deal with case of exactly selecting the endOfFootnote
//
	pf_Frag * pfEndDum = m_fragments.findFirstFragBeforePos(dpos2);
	if(isEndFootnote(pfEndDum))
	{
		if(dpos2 > dpos1)
		{
			dpos2--;
		}
	}
//
// Deal with addStyle
//
	bool bApplyStyle = (PTC_AddStyle == ptc);
	const gchar ** sProps = NULL;
	const gchar ** lProps = properties;
	if(bApplyStyle)
	{
//
// OK for styles we expand out all defined properties including BasedOn styles
// Then we use these to eliminate any specfic properties in the current strux
// Then properties in the current strux will resolve to those defined in the
// style (they exist there) to specifc values in strux (if not overridden by
// the style) then finally to default value.
//
		const gchar * szStyle = UT_getAttribute(PT_STYLE_ATTRIBUTE_NAME,attributes);
		PD_Style * pStyle = NULL;
		UT_return_val_if_fail (szStyle,false);
		getDocument()->getStyle(szStyle,&pStyle);
		UT_return_val_if_fail (pStyle,false);
		UT_Vector vProps;
//
// Get the vector of properties
//
		pStyle->getAllProperties(&vProps,0);
//
// Finally make the const gchar * array of properties
//
		UT_uint32 countp = vProps.getItemCount() + 1;
		sProps = (const gchar **) UT_calloc(countp, sizeof(gchar *));
		countp--;
		UT_uint32 i;
		for(i=0; i<countp; i++)
		{
			sProps[i] = (const gchar *) vProps.getNthItem(i);
		}
		sProps[i] = NULL;
		lProps = sProps;
	}
	if (dpos1 == dpos2) 		// if length of change is zero, then we have a toggle format.
	{
		UT_uint32 startUndoPos = m_history.getUndoPos();
		bool bRes = _insertFmtMarkFragWithNotify(ptc,dpos1,attributes,lProps);
		UT_uint32 endUndoPos = m_history.getUndoPos();
		// Won't be a persistant change if it's just a toggle
		PX_ChangeRecord *pcr=0;
		m_history.getUndo(&pcr,true);
		if (pcr && (startUndoPos != endUndoPos) )
		{
			UT_DEBUGMSG(("Setting persistance of change to false\n"));
			pcr->setPersistance(false);
			m_history.setSavePosition(m_history.getSavePosition()+1);
		}
		if(bApplyStyle)
		{
			FREEP(sProps);
		}
		return bRes;
	}

	UT_return_val_if_fail (dpos1 < dpos2,false);
	bool bHaveAttributes, bHaveProperties;
	bHaveAttributes = (attributes && *attributes);
	bHaveProperties = (lProps && *lProps);

	pf_Frag * pf_First;
	pf_Frag * pf_End;
	PT_BlockOffset fragOffset_First;
	PT_BlockOffset fragOffset_End;

	bool bFound;
	bFound = getFragsFromPositions(dpos1,dpos2,&pf_First,&fragOffset_First,&pf_End,&fragOffset_End);
	UT_return_val_if_fail (bFound, false);

#if 0
	{
		pf_Frag * pf1, * pf2;
		PT_BlockOffset fo1, fo2;

		bool bFound1 = getFragFromPosition(dpos1,&pf1,&fo1);
		bool bFound2 = getFragFromPosition(dpos2,&pf2,&fo2);
		UT_return_val_if_fail (bFound1 && bFound2, false);
		UT_return_val_if_fail ((pf1==pf_First) && (fragOffset_First==fo1), false);
		UT_return_val_if_fail ((pf2==pf_End) && (fragOffset_End==fo2), false);
	}
#endif

	// see if the amount of text to be changed is completely
	// contained within a single fragment.  if so, we have a
	// simple change.  otherwise, we need to set up a multi-step
	// change -- it may not actually take more than one step,
	// but it is too complicated to tell at this point, so we
	// assume it will and don't worry about it.
	//
	// we are in a simple change if the beginning and end are
	// within the same fragment.

	// NOTE: if we call beginMultiStepGlob() we ***MUST*** call
	// NOTE: endMultiStepGlob() before we return -- otherwise,
	// NOTE: the undo/redo won't be properly bracketed.

	bool bSimple = (pf_First == pf_End);
	if (!bSimple)
		beginMultiStepGlob();

	pf_Frag_Strux * pfsContainer = NULL;
	pf_Frag * pfNewEnd;
	UT_uint32 fragOffsetNewEnd;

	UT_uint32 length = dpos2 - dpos1;
	while (length != 0)
	{
		// FIXME: Special check to support a FmtMark at the end of the
		// document. This is necessary because FmtMarks don't have a
		// length...  See bug 452.
		if (0 == length
			&& (!pf_First || pf_Frag::PFT_FmtMark != pf_First->getType()))
			break;

		UT_return_val_if_fail (dpos1+length==dpos2, false);

		UT_uint32 lengthInFrag = pf_First->getLength() - fragOffset_First;
		UT_uint32 lengthThisStep = UT_MIN(lengthInFrag, length);

		switch (pf_First->getType())
		{
		case pf_Frag::PFT_EndOfDoc:
		default:
			UT_DEBUGMSG(("fragment type: %d\n",pf_First->getType()));
			UT_ASSERT_HARMLESS(0);
			if(bApplyStyle)
			{
				FREEP(sProps);
			}
			return false;

		case pf_Frag::PFT_Strux:
			{
				// we are only applying span-level changes, so we ignore strux.
				// but we still need to update our loop indices.

				pfNewEnd = pf_First->getNext();
				fragOffsetNewEnd = 0;
				pfsContainer = static_cast<pf_Frag_Strux *> (pf_First);
				bool bFoundStrux = false;
				if(isEndFootnote(pfsContainer))
				{
					bFoundStrux = _getStruxFromFragSkip(pfsContainer,&pfsContainer);
					UT_return_val_if_fail (bFoundStrux, false);
				}
			}
			break;

		case pf_Frag::PFT_Text:
			{
				if (!pfsContainer)
				{
					bool bFoundStrux;
					bFoundStrux = _getStruxFromPosition(dpos1,&pfsContainer);
					UT_return_val_if_fail (bFoundStrux,false);
					if(isEndFootnote(pfsContainer))
					{
						bFoundStrux = _getStruxFromFragSkip(pfsContainer,&pfsContainer);
						UT_return_val_if_fail (bFoundStrux,false);
					}
				}

				bool bResult;
				bResult	= _fmtChangeSpanWithNotify(ptc,static_cast<pf_Frag_Text *>(pf_First),
											   fragOffset_First,dpos1,lengthThisStep,
											   attributes,lProps,
											   pfsContainer,&pfNewEnd,&fragOffsetNewEnd,bRevisionDelete);
				UT_return_val_if_fail (bResult,false);
			}
			break;

		case pf_Frag::PFT_Object:
			{
				if (!pfsContainer)
				{
					bool bFoundStrux;
					bFoundStrux = _getStruxFromPosition(dpos1,&pfsContainer);
					UT_return_val_if_fail (bFoundStrux,false);
					if(isEndFootnote(pfsContainer))
					{
						bFoundStrux = _getStruxFromFragSkip(pfsContainer,&pfsContainer);
						UT_return_val_if_fail (bFoundStrux,false);
					}
				}

				bool bResult;
				bResult	= _fmtChangeObjectWithNotify(ptc,static_cast<pf_Frag_Object *>(pf_First),
												 fragOffset_First,dpos1,lengthThisStep,
												 attributes,lProps,
												 pfsContainer,&pfNewEnd,&fragOffsetNewEnd,false);
				UT_return_val_if_fail (bResult,false);
			}
			break;

		case pf_Frag::PFT_FmtMark:
			{
				if (!pfsContainer)
				{
					bool bFoundStrux;
					bFoundStrux = _getStruxFromPosition(dpos1,&pfsContainer);
					UT_return_val_if_fail (bFoundStrux,false);
					if(isEndFootnote(pfsContainer))
					{
						bFoundStrux = _getStruxFromFragSkip(pfsContainer,&pfsContainer);
						UT_return_val_if_fail (bFoundStrux,false);
					}

				}

				bool bResult;
				bResult = _fmtChangeFmtMarkWithNotify(ptc,static_cast<pf_Frag_FmtMark *>(pf_First),
												  dpos1, attributes,lProps,
												  pfsContainer,&pfNewEnd,&fragOffsetNewEnd);
				UT_return_val_if_fail (bResult,false);
			}
			break;

		}

		dpos1 += lengthThisStep;
		length -= lengthThisStep;

		// since _fmtChange{Span,FmtMark,...}WithNotify(), can delete pf_First, mess with the
		// fragment list, and does some aggressive coalescing of
		// fragments, we cannot just do a pf_First->getNext() here.
		// to advance to the next fragment, we use the *NewEnd variables
		// that each of the cases routines gave us.

		pf_First = pfNewEnd;
		if (!pf_First)
			length = 0;
		fragOffset_First = fragOffsetNewEnd;
	}
	if(bApplyStyle)
	{
		FREEP(sProps);
	}

	if (!bSimple)
		endMultiStepGlob();

	return true;
}
Example #13
0
bool pt_PieceTable::_doTheDo(const PX_ChangeRecord * pcr, bool bUndo)
{
	// actually do the work of the undo or redo.
	m_bDoingTheDo = true;
	switch (pcr->getType())
	{

	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////

	case PX_ChangeRecord::PXT_GlobMarker:
		DONE();
		m_bDoingTheDo = false;
		return true;
		
	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////

	case PX_ChangeRecord::PXT_InsertSpan:
		{
			const PX_ChangeRecord_Span * pcrSpan = static_cast<const PX_ChangeRecord_Span *>(pcr);
			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			UT_DEBUGMSG(("_undo insertspan Pos = %d \n",pcr->getPosition()));
			bool bFound = getFragFromPosition(pcrSpan->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound,false);

			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux = _getStruxFromFrag(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux,false);
			if(isEndFootnote(static_cast<pf_Frag *>(pfs)))
			{
				bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfs),&pfs);
				UNDO_return_val_if_fail (bFoundStrux,false);
			}
			PT_BlockOffset newOffset = pcrSpan->getPosition() - pfs->getPos() -1;
			if (!_insertSpan(pf,pcrSpan->getBufIndex(),fragOffset,
							 pcrSpan->getLength(),pcrSpan->getIndexAP(),
                             pcrSpan->getField()))
				return false;

			DONE();
			pcrSpan->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
		}
		m_bDoingTheDo = false;
		return true;
		
	case PX_ChangeRecord::PXT_DeleteSpan:
		{
			// Our deleteSpan is much simpler than the main routine.
			// We can do this becase the change history is composed
			// of atomic operations, whereas the main routine has to
			// to deal with whatever the user chose to do (and cut
			// it into a series of steps).

			const PX_ChangeRecord_Span * pcrSpan = static_cast<const PX_ChangeRecord_Span *>(pcr);
			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcrSpan->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound,false);
			UNDO_return_val_if_fail (pf->getType() == pf_Frag::PFT_Text,false);

			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux = _getStruxFromFrag(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux, false);
			if(isEndFootnote(static_cast<pf_Frag *>(pfs)))
			{
				bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfs),&pfs);
				UNDO_return_val_if_fail (bFoundStrux, false);
			}
			UNDO_return_val_if_fail (bFoundStrux, false);
			UT_sint32 newOffset = pcrSpan->getPosition() - pfs->getPos() -1; //was -2 
			if(newOffset < 0)
			  newOffset = 0;
			pf_Frag_Text * pft = static_cast<pf_Frag_Text *> (pf);
			UNDO_return_val_if_fail (pft->getIndexAP() == pcrSpan->getIndexAP(),false);
			xxx_UT_DEBUGMSG(("deletespan in _doTheDo length %d \n",pcrSpan->getLength()));
			UT_uint32 iLenDeleted = fragOffset + pft->getLength();
			if(iLenDeleted >= pcrSpan->getLength())
			{
			    _deleteSpan(pft,fragOffset,pcrSpan->getBufIndex(),pcrSpan->getLength(),NULL,NULL);
			}
			else
			{
			    pf_Frag_Text * pftNext = static_cast<pf_Frag_Text *>(pft->getNext());
			    UT_uint32 iLenDel = pft->getLength() - fragOffset;
			    iLenDeleted = 0;
			    while(pft && (pft ->getType() == pf_Frag::PFT_Text) && (iLenDeleted <pcrSpan->getLength()) )
			    {
				_deleteSpan(pft,fragOffset,pcrSpan->getBufIndex(),iLenDel,NULL,NULL);
				pft = pftNext;
				pftNext = static_cast<pf_Frag_Text *>(pft->getNext());
				iLenDeleted += iLenDel;
				iLenDel = pcrSpan->getLength() - iLenDeleted;
				if(iLenDel > pft->getLength())
				  iLenDel = pft->getLength();
				fragOffset = 0;
			    }
			}
			UT_DEBUGMSG(("newOffset %d spanBlockOffset %d \n",newOffset,pcrSpan->getBlockOffset()));
			pcrSpan->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);

			DONE();
		}
		m_bDoingTheDo = false;
		return true;

	case PX_ChangeRecord::PXT_ChangeSpan:
		{
			// ChangeSpan is it's own inverse.  similarly, we have a much simpler
			// job than the main routine, because we have broken up the user's
			// request into atomic operations.

			const PX_ChangeRecord_SpanChange * pcrs = static_cast<const PX_ChangeRecord_SpanChange *>(pcr);

			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcrs->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound, false);
			UNDO_return_val_if_fail (pf->getType() == pf_Frag::PFT_Text, false);

			pf_Frag_Text * pft = static_cast<pf_Frag_Text *> (pf);

			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux = _getStruxFromFrag(pf,&pfs);
			if(isEndFootnote(static_cast<pf_Frag *>(pfs)))
			{
				bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfs),&pfs);
				UNDO_return_val_if_fail (bFoundStrux, false);
			}
			UNDO_return_val_if_fail (bFoundStrux, false);
			PT_BlockOffset newOffset = pcrs->getPosition() - pfs->getPos() -1;

			// we need to loop here, because even though we have a simple (atomic) change,
			// the document may be fragmented slightly differently (or rather, it may not
			// yet be possible to coalesce it (until the end of the loop)).
			
			pf_Frag * pfEnd;
			UT_uint32 fragOffsetEnd;
			UT_uint32 length = pcrs->getLength();
			while (length)
			{
				UT_uint32 lengthInFrag = pft->getLength() - fragOffset;
				UT_uint32 lengthThisStep = UT_MIN(lengthInFrag, length);

				_fmtChangeSpan(pft,fragOffset,lengthThisStep,pcrs->getIndexAP(),&pfEnd,&fragOffsetEnd);

				length -= lengthThisStep;
				if (length == 0)
					break;

				UNDO_return_val_if_fail (pfEnd->getType() == pf_Frag::PFT_Text, false);
				pft = static_cast<pf_Frag_Text *> (pfEnd);
				fragOffset = fragOffsetEnd;
			}
			
			DONE();
			pcrs->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
		}
		m_bDoingTheDo = false;
		return true;
			
	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////

	case PX_ChangeRecord::PXT_InsertStrux:
		{
			const PX_ChangeRecord_Strux * pcrStrux = static_cast<const PX_ChangeRecord_Strux *>(pcr);
			pf_Frag_Strux * pfsNew = NULL;
			if (!_createStrux(pcrStrux->getStruxType(),pcrStrux->getIndexAP(),&pfsNew))
				return false;

			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFoundFrag = getFragFromPosition(pcrStrux->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFoundFrag, false);

			// get the strux containing the given position.
	
// TODO see if we can avoid this call to _getStruxFromPosition ??
			pf_Frag_Strux * pfsContainer = NULL;
			bool bFoundContainer = _getStruxFromPosition(pcrStrux->getPosition(),&pfsContainer);
			UNDO_return_val_if_fail (bFoundContainer,false);
			if(isEndFootnote(static_cast<pf_Frag *>(pfsContainer)))
			{
				bool bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfsContainer),&pfsContainer);
				UNDO_return_val_if_fail (bFoundStrux, false);
			}
			_insertStrux(pf,fragOffset,pfsNew);
			DONE();
			m_pDocument->notifyListeners(pfsContainer,pfsNew,pcr);
		}
		return true;
		
	case PX_ChangeRecord::PXT_DeleteStrux:
		{
			const PX_ChangeRecord_Strux * pcrStrux = static_cast<const PX_ChangeRecord_Strux *>(pcr);
			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFoundFrag = getFragFromPosition(pcrStrux->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFoundFrag,false);
			UNDO_return_val_if_fail (pf->getType() == pf_Frag::PFT_Strux,false);

			pf_Frag_Strux * pfs = static_cast<pf_Frag_Strux *> (pf);
			UNDO_return_val_if_fail (pcrStrux->getStruxType() == pfs->getStruxType(),false);
			bool bResult = _unlinkStrux(pfs,NULL,NULL);
			m_pDocument->notifyListeners(pfs,pcr);
			UNDO_return_val_if_fail (bResult,false);
			DONE();
			
			delete pfs;
		}
		m_bDoingTheDo = false;
		return true;

	case PX_ChangeRecord::PXT_ChangeStrux:
		{
			// ChangeStrux is it's own inverse.

			const PX_ChangeRecord_StruxChange * pcrs = static_cast<const PX_ChangeRecord_StruxChange *>(pcr);
			pf_Frag_Strux * pfs;
			bool bFound = _getStruxFromPosition(pcrs->getPosition(),&pfs);
			UNDO_return_val_if_fail (bFound,false);
			bool bResult = _fmtChangeStrux(pfs,pcrs->getIndexAP());
			UNDO_return_val_if_fail (bResult,false);
			DONE();
			m_pDocument->notifyListeners(pfs,pcr);
		}
		m_bDoingTheDo = false;
		return true;

	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////

	case PX_ChangeRecord::PXT_InsertObject:
		{
			const PX_ChangeRecord_Object * pcrObject = static_cast<const PX_ChangeRecord_Object *>(pcr);
			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcrObject->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound, false);

			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux2 = _getStruxFromFrag(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux2, false);
			if(isEndFootnote(static_cast<pf_Frag *>(pfs)))
			{
				bool bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfs),&pfs);
				UNDO_return_val_if_fail (bFoundStrux,false);
			}
			pf_Frag_Object * pfo = NULL;
			if (!_insertObject(pf,fragOffset,pcrObject->getObjectType(),
                               pcrObject->getIndexAP(),pfo))
				return false;
			pcrObject->setObjectHandle(pfo);
			UNDO_return_val_if_fail (pfo,false);
			UT_sint32 newOffset = pcrObject->getPosition() - pfs->getPos() -1;

            
            // need to set field pointers to values of new pointer
            // as old field doesn't exist
			pf = pfo->getNext();
			while (pf&&pf->getType()==pf_Frag::PFT_Text&&
			       pf->getField())
			  {
			    pf_Frag_Text * pft = 
			      static_cast<pf_Frag_Text *>(pf);
			    pft->setField(pfo->getField());
			    pf = pft->getNext();
			  }
			DONE();            
			pcrObject->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
            // don't update field until all of changes have been made
		}
		m_bDoingTheDo = false;
		return true;
		
	case PX_ChangeRecord::PXT_DeleteObject:
		{
			const PX_ChangeRecord_Object * pcrObject = static_cast<const PX_ChangeRecord_Object *>(pcr);
			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcrObject->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound, false);
			UNDO_return_val_if_fail (pf->getType() == pf_Frag::PFT_Object,false);
			UNDO_return_val_if_fail (fragOffset == 0,false);
			
			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux2 = _getStruxFromFrag(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux2,false);
			if(isEndFootnote(static_cast<pf_Frag *>(pfs)))
			{
				bool bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfs),&pfs);
				UNDO_return_val_if_fail (bFoundStrux,false);
			}
			UT_sint32 newOffset = pcrObject->getPosition() - pfs->getPos() -1; // was -2
			if(newOffset < 0)
			  newOffset = 0;
			pf_Frag_Object * pfo = static_cast<pf_Frag_Object *> (pf);
			if((pfo->getObjectType() != PTO_Math) && ((pfo->getObjectType() != PTO_Embed)))
			{
			    UNDO_return_val_if_fail (pfo->getIndexAP() == pcrObject->getIndexAP(),false);
			}
			_deleteObject(pfo,NULL,NULL);

			DONE();
			pcrObject->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
		}
		m_bDoingTheDo = false;
		return true;

	case PX_ChangeRecord::PXT_ChangeObject:
		{
			// ChangeSpan is it's own inverse.

			const PX_ChangeRecord_ObjectChange * pcro = static_cast<const PX_ChangeRecord_ObjectChange *>(pcr);

			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcro->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound,false);
			UNDO_return_val_if_fail (pf->getType() == pf_Frag::PFT_Object,false);
			UNDO_return_val_if_fail (fragOffset == 0, false);

			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux2 = _getStruxFromFrag(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux2,false);
			if(isEndFootnote(static_cast<pf_Frag *>(pfs)))
			{
				bool bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfs),&pfs);
				UNDO_return_val_if_fail (bFoundStrux,false);
			}
			UT_sint32 newOffset = pcro->getPosition() - pfs->getPos() -1;

			pf_Frag_Object * pfo = static_cast<pf_Frag_Object *> (pf);

			_fmtChangeObject(pfo,pcro->getIndexAP(),NULL,NULL);

			DONE();
			pcro->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
		}
		m_bDoingTheDo = false;
		return true;

	///////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////

	case PX_ChangeRecord::PXT_InsertFmtMark:
		{
			const PX_ChangeRecord_FmtMark * pcrFM = static_cast<const PX_ChangeRecord_FmtMark *>(pcr);
			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcrFM->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound, false);

			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux2 = _getStruxFromFrag(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux2, false);
			if(isEndFootnote(static_cast<pf_Frag *>(pfs)))
			{
				bool bFoundStrux = _getStruxFromFragSkip(static_cast<pf_Frag *>(pfs),&pfs);
				UNDO_return_val_if_fail (bFoundStrux,false);
			}
			UT_sint32 newOffset = pcrFM->getPosition() - pfs->getPos() -1;
			
			if (!_insertFmtMark(pf,fragOffset,pcrFM->getIndexAP()))
				return false;

			DONE();
			pcrFM->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
		}
		m_bDoingTheDo = false;
		return true;
	 
	case PX_ChangeRecord::PXT_DeleteFmtMark:
		{
			const PX_ChangeRecord_FmtMark * pcrFM = static_cast<const PX_ChangeRecord_FmtMark *>(pcr);
			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcrFM->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound, false);

			// we backup one because we have zero length and getFragFromPosition()
			// returns the right-most thing with this document position.
			if(pf->getType() != pf_Frag::PFT_FmtMark)
			  pf = pf->getPrev();
			if(pf->getType()==pf_Frag::PFT_Strux)
			{
			    if(pf->getNext() && pf->getNext()->getType() == pf_Frag::PFT_Strux)
			    {
				DONE();
				m_bDoingTheDo = false;
				return true;
			    }
			    if(pf->getNext() && pf->getNext()->getType() == pf_Frag::PFT_Text)
			    {
			        pf = pf->getNext();
			    
				if(pf->getNext() && pf->getNext()->getType() == pf_Frag::PFT_FmtMark)
				{
				    pf = pf->getNext();
				}
			    }
			}

			UNDO_return_val_if_fail (pf->getType() == pf_Frag::PFT_FmtMark,false);
			UNDO_return_val_if_fail (fragOffset == 0,false);
			
			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux = _getStruxFromFragSkip(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux,false);
			UT_sint32 newOffset = pcrFM->getPosition() - pfs->getPos() -1;

			pf_Frag_FmtMark * pffm = static_cast<pf_Frag_FmtMark *> (pf);
			//			UNDO_return_val_if_fail (pffm->getIndexAP() == pcrFM->getIndexAP(),false);
			_deleteFmtMark(pffm,NULL,NULL);

			DONE();
			pcrFM->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
		}
		m_bDoingTheDo = false;
		return true;

	case PX_ChangeRecord::PXT_ChangeFmtMark:
		{
			// ChangeFmt is it's own inverse.

			const PX_ChangeRecord_FmtMarkChange * pcrFMC = static_cast<const PX_ChangeRecord_FmtMarkChange *>(pcr);

			pf_Frag * pf = NULL;
			PT_BlockOffset fragOffset = 0;
			bool bFound = getFragFromPosition(pcrFMC->getPosition(),&pf,&fragOffset);
			UNDO_return_val_if_fail (bFound,false);

			// we backup one because we have zero length and getFragFromPosition()
			// returns the right-most thing with this document position.
			if(pf->getType() != pf_Frag::PFT_FmtMark)
			  pf = pf->getPrev();
			if(pf->getType()==pf_Frag::PFT_Strux)
			{
			    if(pf->getNext() && pf->getNext()->getType() == pf_Frag::PFT_Strux)
			    {
				DONE();
				m_bDoingTheDo = false;
				return true;
			    }
			}
			UNDO_return_val_if_fail (pf->getType() == pf_Frag::PFT_FmtMark,false);
			UNDO_return_val_if_fail (fragOffset == 0,false);

			pf_Frag_Strux * pfs = NULL;
			bool bFoundStrux = _getStruxFromFragSkip(pf,&pfs);
			UNDO_return_val_if_fail (bFoundStrux,false);
			UT_sint32 newOffset = pcrFMC->getPosition() - pfs->getPos() -1;

			pf_Frag_FmtMark * pffm = static_cast<pf_Frag_FmtMark *> (pf);

			_fmtChangeFmtMark(pffm,pcrFMC->getIndexAP(),NULL,NULL);

			DONE();
			m_bDoingTheDo = false;
			pcrFMC->AdjustBlockOffset(newOffset);
			m_pDocument->notifyListeners(pfs,pcr);
		}
		return true;
		
	///////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////

	case PX_ChangeRecord::PXT_ChangePoint:
		DONE();
		m_pDocument->notifyListeners(NULL, pcr);

		m_bDoingTheDo = false;
		return true;

	default:
		UT_ASSERT_HARMLESS(0);
		m_bDoingTheDo = false;
		return false;
	}
}
void s_RTF_ListenerGetProps::_check_revs_for_color(const PP_AttrProp * pAP1,
												   const PP_AttrProp * pAP2,
												   const PP_AttrProp * pAP3)
{
	const PP_AttrProp * pAP = NULL;

	for(UT_uint32 i = 0; i < 3; ++i)
	{
		if(i == 0)
			pAP = pAP1;
		else if(i == 1)
			pAP = pAP2;
		else
			pAP = pAP3;
		
		if(!pAP)
			continue;

		const gchar * pRev;
		char *pDup  = NULL;

		if(pAP->getAttribute("revision", pRev))
		{
			char * p;
			pDup = p = g_strdup(pRev);

			do
			{
				char * p1 = strstr(p, "color");
				char * p2 = strstr(p, "bgcolor");

				if(p1 && p2)
				{
					p = UT_MIN(p1,p2);
				}
				else if(p1)
				{
					p = p1;
				}
				else
				{
					p = p2;
				}
			
				if(p)
				{
					char * s = strchr(p, ':');
					if(s)
						++s;
					
					while(s && *s == ' ')
						++s;
				
					if(s)
					{
						char * e1 = strchr(s, ';');
						char * e2 = strchr(s, '}');
						char * e;

						if(e1 && e2)
						{
							e = UT_MIN(e1,e2);
						}
						else if(e1)
						{
							e = e1;
						}
						else
						{
							e = e2;
						}

						
						if(e)
						{
							*e = 0;
							p = e+1;
						}
						else
						{
							p = NULL;
						}

						m_pie->_findOrAddColor(s);
					}
				}
			
			}while(p);
		}
		else
			return;

		if(pDup)
		{
			g_free(pDup);
			pDup = NULL;
		}
	}
}
Example #15
0
bool AP_Win32App::_pasteFormatFromClipboard(PD_DocumentRange * pDocRange, const char * szFormat,
											const char * szType, bool bWide)
{
	HANDLE	hData;
	bool 	bSuccess = false;	
  
	if (!(hData = m_pClipboard->getHandleInFormat(szFormat)))
		return bSuccess;		
 		
 	// It's a bitmap
 	if (g_ascii_strcasecmp(szFormat, AP_CLIPBOARD_BMP)==0)
	{			
 		HBITMAP					hBitmap;
 		PBITMAPINFO 			bi;
 		HWND		 			hWnd;
 		HDC 					hdc;
 		IE_ImpGraphic*			pIEG = NULL;
 		FG_Graphic* 			pFG = NULL;	
 		UT_Error 				errorCode;		
 		UT_ByteBuf 				byteBuf;				
 		IEGraphicFileType		iegft = IEGFT_BMP;	
 		XAP_Frame* 				pFrame;						
 		AP_FrameData* 			pFrameData;		
 		FL_DocLayout*			pDocLy;	
 		FV_View* 				pView;						
		UT_ByteBuf*				bBufBMP = new UT_ByteBuf;
 		
 		hBitmap = (HBITMAP)hData;					
 		hWnd =  GetDesktopWindow();
 		hdc = GetDC(hWnd);		
 		
 		// Create a BMP file from a BITMAP
 		bi =  CreateBitmapInfoStruct(hBitmap);						
 		CreateBMP(hWnd, *bBufBMP, bi, hBitmap,hdc);                  										
 		
 		// Since we are providing the file type, there is not need to pass the bytebuff filled up
 		errorCode = IE_ImpGraphic::constructImporter(*bBufBMP, iegft, &pIEG);				 				
		 				
 		if(errorCode != UT_OK)		
			return false;				  	
		 				 			
 		errorCode = pIEG->importGraphic(bBufBMP, &pFG); 		
 		
 		if(errorCode != UT_OK || !pFG)
		{
			DELETEP(bBufBMP);
			DELETEP(pIEG);
 			return false;
		}
		// sunk in importGraphic
		bBufBMP = NULL;
 		 
 		// Insert graphic in the view
 		pFrame = getLastFocussedFrame(); 						
 		pFrameData = (AP_FrameData*) pFrame->getFrameData();		
 		pDocLy =	pFrameData->m_pDocLayout;	
 		pView =  pDocLy->getView();		
 				
 		errorCode = pView->cmdInsertGraphic(pFG);	  		  		
 	
		DELETEP(pIEG);
 		//DELETEP(pFG);		
 		
 		bSuccess = true;
 	}
 	else	
	{
		unsigned char * pData = static_cast<unsigned char *>(GlobalLock(hData));
		UT_DEBUGMSG(("Paste: [fmt %s %s][hdata 0x%08lx][pData 0x%08lx]\n",
					 szFormat, szType,  hData, pData));
		UT_uint32 iSize = GlobalSize(hData);
		UT_uint32 iStrLen = bWide
			? wcslen(reinterpret_cast<const wchar_t *>(pData)) * 2
			: strlen(reinterpret_cast<const char *>(pData));
		UT_uint32 iLen = UT_MIN(iSize,iStrLen);

		
		IE_Imp * pImp = 0;
		IE_Imp::constructImporter(pDocRange->m_pDoc, IE_Imp::fileTypeForSuffix(szType), &pImp, 0);
		if (pImp)
		{
			const char * szEncoding = 0;
			if (bWide)
				szEncoding = XAP_EncodingManager::get_instance()->getUCS2LEName();
			else
				; // TODO Get code page using CF_LOCALE
			pImp->pasteFromBuffer(pDocRange,pData,iLen,szEncoding);
			delete pImp;
		}

		GlobalUnlock(hData);
		bSuccess = true;
	}
	return bSuccess;
}
void s_RTF_ListenerGetProps::_check_revs_for_font(const PP_AttrProp * pAP1,
												  const PP_AttrProp * pAP2,
												  const PP_AttrProp * pAP3)
{
	const PP_AttrProp * pAP = NULL;

	for(UT_uint32 i = 0; i < 3; ++i)
	{
		if(i == 0)
			pAP = pAP1;
		else if(i == 1)
			pAP = pAP2;
		else
			pAP = pAP3;
		
		if(!pAP)
			continue;

		const gchar * pRev;
		char *pDup  = NULL;

		if(pAP->getAttribute("revision", pRev))
		{
			char * p;
			pDup = p = g_strdup(pRev);

			do
			{
				char * p1 = strstr(p, "font-family");
				char * p2 = strstr(p, "field-font");

				if(p1 && p2)
				{
					p = UT_MIN(p1,p2);
				}
				else if(p1)
				{
					p = p1;
				}
				else
				{
					p = p2;
				}
			
				if(p)
				{
					char * s = strchr(p, ':');
					if(s)
						++s;
					
					while(s && *s == ' ')
						++s;
				
					if(s)
					{
						char * e1 = strchr(s, ';');
						char * e2 = strchr(s, '}');
						char * e;

						if(e1 && e2)
						{
							e = UT_MIN(e1,e2);
						}
						else if(e1)
						{
							e = e1;
						}
						else
						{
							e = e2;
						}

						
						if(e)
						{
							*e = 0;
							p = e+1;
						}
						else
						{
							p = NULL;
						}

						{
							_rtf_font_info fi;

							if (fi.init(s))
							{
								UT_sint32 ndxFont = m_pie->_findFont(&fi);
								if (ndxFont == -1)
									m_pie->_addFont(&fi);
							}
						}
					}
				}
			
			}while(p);
		}
		else
			return;

		if(pDup)
		{
			g_free(pDup);
			pDup = NULL;
		}
	}
}
Example #17
0
/*!
 Draw container content
 \param pDA Draw arguments
 */
void fp_FrameContainer::draw(dg_DrawArgs* pDA)
{
	FV_View * pView = getView();
	UT_return_if_fail( pView);
	
	xxx_UT_DEBUGMSG(("FrameContainer %x called, page %x \n",this,getPage()));
	if(getPage() == NULL)
	{
	     getSectionLayout()->format();
	     getSectionLayout()->setNeedsReformat(getSectionLayout());
	     if(getPage() == NULL)
	     {
			 return;
	     }
	}
	if(pView)
	{
		if(pView->getFrameEdit()->getFrameEditMode() == FV_FrameEdit_DRAG_EXISTING)
		{
			if((pView->getFrameEdit()->getFrameContainer() == this))
			{
				return;
			}
		}
	}
//
// Only draw the lines in the clipping region.
//
/*
	[Somewhere down here is where the logic to only draw the region of the frame which
	is within the complement of the union of all higher frames needs to be. We need to
	draw the applicable region of the rectangle we're on, then unify it with (if
	applicable) the higher union.] <-- Possibly obsolete comment, not sure.
	I think I might have landed on an alternative solution involving more rearranging
	of the storage of the FrameContainers, based on their z-index.  Not sure how far
	I got with that or if it worked either.  See also abi bug 7664 and the original
	discussions about defining the undefinedness of layered frame behaviour.
*/

	if(m_bOverWrote)
	{
		pDA->bDirtyRunsOnly = false;
	}
	dg_DrawArgs da = *pDA;
	GR_Graphics * pG = da.pG;
	UT_return_if_fail( pG);

	UT_sint32 x = pDA->xoff - m_iXpad;
	UT_sint32 y = pDA->yoff - m_iYpad;
	getPage()->expandDamageRect(x,y,getFullWidth(),getFullHeight());
	if(!pDA->bDirtyRunsOnly || m_bNeverDrawn)
	{
		if(m_bNeverDrawn)
		{
			pDA->bDirtyRunsOnly= false;
		} 
		UT_sint32 srcX,srcY;
		getSectionLayout()->checkGraphicTick(pG);
		srcX = -m_iXpad;
		srcY = -m_iYpad;
		//
		// Only fill to the bottom of the viewed page.
		//
		UT_sint32 iFullHeight = getFullHeight();
		fl_DocSectionLayout * pDSL = getDocSectionLayout();
		UT_sint32 iMaxHeight = 0;
		if(!pG->queryProperties(GR_Graphics::DGP_PAPER) && (pView->getViewMode() != VIEW_PRINT))
		{
		        iMaxHeight = pDSL->getActualColumnHeight();
		}
		else
		{
		        iMaxHeight = getPage()->getHeight();
		}
		UT_sint32 iBot = getFullY()+iFullHeight;
		if(iBot > iMaxHeight)
		{
		        iFullHeight = iFullHeight - (iBot-iMaxHeight);
		}
		getFillType()->Fill(pG,srcX,srcY,x,y,getFullWidth(),iFullHeight);
		m_bNeverDrawn = false;
	}
	UT_uint32 count = countCons();
	UT_DEBUGMSG(("Number of containers in frame %d \n",count));
	const UT_Rect * pPrevRect = pDA->pG->getClipRect();
	UT_Rect * pRect = getScreenRect();
	UT_Rect newRect;
	bool bRemoveRectAfter = false;
	bool bSetOrigClip = false;
	bool bSkip = false;
	if((pPrevRect == NULL) && pG->queryProperties(GR_Graphics::DGP_SCREEN))
	{
		pDA->pG->setClipRect(pRect);
		UT_DEBUGMSG(("Clip bottom is %d \n",pRect->top + pRect->height));
		bRemoveRectAfter = true;
	}
	else if(pPrevRect && !pRect->intersectsRect(pPrevRect))
	{
		bSkip = true;
		xxx_UT_DEBUGMSG(("External Clip bottom is %d \n",pRect->top + pRect->height));
	}
	else if(pPrevRect)
	{
		newRect.top = UT_MAX(pPrevRect->top,pRect->top);
		UT_sint32 iBotPrev = pPrevRect->height + pPrevRect->top;
		UT_sint32 iBot = pRect->height + pRect->top;
		newRect.height = UT_MIN(iBotPrev,iBot) - newRect.top;
		newRect.width = pPrevRect->width;
		newRect.left = pPrevRect->left;
		if((newRect.height > 0) && pDA->pG->queryProperties(GR_Graphics::DGP_SCREEN))
		{
			pDA->pG->setClipRect(&newRect);
			bSetOrigClip = true;
		}
		else
		{
			bSkip = true;
		}
	}
	if(!bSkip)
	{
		for (UT_uint32 i = 0; i<count; i++)
		{
			fp_ContainerObject* pContainer = static_cast<fp_ContainerObject*>(getNthCon(i));
			da.xoff = pDA->xoff + pContainer->getX();
			da.yoff = pDA->yoff + pContainer->getY();
			pContainer->draw(&da);
		}
	}
	m_bNeverDrawn = false;
	m_bOverWrote = false;
	if(bRemoveRectAfter)
	{
		pDA->pG->setClipRect(NULL);
	}
	if(bSetOrigClip)
	{
		pDA->pG->setClipRect(pPrevRect);
	}
	delete pRect;
	drawBoundaries(pDA);
}
void fp_EmbedRun::_draw(dg_DrawArgs* pDA)
{
	GR_Graphics *pG = pDA->pG;
#if 0
	UT_DEBUGMSG(("Draw with class %x \n",pG));
	UT_DEBUGMSG(("Contents of fp EmbedRun \n %s \n",m_sEmbedML.utf8_str()));
#endif
	FV_View* pView = _getView();
	UT_return_if_fail(pView);

	// need to draw to the full height of line to join with line above.
	UT_sint32 xoff= 0, yoff=0, DA_xoff = pDA->xoff;

	getLine()->getScreenOffsets(this, xoff, yoff);

	// need to clear full height of line, in case we had a selection

	UT_sint32 iFillHeight = getLine()->getHeight();
	UT_sint32 iFillTop = pDA->yoff - getLine()->getAscent();

	UT_uint32 iSelAnchor = pView->getSelectionAnchor();
	UT_uint32 iPoint = pView->getPoint();

	UT_uint32 iSel1 = UT_MIN(iSelAnchor, iPoint);
	UT_uint32 iSel2 = UT_MAX(iSelAnchor, iPoint);

	UT_ASSERT(iSel1 <= iSel2);

	UT_uint32 iRunBase = getBlock()->getPosition() + getOffsetFirstVis();

	// Fill with background, then redraw.

	UT_sint32 iLineHeight = getLine()->getHeight();
	bool bIsSelected = false;
	if ( !pG->queryProperties(GR_Graphics::DGP_PAPER) && 
	    (isInSelectedTOC() || (iSel1 <= iRunBase && iSel2 > iRunBase))
		)
	{
	  // Need the painter lock to be released at the end of this block
	        GR_Painter painter(pG);
		painter.fillRect(_getView()->getColorSelBackground(), /*pDA->xoff*/DA_xoff, iFillTop, getWidth(), iFillHeight);
		bIsSelected = true;

		getEmbedManager()->setColor(m_iEmbedUID,_getView()->getColorSelForeground());

	}
	else
	{
		Fill(getGraphics(),pDA->xoff, pDA->yoff - getAscent(), getWidth()+getGraphics()->tlu(1), iLineHeight+getGraphics()->tlu(1));
		getEmbedManager()->setColor(m_iEmbedUID,getFGColor());
	}

	UT_Rect rec;
	rec.left = pDA->xoff;
	rec.top = pDA->yoff;
	rec.height = getHeight();
	rec.width = getWidth();
	if(getEmbedManager()->isDefault())
	{
	  rec.top -= _getLayoutPropFromObject("ascent");
	}
	UT_DEBUGMSG(("Draw Embed object top %d \n",rec.top));
	getEmbedManager()->render(m_iEmbedUID,rec);
	if(m_bNeedsSnapshot && !getEmbedManager()->isDefault() && getGraphics()->queryProperties(GR_Graphics::DGP_SCREEN)  )
	{
	  UT_Rect myrec = rec;
	  myrec.top -= getAscent();
	  if(!bIsSelected)
	  {
	    getEmbedManager()->makeSnapShot(m_iEmbedUID,myrec);
	    m_bNeedsSnapshot = false;
	  }
	}
	if(bIsSelected)
	{
	  UT_Rect myrec = rec;
	  if(!getEmbedManager()->isDefault())
	  {
	    myrec.top -= getAscent();
	  }
	  _drawResizeBox(myrec);
	}
}
gint XAP_UnixDialog_FileOpenSaveAs::previewPicture (void)
{
    UT_ASSERT (m_FC && m_preview);

    UT_ASSERT(XAP_App::getApp());

    const XAP_StringSet * pSS = m_pApp->getStringSet();
    UT_return_val_if_fail( pSS, 0 );

    // attach and clear the area immediately
    GR_UnixCairoAllocInfo ai(m_preview);
    GR_CairoGraphics* pGr =
        (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai);

    const gchar * file_name = gtk_file_chooser_get_uri (m_FC);

    GR_Font * fnt = pGr->findFont("Times New Roman",
                                  "normal", "", "normal",
                                  "", "12pt",
                                  pSS->getLanguageName());
    pGr->setFont(fnt);

    UT_UTF8String str;
    pSS->getValueUTF8(XAP_STRING_ID_DLG_IP_No_Picture_Label, str);

    int answer = 0;

    FG_Graphic * pGraphic = 0;
    GR_Image *pImage = NULL;

    double		scale_factor = 0.0;
    UT_sint32     scaled_width,scaled_height;
    UT_sint32     iImageWidth,iImageHeight;

    {
        GR_Painter painter(pGr);
        painter.clearArea(0, 0, pGr->tlu(m_preview->allocation.width), pGr->tlu(m_preview->allocation.height));

        if (!file_name)
        {
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            goto Cleanup;
        }

        // are we dealing with a file or directory here?
        struct stat st;
        if (!stat (file_name, &st))
        {
            if (!S_ISREG(st.st_mode))
            {
                painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
                goto Cleanup;
            }
        }

        GsfInput * input = NULL;
        UT_DEBUGMSG(("file_name %s \n",file_name));
        input = UT_go_file_open (file_name, NULL);
        if (!input)
            goto Cleanup;
        char Buf[4097] = "";  // 4096+nul ought to be enough
        UT_uint32 iNumbytes = UT_MIN(4096, gsf_input_size(input));
        gsf_input_read(input, iNumbytes, (guint8 *)(Buf));
        Buf[iNumbytes] = '\0';

        IEGraphicFileType ief = IE_ImpGraphic::fileTypeForContents(Buf,4096);
        if((ief == IEGFT_Unknown) || (ief == IEGFT_Bogus))
        {
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            g_object_unref (G_OBJECT (input));
            goto Cleanup;
        }
        g_object_unref (G_OBJECT (input));
        input = UT_go_file_open (file_name, NULL);
        size_t num_bytes = gsf_input_size(input);
        UT_Byte * bytes = (UT_Byte *) gsf_input_read(input, num_bytes,NULL );
        if(bytes == NULL)
        {
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            g_object_unref (G_OBJECT (input));
            goto Cleanup;
        }
        UT_ByteBuf * pBB = new UT_ByteBuf();
        pBB->append(bytes,num_bytes);
        g_object_unref (G_OBJECT (input));
        //
        // OK load the data into a GdkPixbuf
        //
        bool bLoadFailed = false;
        //
        GdkPixbuf * pixbuf = pixbufForByteBuf ( pBB);
        delete pBB;
        if(pixbuf == NULL)
        {
            //
            // Try a fallback loader here.
            //
            painter.drawChars (str.ucs4_str().ucs4_str(), 0, str.size(), pGr->tlu(12), pGr->tlu(static_cast<int>(m_preview->allocation.height / 2)) - pGr->getFontHeight(fnt)/2);
            bLoadFailed = true;
            goto Cleanup;
        }

        pImage = new GR_UnixImage(NULL,pixbuf);

        iImageWidth = gdk_pixbuf_get_width (pixbuf);
        iImageHeight = gdk_pixbuf_get_height (pixbuf);
        if (m_preview->allocation.width >= iImageWidth && m_preview->allocation.height >= iImageHeight)
            scale_factor = 1.0;
        else
            scale_factor = MIN( static_cast<double>(m_preview->allocation.width)/iImageWidth,
                                static_cast<double>(m_preview->allocation.height)/iImageHeight);

        scaled_width  = static_cast<int>(scale_factor * iImageWidth);
        scaled_height = static_cast<int>(scale_factor * iImageHeight);

        static_cast<GR_UnixImage *>(pImage)->scale(scaled_width,scaled_height);
        painter.drawImage(pImage,
                          pGr->tlu(static_cast<int>((m_preview->allocation.width  - scaled_width ) / 2)),
                          pGr->tlu(static_cast<int>((m_preview->allocation.height - scaled_height) / 2)));

        answer = 1;
    }

Cleanup:
    FREEP(file_name);
    DELETEP(pImage);
    DELETEP(pGr);
    DELETEP(pGraphic);

    return answer;
}
Example #20
0
void AP_Lists_preview::draw(void)
{
	UT_return_if_fail(m_pFont);

	GR_Painter painter(m_gc);

	m_gc->setFont(m_pFont);
	
	UT_RGBColor clrGrey = UT_RGBColor(128,128,128);
	UT_RGBColor clrBlack = UT_RGBColor(0,0,0);
	UT_sint32 iWidth = m_gc->tlu(getWindowWidth());
	UT_sint32 iHeight = m_gc->tlu(getWindowHeight());
	UT_UCSChar ucs_label[50];

	UT_sint32 iDescent = m_gc->getFontDescent();
	UT_sint32 iAscent = m_gc->getFontAscent();
	UT_sint32 iFont = iDescent + iAscent;
	m_iLine_height = iFont;
	//
	// clear our screen
	//
	if (m_bFirst == true)
	{
		painter.clearArea(0, 0, iWidth, iHeight);
	}
	m_gc->setColor(clrBlack);
	UT_sint32 yoff = m_gc->tlu(5) ;
	UT_sint32 xoff = m_gc->tlu(5) ;
	UT_sint32 i,ii,yloc,awidth,aheight,maxw;
	UT_sint32 twidth =0;
	UT_sint32 j,xy;
	float z,fwidth;
	// todo 6.5 should be the page width in inches
	float pagew = 2.0;
	aheight = m_gc->tlu(16);
	fwidth = static_cast<float>(m_gc->tdu(iWidth));

	z = (float)((fwidth - 2.0*static_cast<float>(m_gc->tdu(xoff))) /pagew);
  UT_sint32 indent = m_gc->tlu(static_cast<UT_sint32>( z*(m_fAlign+m_fIndent)));

	if(indent < 0)
		indent = 0;
	maxw = 0;
	for(i=0; i<4; i++)
	{
		UT_UCSChar * lv = getLists()->getListLabel(i);
		UT_sint32 len =0;

		if(lv != NULL)
		{
			//
			// This code is here because UT_UCS_copy_char is broken
			//
			len = UT_MIN(UT_UCS4_strlen(lv),51);
			for(j=0; j<=len;j++)
			{
				ucs_label[j] = *lv++;
			}

			ucs_label[len] = 0;

			len = UT_UCS4_strlen(ucs_label);
			yloc = yoff + iAscent + (iHeight - 2*yoff -iFont)*i/4;
			//    painter.drawChars(ucs_label,0,len,xoff+indent,yloc);
			twidth = m_gc->measureString(ucs_label,0,len,NULL);
			if(twidth > maxw)
				maxw = twidth;
		}
	}
	//
	// Work out where to put grey areas to represent text
	//
	UT_sint32 xx,yy;
	if(maxw > 0)
		maxw++;

        // UT_sint32 vspace = (iHeight - 2*yoff -iFont)*i/16;
	z = (float)((fwidth - 2.0*static_cast<float>(m_gc->tdu(xoff))) /(float)pagew);
	UT_sint32 ialign = m_gc->tlu(static_cast<UT_sint32>( z*m_fAlign));

	xx = xoff + ialign;
	xy = xoff + ialign;

	if(xx < (xoff + maxw + indent))
		xy = xoff + maxw + indent + m_gc->tlu(1);
	ii = 0;

	for(i=0; i<4; i++)
	{
		yloc = yoff + iAscent + (iHeight - 2*yoff -iFont)*i/4;
		for(j=0; j< 2; j++)
		{
			yy = yloc + m_gc->tlu(5) + j*m_gc->tlu(21);
			m_iLine_pos[ii++] = yy;
		}
	}
	//
	// Now finally draw the preview
	//

	UT_BidiCharType iDirection = getLists()->getBlock()->getDominantDirection();

	for(i=0; i<8; i++)
	{
		//
		// First clear the line
		//
		painter.clearArea(0, m_iLine_pos[i], iWidth, iHeight);
		if((i & 1) == 0)
		{
			//
			// Draw the text
			//
			UT_UCSChar * lv = getLists()->getListLabel(i/2);
			UT_sint32 len =0;

			if(lv != NULL)
			{
				len = UT_MIN(UT_UCS4_strlen(lv),49);

				if(len > 1 && XAP_App::getApp()->theOSHasBidiSupport() == XAP_App::BIDI_SUPPORT_GUI)
				{
					UT_bidiReorderString(lv, len, iDirection, ucs_label);
				}
				else
				{
					for(j=0; j<=len;j++)
						ucs_label[j] = *lv++;
				}

				ucs_label[len] = 0;
				len = UT_UCS4_strlen(ucs_label);
				yloc = yoff + iAscent + (iHeight - 2*yoff -iFont)*i/8;

				if(iDirection == UT_BIDI_RTL)
					painter.drawChars(ucs_label,0,len,iWidth - xoff - indent - maxw,yloc);
				else
					painter.drawChars(ucs_label,0,len,xoff+indent,yloc);

				yy = m_iLine_pos[i];
				awidth = iWidth - 2*xoff - xy;

				if(iDirection == UT_BIDI_RTL)
					painter.fillRect(clrGrey,xoff,yy,awidth,aheight);
				else
					painter.fillRect(clrGrey,xy,yy,awidth,aheight);
			}
			else
			{
				yy = m_iLine_pos[i];
				awidth = iWidth - 2*xoff - xy;

				if(iDirection == UT_BIDI_RTL)
					painter.fillRect(clrGrey,xoff,yy,awidth,aheight);
				else
					painter.fillRect(clrGrey,xy,yy,awidth,aheight);
			}
		}
		else
		{
			yy = m_iLine_pos[i];
			awidth = iWidth - 2*xoff - xx;

			if(iDirection == UT_BIDI_RTL)
				painter.fillRect(clrGrey,xoff,yy,awidth,aheight);
			else
				painter.fillRect(clrGrey,xy,yy,awidth,aheight);
		}
	}
}