void AP_UnixApp::cacheCurrentSelection(AV_View * pView) { if (pView) { // remember a temporary copy of the extent of the current // selection in the given view. this is intended for the // X11 middle mouse trick -- where we need to warp to a // new location and paste the current selection (not the // clipboard) and the act of warping clears the selection. // TODO if we ever support multiple view types, we'll have to // TODO change this. FV_View * pFVView = static_cast<FV_View *>(pView); pFVView->getDocumentRangeOfCurrentSelection(&m_cacheDocumentRangeOfSelection); m_cacheSelectionView = pView; m_cacheDeferClear = false; } else { if (m_cacheDeferClear) { m_cacheDeferClear = false; m_bHasSelection = false; } m_cacheSelectionView = NULL; } }
/*! get the current contents of the selection in the window last known to have a selection using one of the formats in the given list. \param formatList the list of acceptable formats \param ppData \param pLen a pointer to an integer representing the length \param pszFormatFound a pointer for the data to be returned in \return True if successful, false otherwise. */ bool AP_UnixApp::getCurrentSelection(const char** formatList, void ** ppData, UT_uint32 * pLen, const char **pszFormatFound) { int j; *ppData = NULL; // assume failure *pLen = 0; *pszFormatFound = NULL; if (!m_pViewSelection || !m_pFrameSelection || !m_bHasSelection) return false; // can't do it, give up. PD_DocumentRange dr; if (m_cacheSelectionView == m_pViewSelection) { dr = m_cacheDocumentRangeOfSelection; } else { // TODO if we ever support multiple view types, we'll have to // TODO change this. FV_View * pFVView = static_cast<FV_View *>(m_pViewSelection); pFVView->getDocumentRangeOfCurrentSelection(&dr); } m_selectionByteBuf.truncate(0); for (j=0; (formatList[j]); j++) { if ( AP_UnixClipboard::isRichTextTag(formatList[j]) ) { IE_Exp_RTF * pExpRtf = new IE_Exp_RTF(dr.m_pDoc); if (!pExpRtf) return false; // give up on memory errors pExpRtf->copyToBuffer(&dr,&m_selectionByteBuf); DELETEP(pExpRtf); goto ReturnThisBuffer; } if ( AP_UnixClipboard::isHTMLTag(formatList[j]) ) { IE_Exp_HTML * pExpHTML = new IE_Exp_HTML(dr.m_pDoc); if (!pExpHTML) return false; pExpHTML->set_HTML4 (!strcmp (formatList[j], "text/html")); pExpHTML->copyToBuffer(&dr,&m_selectionByteBuf); DELETEP(pExpHTML); goto ReturnThisBuffer; } if ( AP_UnixClipboard::isImageTag(formatList[j]) ) { // TODO: we have to make a good way to tell if the current selection is just an image FV_View * pView = NULL; if(getLastFocussedFrame()) pView = static_cast<FV_View*>(getLastFocussedFrame()->getCurrentView()); if (pView && !pView->isSelectionEmpty()) { // don't own, don't g_free const UT_ByteBuf * png = 0; pView->saveSelectedImage (&png); if (png && png->getLength() > 0) { m_selectionByteBuf.ins (0, png->getPointer (0), png->getLength ()); goto ReturnThisBuffer; } } } if ( AP_UnixClipboard::isTextTag(formatList[j]) ) { IE_Exp_Text * pExpText = new IE_Exp_Text(dr.m_pDoc, "UTF-8"); if (!pExpText) return false; pExpText->copyToBuffer(&dr,&m_selectionByteBuf); DELETEP(pExpText); goto ReturnThisBuffer; } // TODO add other formats as necessary } UT_DEBUGMSG(("Clipboard::getCurrentSelection: cannot create anything in one of requested formats.\n")); return false; ReturnThisBuffer: UT_DEBUGMSG(("Clipboard::getCurrentSelection: copying %d bytes in format [%s].\n", m_selectionByteBuf.getLength(),formatList[j])); *ppData = const_cast<void *>(static_cast<const void *>(m_selectionByteBuf.getPointer(0))); *pLen = m_selectionByteBuf.getLength(); *pszFormatFound = formatList[j]; return true; }