예제 #1
0
void ModuleEntry::ShutDown()
{
	ModuleEntry * pme;

	for (pme = s_pmeFirst; pme; pme = pme->m_pobjNext)
	{
		try
		{
			pme->ProcessDetach();
		}
		catch (const Throwable & thr)
		{
			WarnHr(thr.Error());
		}
		catch (...)
		{
			return WarnHr(E_FAIL);
		}
	}

	// Uninitialize COM, first shutting down the clipboard.
	if (s_qdobjClipboard.Ptr())
	{
		hr = OleIsCurrentClipboard(s_qdobjClipboard.Ptr());
		WarnHr(hr);
		if (hr == S_OK)
		{
			WarnHr(OleFlushClipboard());
		}
		s_qdobjClipboard.Clear();
	}
	OleUninitialize();
}
예제 #2
0
bool wxClipboard::Flush()
{
#if wxUSE_OLE_CLIPBOARD
    if (m_lastDataObject)
    {
        // don't touch data set by other applications
        HRESULT hr = OleIsCurrentClipboard(m_lastDataObject);
        m_lastDataObject = NULL;
        if (S_OK == hr)
        {
            hr = OleFlushClipboard();
            if ( FAILED(hr) )
            {
                wxLogApiError(wxT("OleFlushClipboard"), hr);

                return false;
            }
            return true;
        }
    }
    return false;
#else // !wxUSE_OLE_CLIPBOARD
    return false;
#endif // wxUSE_OLE_CLIPBOARD/!wxUSE_OLE_CLIPBOARD
}
예제 #3
0
bool QClipboard::event(QEvent *e)
{
    if (e->type() != QEvent::Clipboard)
        return QObject::event(e);

    QClipboardData *d = clipboardData();

    MSG *m = (MSG *)((QClipboardEvent*)e)->data();
    if (!m) {
        // this is sent to render all formats at app shut down
        if (ownsClipboard()) {
            OleFlushClipboard();
            d->releaseIData();
        }
        return true;
    }

    bool propagate = false;

    if (m->message == WM_CHANGECBCHAIN) {
        if ((HWND)m->wParam == d->nextClipboardViewer)
            d->nextClipboardViewer = (HWND)m->lParam;
        else
            propagate = true;
    } else if (m->message == WM_DRAWCLIPBOARD) {
        emitChanged(QClipboard::Clipboard);
        if (!ownsClipboard() && d->iData)
            // clean up the clipboard object if we no longer own the clipboard
            d->releaseIData();
        propagate = true;
    }
    if (propagate && d->nextClipboardViewer) {
        if (ptrIsHungAppWindow == 0) {
            QSystemLibrary library(QLatin1String("User32"));
            ptrIsHungAppWindow = (PtrIsHungAppWindow)library.resolve("IsHungAppWindow");
        }
        if (ptrIsHungAppWindow && ptrIsHungAppWindow(d->nextClipboardViewer)) {
            qWarning("%s: Cowardly refusing to send clipboard message to hung application...", Q_FUNC_INFO);
        } else if (isProcessBeingDebugged(d->nextClipboardViewer)) {
            // Also refuse if the process is being debugged, specifically, if it is
            // displaying a runtime assert, which is not caught by isHungAppWindow().
            qWarning("%s: Cowardly refusing to send clipboard message to application under debugger...", Q_FUNC_INFO);
        } else {
            SendMessage(d->nextClipboardViewer, m->message, m->wParam, m->lParam);
        }
    }

    return true;
}
예제 #4
0
파일: ComUtil.cpp 프로젝트: hufuman/xindows
//+-------------------------------------------------------------------------
//
//  Member:     FormSetClipboard(IDataObject *pdo)
//
//  Synopsis:   helper function to set the clipboard contents
//
//--------------------------------------------------------------------------
HRESULT FormSetClipboard(IDataObject* pdo)
{
    HRESULT hr;
    hr = OleSetClipboard(pdo);

    if(!hr && !GetPrimaryObjectCount())
    {
        hr = OleFlushClipboard();
    }
    else
    {
        TLS(pDataClip) = pdo;
    }

    RRETURN(hr);
}
예제 #5
0
파일: txtsrv.c 프로젝트: Strongc/reactos
DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface, LPCWSTR pszText)
{
   ITextServicesImpl *This = impl_from_ITextServices(iface);
   ME_Cursor cursor;

   ME_SetCursorToStart(This->editor, &cursor);
   ME_InternalDeleteText(This->editor, &cursor,
                         ME_GetTextLength(This->editor), FALSE);
   ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
                           This->editor->pBuffer->pDefaultStyle);
   ME_SetSelection(This->editor, 0, 0);
   This->editor->nModifyStep = 0;
   OleFlushClipboard();
   ME_EmptyUndoStack(This->editor);
   ME_UpdateRepaint(This->editor, FALSE);

   return S_OK;
}
예제 #6
0
Application::~Application()
{
    delete mainWindow;
    if (resources)
        resources->flush();
    delete dotaLibrary;
    delete imageLibrary;
    delete resources;
    delete cache;
    delete warLoader;

    cfg.write();
    instance = NULL;
    ScriptType::freeTypes();
    MPQCleanup();
    OleFlushClipboard();
    OleUninitialize();
}
예제 #7
0
bool wxClipboard::Flush()
{
#if wxUSE_OLE_CLIPBOARD
    HRESULT hr = OleFlushClipboard();
    if ( FAILED(hr) )
    {
        wxLogApiError(wxT("OleFlushClipboard"), hr);

        return false;
    }
    else
    {
        m_clearOnExit = false;

        return true;
    }
#else // !wxUSE_OLE_CLIPBOARD
    return false;
#endif // wxUSE_OLE_CLIPBOARD/!wxUSE_OLE_CLIPBOARD
}
예제 #8
0
bool QWindowsClipboard::clipboardViewerWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result)
{
    enum { wMClipboardUpdate = 0x031D };

    *result = 0;
    if (QWindowsContext::verbose)
        qCDebug(lcQpaMime) << __FUNCTION__ << hwnd << message << QWindowsGuiEventDispatcher::windowsMessageName(message);

    switch (message) {
    case WM_CHANGECBCHAIN: {
        const HWND toBeRemoved = (HWND)wParam;
        if (toBeRemoved == m_nextClipboardViewer) {
            m_nextClipboardViewer = (HWND)lParam;
        } else {
            propagateClipboardMessage(message, wParam, lParam);
        }
    }
        return true;
    case wMClipboardUpdate:  // Clipboard Format listener (Vista onwards)
    case WM_DRAWCLIPBOARD: { // Clipboard Viewer Chain handling (up to XP)
        const bool owned = ownsClipboard();
        qCDebug(lcQpaMime) << "Clipboard changed owned " << owned;
        emitChanged(QClipboard::Clipboard);
        // clean up the clipboard object if we no longer own the clipboard
        if (!owned && m_data)
            releaseIData();
        if (!m_formatListenerRegistered)
            propagateClipboardMessage(message, wParam, lParam);
    }
        return true;
    case WM_DESTROY:
        // Recommended shutdown
        if (ownsClipboard()) {
            qCDebug(lcQpaMime) << "Clipboard owner on shutdown, releasing.";
            OleFlushClipboard();
            releaseIData();
        }
        return true;
    } // switch (message)
    return false;
}
예제 #9
0
bool QWindowsClipboard::clipboardViewerWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result)
{
    *result = 0;
    if (QWindowsContext::verboseOLE)
            qDebug("%s HWND=%p 0x%x %s", __FUNCTION__, hwnd, message,
                   QWindowsGuiEventDispatcher::windowsMessageName(message));

    switch (message) {
    case WM_CHANGECBCHAIN: {
        const HWND toBeRemoved = (HWND)wParam;
        if (toBeRemoved == m_nextClipboardViewer) {
            m_nextClipboardViewer = (HWND)lParam;
        } else {
            propagateClipboardMessage(message, wParam, lParam);
        }
    }
        return true;
    case WM_DRAWCLIPBOARD: {
        const bool owned = ownsClipboard();
        if (QWindowsContext::verboseOLE)
            qDebug("Clipboard changed owned %d", owned);
        emitChanged(QClipboard::Clipboard);
        // clean up the clipboard object if we no longer own the clipboard
        if (!owned && m_data)
            releaseIData();
        propagateClipboardMessage(message, wParam, lParam);
    }
        return true;
    case WM_DESTROY:
        // Recommended shutdown
        if (ownsClipboard()) {
            if (QWindowsContext::verboseOLE)
                qDebug("Clipboard owner on shutdown, releasing.");
            OleFlushClipboard();
            releaseIData();
        }
        return true;
    } // switch (message)
    return false;
}
예제 #10
0
bool QClipboard::event(QEvent *e)
{
    if (e->type() != QEvent::Clipboard)
        return QObject::event(e);

    QClipboardData *d = clipboardData();

    MSG *m = (MSG *)((QClipboardEvent*)e)->data();
    if (!m) {
        // this is sent to render all formats at app shut down
        if (ownsClipboard()) {
            OleFlushClipboard();
            d->releaseIData();
        }
        return true;
    }

    bool propagate = false;

    if (m->message == WM_CHANGECBCHAIN) {
        if ((HWND)m->wParam == d->nextClipboardViewer)
            d->nextClipboardViewer = (HWND)m->lParam;
        else
            propagate = true;
    } else if (m->message == WM_DRAWCLIPBOARD) {
        emitChanged(QClipboard::Clipboard);
        if (!ownsClipboard() && d->iData)
            // clean up the clipboard object if we no longer own the clipboard
            d->releaseIData();
        propagate = true;
    }

    if (propagate && d->nextClipboardViewer) {
        SendMessage(d->nextClipboardViewer, m->message, m->wParam, m->lParam);
    }

    return true;
}
예제 #11
0
HRESULT CSimpleDataObjectImpl::SetClipboard()
{
	RETURNIFFAILED(OleSetClipboard(this));
	RETURNIFFAILED(OleFlushClipboard());
	return S_OK;
}
예제 #12
0
파일: ole2_16.c 프로젝트: howard5888/wineT
HRESULT WINAPI OleFlushClipboard16(void)
{
  return OleFlushClipboard();
}
예제 #13
0
CPlugin::EDoMenu CPlugin::DoMenu(LPSHELLFOLDER pCurFolder, LPCITEMIDLIST* pPiids, LPCWSTR pFiles[], unsigned nFiles, unsigned nFolders, LPCWSTR szCommand/*=NULL*/, EAutoItem enAutoItem/*=AI_NONE*/)
{
  assert(nFolders+nFiles);
  auto_sz strMnuTitle;
  if (nFolders+nFiles==1)
  {
    strMnuTitle=pFiles[0];
    if (nFolders)
    {
      strMnuTitle.RemoveTrailing(L'\\');
      strMnuTitle+=L"\\";
    }
  }
  else
  {
    auto_sz strFiles;
    strFiles.Realloc(20);
    wsprintf(strFiles, L"%u %s", nFiles, GetMsg(LNG_FILES));

    auto_sz strFolders;
    strFolders.Realloc(20);
    wsprintf(strFolders, L"%u %s", nFolders, GetMsg(LNG_FOLDERS));

    if (nFiles)
    {
      strMnuTitle+=strFiles;
    }
    if (nFolders)
    {
      if (nFiles) strMnuTitle+=L", ";
      strMnuTitle+=strFolders;
    }
  }
  IContextMenuPtr pCMenu1;

  if (FAILED(pCurFolder->GetUIObjectOf(NULL_HWND, nFolders+nFiles, pPiids, IID_IContextMenu, 0, reinterpret_cast<void**>(&pCMenu1))))
  {
    return DOMNU_ERR_SHOW;
  }
  LPCONTEXTMENU pPreferredMenu=pCMenu1;

  IContextMenu2Ptr pCMenu2(pCMenu1);
  if (pCMenu2)
  {
    pPreferredMenu=pCMenu2;
  }

  IContextMenu3Ptr pCMenu3(pCMenu1);
  if (pCMenu3)
  {
    pPreferredMenu=pCMenu3;
  }

  // Решение дурацкой проблемы с падением в 2000 на paste
  if (m_bWin2K) pCMenu1.Detach();

  CHMenu oHMenu;
  if (!oHMenu) return DOMNU_ERR_SHOW;
  enum {EMENU_CMF_EXTENDEDVERBS=0x00000100}; // rarely used verbs
  if (!pPreferredMenu || FAILED(pPreferredMenu->QueryContextMenu(oHMenu, 0, MENUID_CMDOFFSET, 0x7FFF, CMF_CANRENAME|(GetKeyState(VK_SHIFT)&0xF000?EMENU_CMF_EXTENDEDVERBS:0))))
  {
    return DOMNU_ERR_SHOW;
  }

  int nCmd=0;
  if (szCommand)
  {
    for (int i=0; i<oHMenu.GetMenuItemCount(); i++)
    {
      MENUITEMINFO mii={0};
      mii.cbSize=sizeof(mii);
      mii.fMask=MIIM_ID|MIIM_STATE;
      if (!GetMenuItemInfo(oHMenu, i, TRUE, &mii)) return DOMNU_ERR_INVOKE;
      if (mii.fState&MFS_DISABLED) continue;
      auto_sz strAutoItem;
      switch (enAutoItem)
      {
      case AI_VERB:
        if (!GetAdditionalString(pPreferredMenu, mii.wID-MENUID_CMDOFFSET, AS_VERB, &strAutoItem))
        {
          continue;
        }
        break;
      case AI_ITEM:
        {
          int nLen=GetMenuString(oHMenu, i, NULL, 0, MF_BYPOSITION);
          if (!nLen) continue;
          ++nLen;
          strAutoItem.Realloc(nLen);
          if (!GetMenuString(oHMenu, i, strAutoItem, nLen, MF_BYPOSITION))
          {
            continue;
          }
        }
        break;
      default:
        assert(0);
        break;
      }
      if (strAutoItem.CompareExcluding(szCommand, L'&'))
      {
        nCmd=mii.wID;
        break;
      }
    }
    if (nCmd<MENUID_CMDOFFSET) return DOMNU_ERR_INVOKE;
  }
  else
  {
    int nSelItem=0;
    CFarMenu oTypeMenu(g_szTopicChooseMenuType, &GuiTextMenuGuid);
    oTypeMenu.AddItem(GetMsg(LNG_MNU_GUI));
    oTypeMenu.AddItem(GetMsg(LNG_MNU_TEXT));
    while (1)
    {
      bool bGUI;
      if(2!=m_UseGUI)
      {
        bGUI=(0!=m_UseGUI);
      }
      else
      {
        nSelItem=OleThread::ShowMenu(oTypeMenu,strMnuTitle, nSelItem, m_GuiPos==0);
        switch (nSelItem)
        {
        case CFarMenu::SHOW_CANCEL:
          return DOMENU_CANCELLED;
        case CFarMenu::SHOW_BACK:
          return DOMENU_BACK;
        case 0:
          bGUI=true;
          break;
        case 1:
          bGUI=false;
          break;
        }
      }
      if (bGUI)
      {
        if (!ShowGuiMenu(oHMenu, pCMenu1, pCMenu2, pCMenu3, &nCmd))
        {
          return DOMNU_ERR_SHOW;
        }
      }
      else
      {
        if (!ShowTextMenu(oHMenu, pPreferredMenu, pCMenu2, pCMenu3, &nCmd, strMnuTitle, pCurFolder, pPiids, nFolders+nFiles))
        {
          return DOMNU_ERR_SHOW;
        }
      }
      if (nCmd==MENUID_CANCELLED)
      {
        return DOMENU_CANCELLED;
      }
      if (nCmd!=MENUID_BACK)
      {
        break;
      }
    }
  }

  if (nCmd>=MENUID_CMDOFFSET)
  {
    int nId=nCmd-MENUID_CMDOFFSET;
    CHAR szVerb[100];
    if (FAILED(pPreferredMenu->GetCommandString(nId, GCS_VERBA, NULL, szVerb, ARRAYSIZE(szVerb))))
    {
      szVerb[0]='\0';
    }
    if (lstrcmpA(szVerb, "rename")==0)
    {
      MacroSendMacroText mcmd = {sizeof(MacroSendMacroText), 0, {0}, L"Keys'F6'"};
      MacroControl(NULL, MCTL_SENDSTRING, MSSC_POST, &mcmd);
      return DOMENU_CANCELLED;
    }
    if (m_DelUsingFar && lstrcmpA(szVerb, "delete")==0)
    {
      MacroSendMacroText mcmd = {sizeof(MacroSendMacroText), 0, {0}, L"Keys'F8'"};
      if (GetKeyState(VK_LSHIFT)&0x8000 || GetKeyState(VK_RSHIFT)&0x8000)
      {
        mcmd.SequenceText=L"Keys'ShiftDel'";
      }
      else if (GetKeyState(VK_LMENU)&0x8000 || GetKeyState(VK_RMENU)&0x8000)
      {
        mcmd.SequenceText=L"Keys'AltDel'";
      }
      MacroControl(NULL, MCTL_SENDSTRING, MSSC_POST, &mcmd);
      return DOMENU_CANCELLED;
    }
    else
    {
      CMINVOKECOMMANDINFO cmici;
      cmici.cbSize       = sizeof(cmici);
      cmici.fMask        = 0;
      cmici.hwnd         = NULL_HWND;
      cmici.lpVerb       = (LPCSTR)MAKEINTRESOURCE(nId);
      cmici.lpParameters = NULL;
      cmici.lpDirectory  = NULL;
      cmici.nShow        = SW_SHOWNORMAL;
      cmici.dwHotKey     = 0;
      cmici.hIcon        = NULL;
      if (FAILED(pPreferredMenu->InvokeCommand(&cmici)))
      {
        // return DOMNU_ERR_INVOKE;
        // Иногда здесь возвращается ошибка даже в
        // нормальных ситуациях.
        // Например, если занести это в реестр
//[HKEY_CLASSES_ROOT\AllFileSystemObjects\shellex\ContextMenuHandlers\Copy To]
//@="{C2FBB630-2971-11D1-A18C-00C04FD75D13}"
//[HKEY_CLASSES_ROOT\AllFileSystemObjects\shellex\ContextMenuHandlers\Move To]
//@="{C2FBB631-2971-11D1-A18C-00C04FD75D13}"
        // , а потом вызвать один из добавившихся пунктов
        // и нажать Esc.
      }

      // Эта функция решает проблему, когда
      // после помещения файла в буфер и выхода из FARа
      // буфер портился.
      // проблема точно проявлялась на Build950 и XP
      if (FAILED(OleFlushClipboard()))
      {
        // иногда бывает E_FAIL
        //assert(0);
      }
    }
  }
  return DOMNU_OK;
}
예제 #14
0
LRESULT C_Edit::OnDrop(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	try {

		IDataObject* pdto = *reinterpret_cast<IDataObject**>(lParam);

		if (pdto) {

			HRESULT hres = E_FAIL;
			FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1,	TYMED_HGLOBAL};
			STGMEDIUM medium;
			int files = 0;

			if (pdto && SUCCEEDED (pdto->GetData(&fmte, &medium))) {

				//char szFileDropped [MAX_PATH];

				files = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0);
			}

			OleSetClipboard(pdto);
			OleFlushClipboard();

			C_ClipboardPtr clipboard;

			clipboard.Create();
			
			if (clipboard) {

				if (0 == files) {

					clipboard->Load(CF_TEXT);

					short s = -1;
					clipboard->get_Type(&s);

					switch (s) {
					case CF_OEMTEXT:
					case CF_TEXT:

						BSTR bs = NULL;
						clipboard->get_Text(&bs);
						
						String s(bs);
						
						String::FreeBSTR(&bs);

						int len = s.GetLength();

						SetFocus();

						TCHAR t[1024];
						SendMessage(WM_GETTEXT, 1023, reinterpret_cast<LPARAM>(t));
						String old(t);

						POINT p = { 
							reinterpret_cast<POINT*>(wParam)->x, 
							reinterpret_cast<POINT*>(wParam)->y 
						};
						ScreenToClient(&p);

						int selpos = LOWORD(SendMessage(EM_CHARFROMPOS, 0, MAKELPARAM(p.x, p.y)));

						if (selpos >= 0 && selpos < old.GetLength()) {
							s = old.Left(selpos) + s + old.Right(old.GetLength() - selpos);
						}

						if (selpos < m_dwSelEnd) {

							m_dwSelStart += len;
							m_dwSelEnd += len;
						}

						SendMessage(WM_SETTEXT, 0, reinterpret_cast<LPARAM>(s.toLPCTSTR()));
						SendMessage(EM_SETSEL, selpos, selpos + len);
					}
				}
			}
		}

		OnDragLeave(uMsg, wParam, lParam, bHandled);
	}
	catch (C_STLNonStackException const &exception) {
		exception.Log(_T("Exception in C_Edit::OnCanDrop"));
	}

	return S_OK;
}
예제 #15
0
/*----------------------------------------------------------------------------------------------
	WinMain for an exe server.
----------------------------------------------------------------------------------------------*/
int ModuleEntry::WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR pszCmdLine,
	int nShowCmd)
{
	AssertPsz(pszCmdLine);
	Assert(!hinstPrev);

	// Initialize COM
	HRESULT hr = OleInitialize(NULL);
	s_qdobjClipboard.Clear();

	if (FAILED(hr))
	{
		WarnHr(hr);
		// REVIEW DarrellZ: Should we alert the user?
		return 0;
	}

	s_hmod = hinst;
	s_tid = ::GetCurrentThreadId();

	int nRet = 0;
	bool fRun = true;

	// Look through the command line to see if the EXE server should be registered or
	// unregistered. If it should, quit the EXE server after performing the appropriate action.
	if (*pszCmdLine == '-' || *pszCmdLine == '/')
	{
		if (_stricmp(pszCmdLine + 1, "UnregServer") == 0)
		{
			hr = ModuleEntry::ModuleUnregisterServer();
			fRun = false;
		}
		else if (_stricmp(pszCmdLine + 1, "RegServer") == 0)
		{
			hr = ModuleEntry::ModuleRegisterServer();
			fRun = false;
		}
		else if (_stricmp(pszCmdLine + 1, "RegRedirect") == 0)
		{
			// Used only during creation of installer:
			OverrideRegistryKeys();
			hr = ModuleEntry::ModuleRegisterServer();
			return true;
		}
	}

	if (fRun)
	{
		hr = ModuleEntry::ModuleProcessAttach();
		WarnHr(hr);

		// NealA: I am working on this for UNICODE support
		// if not removed by 12-2002 please remove these comments
		// StrApp strCmdLine = pszCmdLine;
		nRet = Run(hinst, pszCmdLine, nShowCmd);

		hr = ModuleEntry::ModuleProcessDetach();
		WarnHr(hr);
		// Check for memory leaks in the main program.
		_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
	}
	else
	{
		WarnHr(hr);
	}

	// Uninitialize COM, first shutting down the clipboard.
	if (s_qdobjClipboard.Ptr())
	{
		hr = OleIsCurrentClipboard(s_qdobjClipboard.Ptr());
		WarnHr(hr);
		if (hr == S_OK)
		{
			WarnHr(OleFlushClipboard());
		}
		s_qdobjClipboard.Clear();
	}
	OleUninitialize();

	return nRet;
}
예제 #16
0
void CTextObject::ReleaseObjectText()
{
	FireDataStop();
	if (OleIsCurrentClipboard(this) == S_OK)
		OleFlushClipboard();
}