bool WinClipboard::getString(StringStorage *str)
{
  UINT strType = CF_UNICODETEXT;

  if (sizeof(TCHAR) == 1) {
    strType = CF_TEXT;
  }
  int uFormat = GetPriorityClipboardFormat(&strType, sizeof(UINT));

  if (uFormat == 0 || uFormat == -1) {
     return false;
  }
  if (OpenClipboard(m_hWnd)) {
     HANDLE hndData = GetClipboardData(uFormat); 

     if (hndData) {
        TCHAR *szData = (TCHAR *)GlobalLock(hndData); 
        StringStorage nativeClipboard = szData;
        //str->setString(szData);
        GlobalUnlock(hndData); 
        CloseClipboard();
        *str = removeCR(&nativeClipboard);
        return true;
      }
    CloseClipboard();
    return false;
  }
  return false;
}
Exemple #2
0
HRESULT touchmind::shell::Clipboard::PasteNodeModel(
    IN HWND hWnd,
    OUT std::shared_ptr<touchmind::model::node::NodeModel> &node,
    OUT std::vector<std::shared_ptr<model::link::LinkModel>> &links)
{
    HRESULT hr = _InitializeClipboard();
    if (SUCCEEDED(hr)) {
        int formatId = GetPriorityClipboardFormat(
                           &m_pFormatPriorityList.front(),
                           static_cast<int>(m_pFormatPriorityList.size()));
        if (formatId >= 0) {
            if (formatId == m_touchMindClipboardFormatId) {
                std::wstring s_xml;
                _PasteXML(hWnd, s_xml);
                LOG(SEVERITY_LEVEL_DEBUG) << s_xml;
                MSXML::IXMLDOMDocumentPtr pXMLDoc;
                hr = pXMLDoc.CreateInstance(__uuidof(MSXML::DOMDocument60), nullptr, CLSCTX_INPROC_SERVER);
                _bstr_t xml(s_xml.c_str());
                pXMLDoc->loadXML(xml);
                MSXML::IXMLDOMElementPtr pElement = pXMLDoc->firstChild;
                m_pNodeModelXMLDecoder->Decode(pElement, node, links, false, false);
            } else if (formatId == CF_UNICODETEXT) {
                std::wstring text;
                _PasteTEXT(hWnd, text);
                touchmind::converter::NodeModelToTextConverter textConverter;
                textConverter.SetSelectionManager(m_pSelectionManager);
                node = textConverter.FromText(text);
            }
        }
    }
    return hr;
}
//*****************************************************************************
//
// @pymethod int|win32clipboard|GetPriorityClipboardFormat|Returns the first available clipboard format in the specified list.
static PyObject *
py_getPriority_clipboard_format(PyObject* self, PyObject* args)
{

  // @pyparm sequence|formats||Sequence of integers identifying clipboard formats,
  // in priority order. For a description of the standard clipboard formats,
  // see Standard Clipboard Formats. 

  PyObject *formats;
  if (!PyArg_ParseTuple (args,"O:GetPriorityClipboardFormat", 
                         &formats)) {
    return NULL;
  }

  UINT *format_list;
  DWORD num_formats;
  if (!PyWinObject_AsDWORDArray(formats, (DWORD **)&format_list, &num_formats, FALSE))
	  return NULL;

  int rc;
  Py_BEGIN_ALLOW_THREADS;
  rc = GetPriorityClipboardFormat(format_list, num_formats);
  Py_END_ALLOW_THREADS;

  free(format_list);
  return PyInt_FromLong(rc);
  // @pyseeapi GetPriorityClipboardFormat
  // @pyseeapi Standard Clipboard Formats

  // @rdesc If the function succeeds, the return value is the first clipboard
  // format in the list for which data is available. If the clipboard is
  // empty, the return value is NULL. If the clipboard contains data, but not
  // in any of the specified formats, the return value is -1.

}
/* ************************************
* void WINAPI SetAutoView(HWND hwnd)
* 获取粘贴板的主要格式,并设置显示方式
**************************************/
void WINAPI SetAutoView(HWND hwnd)
{
	static UINT auPriorityList[] = {
		CF_OWNERDISPLAY,
		CF_TEXT,
		CF_ENHMETAFILE,
		CF_BITMAP
	};
	// 获取粘贴板主要格式
	// 设置显示模式
	// uFormat在WM_PAINT消息时引用
	uFormat = GetPriorityClipboardFormat(auPriorityList, 4);
	fAuto = TRUE;

	InvalidateRect(hwnd, NULL, TRUE);
	UpdateWindow(hwnd);
}
Exemple #5
0
//---------------------------------------------------------------------------
bool TVPClipboardGetText(ttstr & text)
{
	if(!OpenClipboard(Application->Handle)) return false;

	bool result = false;
	try
	{
		// select CF_UNICODETEXT or CF_TEXT
		UINT formats[2] = { CF_UNICODETEXT, CF_TEXT};
		int format = GetPriorityClipboardFormat(formats, 2);

		if(format == CF_UNICODETEXT)
		{
			// try to read unicode text
			HGLOBAL hglb = (HGLOBAL)GetClipboardData(CF_UNICODETEXT);
			if(hglb != NULL)
			{
				const tjs_char *p = (const tjs_char *)GlobalLock(hglb);
				if(p)
				{
					try
					{
						text = ttstr(p);
						result = true;
					}
					catch(...)
					{
						GlobalUnlock(hglb);
						throw;
					}
					GlobalUnlock(hglb);
				}
			}
		}
		else if(format == CF_TEXT)
		{
			// try to read ansi text
			HGLOBAL hglb = (HGLOBAL)GetClipboardData(CF_TEXT);
			if(hglb != NULL)
			{
				const char *p = (const char *)GlobalLock(hglb);
				if(p)
				{
					try
					{
						text = ttstr(p);
						result = true;
					}
					catch(...)
					{
						GlobalUnlock(hglb);
						throw;
					}
					GlobalUnlock(hglb);
				}
			}
		}
	}
	catch(...)
	{
		CloseClipboard();
		throw;
	}
	CloseClipboard();

	return result;
}
Exemple #6
0
PUBLIC LONGINT
GetScrapX (LONGINT type, char **h)
{
  UINT format;
  LONGINT retval;

  retval = -1;
  switch (type)
    {
    case T ('T', 'E', 'X', 'T'):
      format = CF_TEXT;
      break;
    default:
      format = ROMlib_executor_format (type);
      if (type == T('P','I','C','T'))
	{
	  typeof (format) newval;
	  UINT formats[2] = { format, CF_DIB };
	  
	  newval = GetPriorityClipboardFormat (formats, NELEM (formats));
	  if (newval != 0 && newval != (UINT) -1)
	    format = newval;
 	  }
      break;
    }
  if (IsClipboardFormatAvailable (format) && OpenClipboard (cygwin_sdlwindow ()))
    {
      HANDLE data;

      data = GetClipboardData (format);
      if (data)
	{
	  LPVOID lp;

	  lp = GlobalLock (data);
	  switch (type)
	    {
	    case T ('T', 'E', 'X', 'T'):
	      {
		int len;

		len = strlen (lp);
		retval = get_scrap_helper (h, lp, len, TRUE);
	      }
	    break;
	    default:
	      {
#if defined (SDL)
		if (format == CF_DIB)
		  retval = get_scrap_helper_dib (h, lp);
		else
#endif
		  {
		    int32 len;
		    len = *(int32 *)lp;

		    retval = get_scrap_helper (h, lp+sizeof(int32),
					       len, FALSE);
		  }
	      }
	      break;
	    }
	  GlobalUnlock (data);
	  CloseClipboard ();
	}
    }
  return retval;
}