本文整理汇总了C++中UT_return_val_if_fail函数的典型用法代码示例。如果您正苦于以下问题:C++ UT_return_val_if_fail函数的具体用法?C++ UT_return_val_if_fail怎么用?C++ UT_return_val_if_fail使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UT_return_val_if_fail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UT_return_val_if_fail
int XAP_Win32DialogBase::getListDataItem(UT_sint32 controlId, int nIndex)
{
UT_return_val_if_fail(IsWindow(m_hDlg), LB_ERR);
return SendDlgItemMessageW(m_hDlg, controlId, LB_GETITEMDATA, nIndex,0);
}
示例2: PP_RevisionsAttr
/*!
A helper function which translates a revision attribute associated with fragment of type pts at
pos dpos into arrays of attributes and properties suitable for passing into formating and other funcitons.
Revisions -- an instance of an empty PP_RevisionsAttr (i.e., PP_RevisionsAttr(NULL);)
ppRevAttrib -- pointers to arrays of attributes and properties; the actual props and attribs are
ppRevProps found inside the Revisions variable, so the returned pointers are only valid
within the Revisions scope !!!.
ppAttrib -- pointers to any attributes/properties that are to be added to this revision, can be NULL
ppProps
*/
bool pt_PieceTable::_translateRevisionAttribute(PP_RevisionAttr & Revisions, PT_AttrPropIndex indexAP,
PP_RevisionType eType,
const gchar ** & ppRevAttrib,
const gchar ** & ppRevProps,
const gchar ** ppAttrib,
const gchar ** ppProps)
{
// foolproofing
ppRevAttrib = NULL;
ppRevProps = NULL;
UT_return_val_if_fail(m_pDocument->isMarkRevisions(),false );
const PP_AttrProp * pRevisedAP = NULL;
const PP_AttrProp * pAP = NULL;
getAttrProp(indexAP, &pAP);
const gchar name[] = "revision";
if(pAP)
{
const gchar * pRev = NULL;
if(pAP->getAttribute(name, pRev))
{
// OK, the previous strux had a revision attribute, which was copied into the new
// strux. This revision attribute can contain significant properties and attributes
// which need to be preserved (such as list ids). However, we want the revision
// attributes from the addition and fmt records to be transfered into the regular
// attrs and props
Revisions.setRevision(pRev);
Revisions.pruneForCumulativeResult(m_pDocument);
pRevisedAP = Revisions.getLastRevision();
// it is legal of pRevisedAP to be NULL here -- it simply means that the cumulative
// effect of the revisions attribute was nothing at all (i.e., the highest revision
// was a deletion)
if(pRevisedAP)
{
PP_RevisionAttr Revisions2(NULL);
// now add the revision attribute
Revisions2.addRevision(m_pDocument->getRevisionId(),eType,ppAttrib,ppProps);
const_cast<PP_AttrProp*>(pRevisedAP)->setAttribute(name, Revisions2.getXMLstring());
}
}
}
if(!pRevisedAP)
{
// there was either no pAP or no pRev, just add the current revision ...
// we need to create a rev. instance in Revisions
Revisions.addRevision(m_pDocument->getRevisionId(),eType,ppAttrib,ppProps);
pRevisedAP = Revisions.getLastRevision();
UT_return_val_if_fail( pRevisedAP, false );
// now set the revision attribute of the revision
const_cast<PP_AttrProp*>(pRevisedAP)->setAttribute(name, Revisions.getXMLstring());
}
ppRevAttrib = pRevisedAP->getAttributes();
ppRevProps = pRevisedAP->getProperties();
return true;
}
示例3: UT_return_val_if_fail
/*!
* Sets given attribute in this PP_AttrProp bundle.
* Deals correctly with setting the PT_PROPS_ATTRIBUTE_NAME property:
* intercepts this call and appends properties instead.
*
* Because all mutations of attributes go through here, it is always the
* case that the props attribute is correctly handled.
*/
bool PP_AttrProp::setAttribute(const gchar * szName, const gchar * szValue)
{
// TODO when this assert fails, switch this file to use UT_XML_ version of str*() functions.
UT_return_val_if_fail (sizeof(char)==sizeof(gchar), false);
if (0 == strcmp(szName, PT_PROPS_ATTRIBUTE_NAME) && *szValue) // PROPS -- cut value up into properties
{
char * pOrig = NULL;
if (!(pOrig = g_strdup(szValue)))
{
UT_DEBUGMSG(("setAttribute: g_strdup() failed on [%s]\n",szValue));
return false;
}
// This function parses out CSS properties, separated by semicolons.
char *z = pOrig;
int bDone = 0;
while (!bDone)
{
// p will point to the property name. q will be the property value.
char *p = z;
char *q = p;
// skip the whitespace before the property name
while (isspace(*p))
p++;
// skip to the colon to find the value
while (*q && (*q != ':'))
q++;
// if there was no colon, this is invalid
if (!*q)
{
g_free(pOrig);
UT_DEBUGMSG(("props: %s\n", szValue));
return false;
}
// zero-out the colon, thus separating into two strings.
*q = 0;
q++;
// now, search ahead for the next semicolon, and separate this property from the next
z = q;
while (*z && (*z != ';'))
z++;
if (*z == ';')
{
*z = 0;
z++;
}
else
{
bDone = 1;
}
// skip the whitespace before the property value
while ((*q > 0) && isspace(*q))
q++;
setProperty(p, q);
}
g_free(pOrig);
return true;
}
else if (0 == strcmp(szName, PT_XID_ATTRIBUTE_NAME) && *szValue)
{
// XID is a unique id for the xml element / PT frag. Its function is to facilitate
// comparing/merging documents and we do not want it in the AP
return true;
}
else // not "PROPS" -- add to attribute list
{
UT_UTF8String url;
if (szValue && *szValue && (0 == strcmp(szName, "xlink:href") || 0 == strcmp(szName, "href")))
{
url = szValue;
url.decodeURL();
szValue = url.utf8_str();
}
if (!m_pAttributes)
{
m_pAttributes = new UT_GenericStringMap<gchar*>(5);
if (!m_pAttributes)
{
UT_DEBUGMSG(("setAttribute: could not allocate hash table.\n"));
return false;
//.........这里部分代码省略.........
示例4: getUserPrivateDirectory
bool AP_Win32App::initialize(void)
{
bool bSuccess = true;
const char * szUserPrivateDirectory = getUserPrivateDirectory();
bool bVerified = s_createDirectoryIfNecessary(szUserPrivateDirectory);
UT_return_val_if_fail (bVerified, false);
// create templates directory
UT_String sTemplates = szUserPrivateDirectory;
sTemplates += "/templates";
s_createDirectoryIfNecessary(sTemplates.c_str());
// load the preferences.
m_prefs = new AP_Win32Prefs();
UT_return_val_if_fail (m_prefs, false);
m_prefs->fullInit();
// now that preferences are established, let the xap init
m_pClipboard = new AP_Win32Clipboard();
UT_return_val_if_fail (m_pClipboard, false);
m_pEMC = AP_GetEditMethods();
UT_return_val_if_fail (m_pEMC, false);
m_pBindingSet = new AP_BindingSet(m_pEMC);
UT_return_val_if_fail (m_pBindingSet, false);
m_pMenuActionSet = AP_CreateMenuActionSet();
UT_return_val_if_fail (m_pMenuActionSet,false);
m_pToolbarActionSet = AP_CreateToolbarActionSet();
UT_return_val_if_fail (m_pToolbarActionSet,false);
//////////////////////////////////////////////////////////////////
// load the dialog and message box strings
//////////////////////////////////////////////////////////////////
{
// assume we will be using the builtin set (either as the main
// set or as the fallback set).
AP_BuiltinStringSet * pBuiltinStringSet = new AP_BuiltinStringSet(this,AP_PREF_DEFAULT_StringSet);
UT_return_val_if_fail (pBuiltinStringSet, false);
m_pStringSet = pBuiltinStringSet;
// see if we should load an alternate set from the disk
const char * szDirectory = NULL;
const char * szStringSet = NULL;
if ( (getPrefsValue(AP_PREF_KEY_StringSet,&szStringSet))
&& (szStringSet)
&& (*szStringSet)
&& (g_ascii_strcasecmp(szStringSet,AP_PREF_DEFAULT_StringSet) != 0))
{
getPrefsValueDirectory(true,AP_PREF_KEY_StringSetDirectory,&szDirectory);
UT_return_val_if_fail ((szDirectory) && (*szDirectory), false);
char * szPathname = (char *)UT_calloc(sizeof(char),strlen(szDirectory)+strlen(szStringSet)+100);
UT_return_val_if_fail (szPathname, false);
sprintf(szPathname,"%s%s%s.strings",
szDirectory,
((szDirectory[strlen(szDirectory)-1]=='\\') ? "" : "\\"),
szStringSet);
AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this);
UT_return_val_if_fail (pDiskStringSet, false);
if (pDiskStringSet->loadStringsFromDisk(szPathname))
{
pDiskStringSet->setFallbackStringSet(m_pStringSet);
m_pStringSet = pDiskStringSet;
UT_Language_updateLanguageNames();
UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname));
}
else
{
UT_DEBUGMSG(("Unable to load StringSet [%s] -- using builtin strings instead.\n",szPathname));
DELETEP(pDiskStringSet);
}
g_free(szPathname);
}
}
// AP_App::initilize() calls for us XAP_Win32App::initialize()
if (! AP_App::initialize())
return false;
// let various window types register themselves
if (!AP_Win32Frame::RegisterClass(this))
{
UT_DEBUGMSG(("couldn't register class\n"));
//.........这里部分代码省略.........
示例5: _getStruxFromPosition
bool pt_PieceTable::insertStrux(PT_DocPosition dpos,
PTStruxType pts,
const gchar ** attributes,
const gchar ** properties,
pf_Frag_Strux ** ppfs_ret)
{
if(m_pDocument->isMarkRevisions())
{
// This is just like the previous method, except that in addition to calling
// _translateRevisionAttribute() we also need to set the attrs and props
// passed to us.
pf_Frag_Strux * pfsContainer = NULL;
bool bFoundContainer = _getStruxFromPosition(dpos,&pfsContainer); // the orig. strux
UT_return_val_if_fail(bFoundContainer, false);
if(isEndFootnote(pfsContainer))
{
bFoundContainer = _getStruxFromFragSkip(pfsContainer,&pfsContainer);
UT_return_val_if_fail(bFoundContainer, false);
}
PT_AttrPropIndex indexAP = 0;
if (pfsContainer->getStruxType() == pts)
{
indexAP = pfsContainer->getIndexAP();
}
PP_RevisionAttr Revisions(NULL);
const gchar ** ppRevAttrs = NULL;
const gchar ** ppRevProps = NULL;
_translateRevisionAttribute(Revisions, indexAP, PP_REVISION_ADDITION,
ppRevAttrs, ppRevProps, NULL, NULL);
// count original attributes and the revision-inherited attributes
// and add them to the revision attribute
UT_uint32 iAttrCount = 0;
for (; attributes && attributes[iAttrCount]; iAttrCount+=2){}
UT_uint32 iRevAttrCount = 0;
for (; ppRevAttrs && ppRevAttrs[iRevAttrCount]; iRevAttrCount+=2){}
const gchar ** ppRevAttrib = NULL;
if(iAttrCount + iRevAttrCount > 0)
{
ppRevAttrib = new const gchar * [iAttrCount + iRevAttrCount + 1];
UT_return_val_if_fail( ppRevAttrib, false );
UT_uint32 i = 0;
for (i = 0; i < iAttrCount; ++i)
{
ppRevAttrib[i] = attributes[i];
}
for (; i < iRevAttrCount + iAttrCount; ++i)
{
ppRevAttrib[i] = ppRevAttrs[i - iAttrCount];
}
ppRevAttrib[i] = NULL;
}
//return _realChangeStruxFmt(PTC_AddFmt, dpos, dpos + iLen, ppRevAttrib,NULL,pts);
bool bRet = _realInsertStrux(dpos,pts,ppRevAttrib,properties,ppfs_ret);
delete [] ppRevAttrib;
return bRet;
}
else
{
return _realInsertStrux(dpos,pts,attributes,properties,ppfs_ret);
}
}
示例6: DIB
bool GR_Win32Image::convertToBuffer(UT_ByteBuf** ppBB) const
{
/*
The purpose of this routine is to convert our DIB (m_pDIB)
into a PNG image, storing it in a ByteBuf and returning it
to the caller.
*/
// Create our bytebuf
UT_ByteBuf* pBB = new UT_ByteBuf();
png_structp png_ptr;
png_infop info_ptr;
// initialize some libpng stuff
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
info_ptr = png_create_info_struct(png_ptr);
// libpng will longjmp back to here if a fatal error occurs
if (setjmp(png_jmpbuf(png_ptr)))
{
/* If we get here, we had a problem reading the file */
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
*ppBB = NULL;
return false;
}
// We want libpng to write to our ByteBuf, not stdio
png_set_write_fn(png_ptr, (void *)pBB, _png_write, _png_flush);
UT_uint32 iWidth = m_pDIB->bmiHeader.biWidth;
UT_uint32 iHeight;
/*
DIBs are usually bottom-up (backwards, if you ask me), but
sometimes they are top-down.
*/
bool bTopDown = false;
if (m_pDIB->bmiHeader.biHeight < 0)
{
iHeight = -(m_pDIB->bmiHeader.biHeight);
bTopDown = true;
}
else
{
iHeight = (m_pDIB->bmiHeader.biHeight);
}
png_set_IHDR(png_ptr,
info_ptr,
iWidth,
iHeight,
8, // 8 bits per channel (24 bits)
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
/* Write the file header information. REQUIRED */
png_write_info(png_ptr, info_ptr);
/*
The next big thing is writing out all of the pixels into the PNG
file. We've got quite a bit of code here to handle various kinds
of DIB images.
*/
UT_uint32 iSizeOfColorData = m_pDIB->bmiHeader.biClrUsed * sizeof(RGBQUAD);
RGBQUAD* pColors = (RGBQUAD*) (((unsigned char*) m_pDIB) + m_pDIB->bmiHeader.biSize);
UT_Byte* pBits = ((unsigned char*) m_pDIB) + m_pDIB->bmiHeader.biSize + iSizeOfColorData;
UT_Byte* pData = (UT_Byte*) g_try_malloc(iWidth * iHeight * 3);
UT_return_val_if_fail(pData, false); // TODO outofmem
UT_uint32 iRow;
UT_uint32 iCol;
UT_Byte* pRow;
UT_uint32 iBytesInRow;
/*
We can handle a DIB in either 4-bit, 8-bit, or 24-bit format.
The way we do this is allocate a single 24-bit buffer, and
regardless of what the format of the DIB is, we convert it to
our 24-bit buffer. Below, we will copy our 24-bit buffer into
the PNG file.
*/
switch (m_pDIB->bmiHeader.biBitCount)
{
case 4:
{
iBytesInRow = iWidth / 2;
if (iWidth % 2)
{
iBytesInRow++;
}
//.........这里部分代码省略.........
示例7: UT_DEBUGMSG
ConnectResult TCPAccountHandler::connect()
{
UT_DEBUGMSG(("TCPAccountHandler::connect()\n"));
AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager();
UT_return_val_if_fail(pManager, CONNECT_INTERNAL_ERROR);
UT_return_val_if_fail(!m_pDelegator, CONNECT_INTERNAL_ERROR);
UT_return_val_if_fail(!m_bConnected, CONNECT_ALREADY_CONNECTED);
UT_return_val_if_fail(!m_thread, CONNECT_INTERNAL_ERROR);
m_io_service.reset();
m_thread = new asio::thread(boost::bind(&asio::io_service::run, &m_io_service));
// set up the connection
if (getProperty("server") == "")
{
UT_sint32 port = _getPort(getProperties());
UT_DEBUGMSG(("Start accepting connections on port %d...\n", port));
try
{
IOServerHandler* pDelegator = new IOServerHandler(port,
boost::bind(&TCPAccountHandler::_handleAccept, this, _1, _2),
boost::bind(&TCPAccountHandler::handleEvent, this, _1), m_io_service);
m_pDelegator = pDelegator;
m_bConnected = true; // todo: ask it to the acceptor
pDelegator->run();
}
catch (asio::system_error se)
{
UT_DEBUGMSG(("Failed to start accepting connections: %s\n", se.what()));
_teardownAndDestroyHandler();
return CONNECT_FAILED;
}
catch (...)
{
UT_DEBUGMSG(("Caught unhandled server exception!\n"));
_teardownAndDestroyHandler();
return CONNECT_FAILED;
}
}
else
{
UT_DEBUGMSG(("Connecting to server %s on port %d...\n", getProperty("server").c_str(), _getPort(getProperties())));
try
{
asio::ip::tcp::resolver resolver(m_io_service);
asio::ip::tcp::resolver::query query(getProperty("server"), getProperty("port"));
asio::ip::tcp::resolver::iterator iterator(resolver.resolve(query));
bool connected = false;
boost::shared_ptr<Session> session_ptr(new Session(m_io_service, boost::bind(&TCPAccountHandler::handleEvent, this, _1)));
while (iterator != tcp::resolver::iterator())
{
try
{
UT_DEBUGMSG(("Attempting to connect...\n"));
session_ptr->connect(iterator);
UT_DEBUGMSG(("Connected!\n"));
connected = true;
break;
}
catch (asio::system_error se)
{
UT_DEBUGMSG(("Connection attempt failed: %s\n", se.what()));
// make sure we close the socket after a failed attempt, as it
// may have been opened by the connect() call.
try { session_ptr->getSocket().close(); } catch(...) {}
}
iterator++;
}
if (!connected)
{
UT_DEBUGMSG(("Giving up to connecting to server!\n"));
_teardownAndDestroyHandler();
return CONNECT_FAILED;
}
session_ptr->asyncReadHeader();
m_bConnected = true; // todo: ask it to the socket
// Add a buddy
TCPBuddyPtr pBuddy = boost::shared_ptr<TCPBuddy>(new TCPBuddy(this,
session_ptr->getRemoteAddress(),
boost::lexical_cast<std::string>(session_ptr->getRemotePort())));
addBuddy(pBuddy);
m_clients.insert(std::pair<TCPBuddyPtr, boost::shared_ptr<Session> >(pBuddy, session_ptr));
}
catch (asio::system_error se)
{
UT_DEBUGMSG(("Failed to resolve %s:%d: %s\n", getProperty("server").c_str(), _getPort(getProperties()), se.what()));
_teardownAndDestroyHandler();
return CONNECT_FAILED;
}
}
if (!m_bConnected)
return CONNECT_FAILED;
//.........这里部分代码省略.........
示例8: UT_DEBUGMSG
bool AbiCollab::_handleSessionTakeover(AbstractSessionTakeoverPacket* pPacket, BuddyPtr collaborator)
{
UT_DEBUGMSG(("AbiCollab::_handleSessionTakeover()\n"));
UT_return_val_if_fail(pPacket, false);
UT_return_val_if_fail(collaborator, false);
AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager();
UT_return_val_if_fail(pManager, false);
switch (m_eTakeoveState)
{
case STS_NONE:
{
// we only accept a SessionTakeoverRequest or MasterChangeRequest packet
UT_return_val_if_fail(pPacket->getClassType() == PCT_SessionTakeoverRequestPacket, false);
// we can only allow such a packet from the controller
UT_return_val_if_fail(m_pController == collaborator, false);
// handle the SessionTakeoverRequestPacket packet
m_pProposedController = BuddyPtr();
m_vApprovedReconnectBuddies.clear();
SessionTakeoverRequestPacket* strp = static_cast<SessionTakeoverRequestPacket*>(pPacket);
m_bProposedController = strp->promote();
if (m_bProposedController)
{
for (std::vector<std::string>::const_iterator cit = strp->getBuddyIdentifiers().begin(); cit != strp->getBuddyIdentifiers().end(); cit++)
m_vApprovedReconnectBuddies[*cit] = false;
}
else
{
UT_return_val_if_fail(strp->getBuddyIdentifiers().size() == 1, false);
BuddyPtr pBuddy = pManager->constructBuddy(strp->getBuddyIdentifiers()[0], collaborator);
UT_return_val_if_fail(pBuddy, false);
m_pProposedController = pBuddy;
}
// inform the master that we received the takeover request
SessionTakeoverAckPacket stap(m_sId, m_pDoc->getDocUUIDString());
collaborator->getHandler()->send(&stap, collaborator);
m_eTakeoveState = STS_SENT_TAKEOVER_ACK;
return true;
}
return false;
case STS_SENT_TAKEOVER_REQUEST:
{
// we only accept SessionTakeoverAck packets
UT_return_val_if_fail(pPacket->getClassType() == PCT_SessionTakeoverAckPacket, false);
// we can only receive SessionTakeoverAck packets when we are the master
UT_return_val_if_fail(!m_pController, false);
// we should have a proposed master
UT_return_val_if_fail(m_pProposedController, false);
// a slave should only ack once
UT_return_val_if_fail(!_hasAckedSessionTakeover(collaborator), false);
// handle the SessionTakeoverAck packet
m_mAckedSessionTakeoverBuddies[collaborator] = true;
// check if every slave has acknowledged the session takeover
// TODO: handle dropouts
if (m_vCollaborators.size() == 1 ||
m_mAckedSessionTakeoverBuddies.size() == m_vCollaborators.size())
{
// ... our tour of duty is done
_shutdownAsMaster();
m_eTakeoveState = STS_NONE;
return true;
}
}
return true;
case STS_SENT_TAKEOVER_ACK:
// we only accept a SessionFlushed or SessionReconnectRequest packet
UT_return_val_if_fail(
pPacket->getClassType() == PCT_SessionFlushedPacket ||
pPacket->getClassType() == PCT_SessionReconnectRequestPacket,
false
);
if (pPacket->getClassType() == PCT_SessionReconnectRequestPacket)
{
// we only accept a SessionReconnectRequest when we are the proposed master
UT_return_val_if_fail(m_bProposedController, false);
// we only allow an incoming SessionReconnectRequest packet from a buddy
// that is in the buddy list we received from the master, and we didn't receive
// such a packet from him before
bool allow = false;
for (std::map<std::string, bool>::iterator it = m_vApprovedReconnectBuddies.begin(); it != m_vApprovedReconnectBuddies.end(); it++)
{
// TODO: is it a good idea to compare descriptors with full session information?
if ((*it).first == collaborator->getDescriptor(true) && (*it).second == false)
{
(*it).second = true;
allow = true;
break;
}
}
UT_return_val_if_fail(allow, false);
//.........这里部分代码省略.........
示例9: switch
//.........这里部分代码省略.........
}
}
if (fragOffset == 0)
{
// we are to insert it immediately before this fragment.
// if we are coalescable, just prepend it to this fragment.
if ( (pft->getIndexAP()==indexAP)
&& m_varset.isContiguous(bi,length,pft->getBufIndex()))
{
// new text is contiguous, we just update the offset and length of
// of this fragment.
pft->adjustOffsetLength(bi,length+fragLen);
// see if this (enlarged) fragment is now contiguous with the
// one that preceeds us (this can happen after a delete-char followed
// by undo). if so, we coalesce them.
if (pft->getPrev() && (pft->getPrev()->getType() == pf_Frag::PFT_Text)&&(pft->getPrev()->getField()==NULL))
{
pf_Frag_Text * pftPrev = static_cast<pf_Frag_Text *>(pft->getPrev());
if ( (pft->getIndexAP() == pftPrev->getIndexAP())
&& m_varset.isContiguous(pftPrev->getBufIndex(),pftPrev->getLength(),pft->getBufIndex()))
{
pftPrev->changeLength(pftPrev->getLength()+pft->getLength());
m_fragments.unlinkFrag(pft);
delete pft;
}
}
return true;
}
// one last attempt to coalesce. if we are at the beginning of
// the fragment, and this fragment and the previous fragment have
// the same properties, and the character data is contiguous with
// it, let's stick it in the previous fragment.
pf_Frag * pfPrev = pft->getPrev();
if (pfPrev && pfPrev->getType()==pf_Frag::PFT_Text && (pfPrev->getField()==NULL))
{
pf_Frag_Text * pftPrev = static_cast<pf_Frag_Text *>(pfPrev);
UT_uint32 prevLength = pftPrev->getLength();
if ( (pftPrev->getIndexAP() == indexAP)
&& (m_varset.isContiguous(pftPrev->getBufIndex(),prevLength,bi)))
{
pftPrev->changeLength(prevLength+length);
return true;
}
}
}
}
// new text is not contiguous, we need to insert one or two new text
// fragment(s) into the list. first we construct a new text fragment
// for the data that we inserted.
pf_Frag_Text * pftNew = new pf_Frag_Text(this,bi,length,indexAP,pField);
if (!pftNew)
return false;
if (fragOffset == 0)
{
// if change is at the beginning of the fragment, we insert a
// single new text fragment before the one we found.
m_fragments.insertFrag(pf->getPrev(),pftNew);
return true;
}
UT_uint32 fragLen = pf->getLength();
if (fragLen==fragOffset)
{
// if the change is after this fragment, we insert a single
// new text fragment after the one we found.
m_fragments.insertFrag(pf,pftNew);
return true;
}
// if the change is in the middle of the fragment, we construct
// a second new text fragment for the portion after the insert.
UT_return_val_if_fail (pft,false);
UT_uint32 lenTail = pft->getLength() - fragOffset;
PT_BufIndex biTail = m_varset.getBufIndex(pft->getBufIndex(),fragOffset);
pf_Frag_Text * pftTail = new pf_Frag_Text(this,biTail,lenTail,pft->getIndexAP(),pft->getField());
if (!pftTail)
return false;
pft->changeLength(fragOffset);
m_fragments.insertFrag(pft,pftNew);
m_fragments.insertFrag(pftNew,pftTail);
return true;
}
示例10: UT_return_val_if_fail
/*!
Get next byte from file
\param b Reference to the byte
*/
bool ImportStreamFile::_getByte(unsigned char &b)
{
UT_return_val_if_fail(m_pFile, false);
return (gsf_input_read(m_pFile, 1, &b) != NULL);
}
示例11: UT_DEBUGMSG
/*!
* Take a packet, interpret it's contents and apply the implied operations on the document.
*/
bool ABI_Collab_Import::_import(const SessionPacket& packet, UT_sint32 iImportAdjustment, BuddyPtr pCollaborator, bool inGlob)
{
UT_DEBUGMSG(("ABI_Collab_Import::_import() - packet class type: %d, iImportAdjustment: %d\n", packet.getClassType(), iImportAdjustment));
UT_return_val_if_fail(pCollaborator, false);
switch (packet.getClassType())
{
case PCT_GlobSessionPacket:
{
const GlobSessionPacket* gp = static_cast<const GlobSessionPacket*>(&packet);
UT_return_val_if_fail(gp->getPackets().size() > 0, false);
// store the last seen revision from this collaborator (it is immediately used by the export)
m_remoteRevs[pCollaborator] = gp->getRev();
for (UT_uint32 j = 0; j < gp->getPackets().size(); j++)
{
SessionPacket* pGlobPacket = gp->getPackets()[j];
if (pGlobPacket)
{
bool res = _import(*pGlobPacket, iImportAdjustment, pCollaborator, true); // yay for recursion :)
if (!res)
{
UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
}
}
}
return true;
}
case PCT_SignalSessionPacket:
{
const SignalSessionPacket* sp = static_cast<const SignalSessionPacket*>(&packet);
m_pDoc->signalListeners(sp->getSignalType());
return true;
}
case PCT_RevertSessionPacket:
{
const RevertSessionPacket* rrp = static_cast<const RevertSessionPacket*>(&packet);
UT_DEBUGMSG(("Revert packet seen on import for rev: %d\n", rrp->getRev()));
if (m_iAlreadyRevertedRevs.size() == 0 || m_iAlreadyRevertedRevs.front() != rrp->getRev())
{
UT_DEBUGMSG(("Incoming revert for revision %d, which we didn't detect locally (m_iAlreadyRevertedRev: %d)!\n", rrp->getRev(), m_iAlreadyRevertedRevs.front()));
UT_DEBUGMSG(("DOCUMENT OUT OF SYNC DETECTED!!!!\n"));
UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED);
return false;
}
m_iAlreadyRevertedRevs.pop_front();
return true;
}
case PCT_RevertAckSessionPacket:
{
UT_DEBUGMSG(("RevertAck packet seen on import for rev: %d\n", static_cast<const RevertAckSessionPacket*>(&packet)->getRev()));
// remove this collaborator from our revert ack list; he can play again...
for (std::vector<std::pair<BuddyPtr, UT_sint32> >::iterator it = m_revertSet.begin(); it != m_revertSet.end(); it++)
{
if ((*it).first == pCollaborator)
{
UT_DEBUGMSG(("Found collaborator %s on our revert ack list with rev %d! Removing him from the list...\n", (*it).first->getDescription().utf8_str(), (*it).second));
UT_ASSERT_HARMLESS((*it).second == static_cast<const RevertAckSessionPacket*>(&packet)->getRev());
m_revertSet.erase(it);
return true;
}
}
UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
return false;
}
default:
// silly C++ can't switch on ranges
if (packet.getClassType() >= _PCT_FirstChangeRecord && packet.getClassType() <= _PCT_LastChangeRecord)
{
const ChangeRecordSessionPacket* crp = static_cast<const ChangeRecordSessionPacket*>(&packet);
UT_DEBUGMSG(("It's safe to import this packet\n"));
UT_DEBUGMSG(("For CR number %d requested point %d adjustment %d \n", crp->getRev(), crp->getPos(), iImportAdjustment));
PT_DocPosition pos = static_cast<PT_DocPosition>(crp->getPos() + iImportAdjustment);
UT_ASSERT(pos <= getEndOfDoc());
if (!inGlob)
{
// store the last seen revision from this collaborator (it is immediately used by the export)
// NOTE: if this changerecord is part of a glob, then we don't do this; we'll have
// already set the revision of the glob itself as the last seen one
m_remoteRevs[pCollaborator] = crp->getRev();
}
// todo: remove these temp vars
PT_DocPosition iPos2 = 0;
//.........这里部分代码省略.........
示例12: UT_return_val_if_fail
bool pt_PieceTable::_realInsertSpan(PT_DocPosition dpos,
const UT_UCSChar * p,
UT_uint32 length,
const gchar ** attributes,
const gchar ** properties,
fd_Field * pField,
bool bAddChangeRec)
{
// insert character data into the document at the given position.
UT_return_val_if_fail (m_pts==PTS_Editing, false);
// get the fragment at the given document position.
pf_Frag * pf = NULL;
PT_BlockOffset fragOffset = 0;
bool bFound = getFragFromPosition(dpos,&pf,&fragOffset);
UT_return_val_if_fail (bFound,false);
// append the text data to the end of the current buffer.
PT_BufIndex bi;
if (!m_varset.appendBuf(p,length,&bi))
return false;
pf_Frag_Strux * pfs = NULL;
bool bFoundStrux = _getStruxFromFrag(pf,&pfs);
UT_return_val_if_fail (bFoundStrux,false);
if(isEndFootnote((pf_Frag *)pfs))
{
bFoundStrux = _getStruxFromFragSkip((pf_Frag *) pfs,&pfs);
}
UT_return_val_if_fail (pfs,false);
if(pfs->getStruxType() == PTX_EndFrame)
{
bFoundStrux = _getStruxFromFragSkip((pf_Frag *) pfs,&pfs);
}
// we just did a getFragFromPosition() which gives us the
// the thing *starting* at that position. if we have a
// fragment boundary at that position, it's sort of arbitrary
// whether we treat this insert as a prepend to the one we just found
// or an append to the previous one (when it's a text frag).
// in the normal case, we want the Attr/Prop of a character
// insertion to take the AP of the thing to the immediate
// left (seems to be what MS-Word and MS-WordPad do). It's also
// useful when the user hits the BOLD button (without a)
// selection) and then starts typing -- ideally you'd like
// all of the text to have bold not just the first. therefore,
// we will see if we are on a text-text boundary and backup
// (and thus appending) to the previous.
bool bNeedGlob = false;
PT_AttrPropIndex indexAP = 0;
if ( (fragOffset==0) && (pf->getPrev()) )
{
bool bRightOfFmtMark = (pf->getPrev()->getType() == pf_Frag::PFT_FmtMark);
if (bRightOfFmtMark)
{
// if we're just to the right of a _FmtMark, we want to replace
// it with a _Text frag with the same attr/prop (we
// only used the _FmtMark to remember a toggle format
// before we had text for it).
pf_Frag_FmtMark * pfPrevFmtMark = static_cast<pf_Frag_FmtMark *>(pf->getPrev());
indexAP = pfPrevFmtMark->getIndexAP();
if (_lastUndoIsThisFmtMark(dpos))
{
// if the last thing in the undo history is the insertion of this
// _FmtMark, then let's remember the indexAP, do an undo, and then
// insert the text. this way the only thing remaining in the undo
// is the insertion of this text (with no globbing around it). then
// a user-undo will undo all of the coalesced text back to this point
// and leave the insertion point as if the original InsertFmtMark
// had never happened.
//
// we don't allow consecutive FmtMarks, but the undo may be a
// changeFmtMark and thus just re-change the mark frag rather
// than actually deleting it. so we loop here to get back to
// the original insertFmtMark (this is the case if the user hit
// BOLD then ITALIC then UNDERLINE then typed a character).
do { undoCmd(); } while (_lastUndoIsThisFmtMark(dpos));
}
else
{
// for some reason, something else has happened to the document
// since this _FmtMark was inserted (perhaps it was one that we
// inserted when we did a paragraph break and inserted several
// to remember the current inline formatting).
//
// here we have to do it the hard way and use a glob and an
// explicit deleteFmtMark. note that this messes up the undo
// coalescing. that is, if the user starts typing at this
// position and then hits UNDO, we will erase all of the typing
// except for the first character. the second UNDO, will erase
// the first character and restores the current FmtMark. if the
// user BACKSPACES instead of doing the second UNDO, both the
//.........这里部分代码省略.........
示例13: UT_GetDefaultPrinterName
wchar_t * UT_GetDefaultPrinterName()
{
UT_uint32 iBufferSize = 128; // will become 2x bigger immediately in the loop
wchar_t * pPrinterName = NULL;
DWORD rc;
do
{
iBufferSize *= 2;
if(pPrinterName)
g_free(pPrinterName);
pPrinterName = (wchar_t *) UT_calloc(sizeof(wchar_t),iBufferSize);
UT_return_val_if_fail( pPrinterName, NULL );
// the method of obtaining the name is version specific ...
OSVERSIONINFOW osvi;
DWORD iNeeded, iReturned, iBuffSize;
LPPRINTER_INFO_5W pPrinterInfo;
wchar_t* p;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
GetVersionExW(&osvi);
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
// get size of the buffer needed to call enum printers
if (!EnumPrintersW(PRINTER_ENUM_DEFAULT,NULL,5,NULL,0,&iNeeded,&iReturned))
{
if ((rc = GetLastError()) != ERROR_INSUFFICIENT_BUFFER)
{
return NULL;
}
}
// allocate the buffer
if ((pPrinterInfo = (LPPRINTER_INFO_5W)LocalAlloc(LPTR,iNeeded)) == NULL)
{
rc = GetLastError();
}
else
{
// now get the default printer
if (!EnumPrintersW(PRINTER_ENUM_DEFAULT,NULL,5,
(LPBYTE) pPrinterInfo,iNeeded,&iNeeded,&iReturned))
{
rc = GetLastError();
}
else
{
if (iReturned > 0)
{
// here we copy the name to our own buffer
if ((DWORD) wcslen(pPrinterInfo->pPrinterName) > iBufferSize-1)
{
rc = ERROR_INSUFFICIENT_BUFFER;
}
else
{
wcscpy(pPrinterName,pPrinterInfo->pPrinterName);
rc = ERROR_SUCCESS;
}
}
else
{
*pPrinterName = '0';
rc = ERROR_SUCCESS;
}
}
LocalFree(pPrinterInfo);
}
}
else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if (osvi.dwMajorVersion >= 5) /* Windows 2000 or later */
{
iBuffSize = iBufferSize;
HMODULE hWinSpool = LoadLibraryW(L"winspool.drv");
if (!hWinSpool)
return NULL;
HRESULT (WINAPI * fnGetDefaultPrinter)(LPWSTR, LPDWORD) =
(HRESULT (WINAPI * )(LPWSTR, LPDWORD)) GetProcAddress(hWinSpool, GETDEFAULTPRINTER);
if (!fnGetDefaultPrinter)
{
FreeLibrary(hWinSpool);
return NULL;
}
bool i =false;
if (!fnGetDefaultPrinter(pPrinterName,&iBuffSize))
i = true;
if(i)
rc = GetLastError();
else
//.........这里部分代码省略.........
示例14: Revisions
bool pt_PieceTable::insertSpan(PT_DocPosition dpos,
const UT_UCSChar * p,
UT_uint32 length, fd_Field * pField,
bool bAddChangeRec)
{
if(bAddChangeRec && m_pDocument->isMarkRevisions())
{
PP_RevisionAttr Revisions(NULL);
const gchar ** ppRevAttrib = NULL;
const gchar ** ppRevProps = NULL;
pf_Frag * pf = NULL;
PT_BlockOffset fragOffset = 0;
bool bFound = getFragFromPosition(dpos,&pf,&fragOffset);
UT_return_val_if_fail( bFound, false );
if(pf->getType() == pf_Frag::PFT_EndOfDoc)
pf = pf->getPrev();
UT_return_val_if_fail( pf, false );
PT_AttrPropIndex indexAP = pf->getIndexAP();
_translateRevisionAttribute(Revisions, indexAP, PP_REVISION_ADDITION, ppRevAttrib, ppRevProps, 0, 0);
//return _realChangeSpanFmt(PTC_AddFmt, dpos, dpos + length, ppRevAttrib, ppRevProps);
return _realInsertSpan(dpos, p, length, ppRevAttrib, ppRevProps, pField, bAddChangeRec);
}
else if(bAddChangeRec)
{
// When the revision marking is not on, we need to make sure
// that the text does not get inserted with a leftover
// revision attribute (e.g., if we are inserting it next to
// revisioned text
const gchar name[] = "revision";
const gchar * ppRevAttrib[5];
ppRevAttrib[0] = name;
ppRevAttrib[1] = NULL;
ppRevAttrib[2] = NULL;
ppRevAttrib[3] = NULL;
ppRevAttrib[4] = NULL;
const gchar * pRevision = NULL;
// first retrive the fmt we have (_realChangeSpanFmt()) is
// quite involved, so we want to avoid calling it, if we can)
pf_Frag * pf1;
PT_BlockOffset Offset1;
if(!getFragFromPosition(dpos, &pf1, &Offset1))
return false;
const PP_AttrProp * pAP;
if(_getSpanAttrPropHelper(pf1, &pAP))
{
const gchar * szStyleNameVal = NULL;
pAP->getAttribute(PT_STYLE_ATTRIBUTE_NAME,szStyleNameVal);
if(!pAP->getAttribute(name, pRevision))
{
return _realInsertSpan(dpos, p, length,NULL , NULL, pField, bAddChangeRec);
}
if(szStyleNameVal != NULL)
{
ppRevAttrib[2] = PT_STYLE_ATTRIBUTE_NAME;;
ppRevAttrib[3] = szStyleNameVal;
}
//if(!_realChangeSpanFmt(PTC_RemoveFmt, dpos, dpos+length, ppRevAttrib,NULL))
// return false;
return _realInsertSpan(dpos, p, length, ppRevAttrib, NULL, pField, bAddChangeRec);
}
else
{
// no AP, this is probably OK
UT_DEBUGMSG(("pt_PieceTable::insertSpan: no AP\n"));
return _realInsertSpan(dpos, p, length, NULL, NULL, pField, bAddChangeRec);
}
}
else
{
return _realInsertSpan(dpos, p, length, NULL, NULL, pField, bAddChangeRec);
}
}
示例15: UT_return_val_if_fail
/*!
* The idea is to create a
* new image from the rectangular segment in device units defined by
* UT_Rect rec. The Image should be deleted by the calling routine.
*/
GR_Image * GR_Win32Image::createImageSegment(GR_Graphics * pG,const UT_Rect & rec)
{
// this code assumes 24 bit RGB bitmaps ...
UT_return_val_if_fail(pG && m_pDIB && m_pDIB->bmiHeader.biBitCount == 24, NULL);
// the ration of x and y coords for the graphics class
double fXYRatio = ((GR_Win32Graphics *)pG)->getXYRatio();
// We have three different coordinate systems here:
//
// rec: the requested segment size, in layout units
//
// m_pDIB->bmiHeader.biHeight/Width(): physical size of the bitmap
//
// getDisplayWidth()/Height() : size in device units for which this image was to be
// rendered
//
// From these we need to work out the size/offset of the segment in the DIB
// coordinaces
// these are the DIB physical dimensions of the original
UT_sint32 dH = m_pDIB->bmiHeader.biHeight;
UT_sint32 dW = m_pDIB->bmiHeader.biWidth;
// this is the internal scaling of the orginal DIB, which we need to workout
// relationship between display units and DIB units; we need to use separate factors
// for x and y axis, since the proportions of the DIB have no formal relationship to
// the dimensions of the displayed rectangle (e.g., the display image could be
// cropped).
double fDibScaleFactorX = (double) dW / (double)getDisplayWidth();
double fDibScaleFactorY = (double) dH / (double)getDisplayHeight();
// these are the requested dimensions in device units
UT_sint32 widthDU = (UT_sint32)((double)pG->tdu(rec.width) * fXYRatio);
UT_sint32 heightDU = pG->tdu(rec.height);
UT_sint32 xDU = (UT_sint32)((double)pG->tdu(rec.left) * fXYRatio);
UT_sint32 yDU = pG->tdu(rec.top);
// now convert the DUs into DIB units -- these are the values we need to work with
// when copying the image segment
UT_sint32 widthDIB = (UT_sint32)((double)widthDU * fDibScaleFactorX);
UT_sint32 heightDIB = (UT_sint32)((double)heightDU * fDibScaleFactorY);
UT_sint32 xDIB = (UT_sint32)((double)xDU * fDibScaleFactorX);
UT_sint32 yDIB = (UT_sint32)((double)yDU * fDibScaleFactorY);
if(xDIB < 0)
{
xDIB = 0;
}
if(yDIB < 0)
{
yDIB = 0;
}
if(heightDIB > dH)
{
heightDIB = dH;
}
if(widthDIB > dW)
{
widthDIB = dW;
}
if(xDIB + widthDIB > dW)
{
widthDIB = dW - xDIB;
}
if(yDIB + heightDIB > dH)
{
heightDIB = dH - yDIB;
}
if(widthDIB < 0)
{
xDIB = dW -1;
widthDIB = 1;
}
if(heightDIB < 0)
{
yDIB = dH -1;
heightDIB = 1;
}
UT_String sName("");
getName(sName);
UT_String sSub("");
UT_String_sprintf(sSub,"_segment_%d_%d_%d_%d",xDIB,yDIB,widthDIB,heightDIB);
sName += sSub;
GR_Win32Image * pImage = new GR_Win32Image(sName.c_str());
UT_return_val_if_fail( pImage, NULL );
// now allocate memory -- mostly copied from convertFromBuffer()
UT_uint32 iBytesInRow = widthDIB * 3;
if (iBytesInRow % 4)
{
//.........这里部分代码省略.........