当前位置: 首页>>代码示例>>C++>>正文


C++ StrAnsi::Format方法代码示例

本文整理汇总了C++中StrAnsi::Format方法的典型用法代码示例。如果您正苦于以下问题:C++ StrAnsi::Format方法的具体用法?C++ StrAnsi::Format怎么用?C++ StrAnsi::Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StrAnsi的用法示例。


在下文中一共展示了StrAnsi::Format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AddAction

/*----------------------------------------------------------------------------------------------
	${IActionHandler#AddAction}
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::AddAction(IUndoAction * puact)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(puact);

	if (m_fUndoOrRedoInProgress)
		return S_OK;

	if(m_fCreateMarkIfNeeded && m_viMarks.Size() == 0)
	{
		// m_fCreateMarkIfNeeded probably didn't get reset (TE-4856)
		Assert(m_nDepth <= 0 || m_fStartedNext);

		int hmark;
		CheckHr(Mark(&hmark));
		Assert(hmark == 1); // Should only have 1 mark!
	}
	ContinueUndoTask();
	AddActionAux(puact);
	EndUndoTask();

#ifdef DEBUG_ACTION_HANDLER
	StrAnsi sta;
	sta.Format("AddAction:");
	sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
		m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
	::OutputDebugStringA(sta.Chars());
#endif//DEBUG_ACTION_HANDLER

	END_COM_METHOD(g_factActh, IID_IActionHandler);
}
开发者ID:agran147,项目名称:FieldWorks,代码行数:34,代码来源:ActionHandler.cpp

示例2: EndUndoTask

/*----------------------------------------------------------------------------------------------
	${IActionHandler#EndUndoTask}
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::EndUndoTask()
{
	BEGIN_COM_METHOD;

	if (m_fUndoOrRedoInProgress)
		return S_OK;

	if (m_nDepth <= 0)
	{
		return E_UNEXPECTED;
	}
	else
	{
		--m_nDepth;
		if (m_nDepth == 0)
		{
			// cleans no-op undo tasks
			EndOuterUndoTask();
		}
	}

#ifdef DEBUG_ACTION_HANDLER
	StrAnsi sta;
	sta.Format("EndUndoTask:");
	sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
		m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
	::OutputDebugStringA(sta.Chars());
#endif//DEBUG_ACTION_HANDLER

	END_COM_METHOD(g_factActh, IID_IActionHandler);
}
开发者ID:agran147,项目名称:FieldWorks,代码行数:34,代码来源:ActionHandler.cpp

示例3: BreakUndoTask

/*----------------------------------------------------------------------------------------------
	${IActionHandler#BreakUndoTask}
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::BreakUndoTask(BSTR bstrUndo, BSTR bstrRedo)
{
	BEGIN_COM_METHOD;
	ChkComBstrArg(bstrUndo);
	ChkComBstrArg(bstrRedo);

	if (m_fUndoOrRedoInProgress)
		return S_OK;

	int nSaveDepth = m_nDepth;

	EndOuterUndoTask();

	BeginUndoTask(bstrUndo, bstrRedo);

	m_nDepth = nSaveDepth;

#ifdef DEBUG_ACTION_HANDLER
	StrAnsi sta;
	sta.Format("BreakUndoTask:");
	sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
		m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
	::OutputDebugStringA(sta.Chars());
#endif//DEBUG_ACTION_HANDLER

	END_COM_METHOD(g_factActh, IID_IActionHandler);
}
开发者ID:agran147,项目名称:FieldWorks,代码行数:30,代码来源:ActionHandler.cpp

示例4: SetKeyboard_Windows

/*----------------------------------------------------------------------------------------------
	Set the keyboard the Windows API way
----------------------------------------------------------------------------------------------*/
void SetKeyboard_Windows(int lcid)
{
#ifdef Tracing_KeybdSelection
	StrAnsi sta;
	sta.Format("LgTextServices::SetKeyboard(%d) [not Keyman]%n", lcid);
	::OutputDebugStringA(sta.Chars());
#endif
	int nLangId = LANGIDFROMLCID(lcid);
	HKL hkl = (HKL)nLangId;
	if (hkl == 0)
		hkl = (HKL)::GetSystemDefaultLangID();

	// If we're not activating a Keyman keyboard, activate the appropriate OS IM.
	// Microsoft says we should only do this if we were not able to do it using
	// ActivateLanguageProfile (private communication to JohnT).
#ifdef Tracing_KeybdSelection
	sta.Format("LgTextServices::SetKeyboard(%d) - "
		"hkl = %x, ::GetKeyboardLayout() = %x%n",
		lcid, hkl, ::GetKeyboardLayout(0));
	::OutputDebugStringA(sta.Chars());
#endif
	if (hkl != ::GetKeyboardLayout(0))
	{
		// We need to work out whether we're using at least W2000, because
		// KLF_SETFORPROCESS is not supported before that.
		UINT flags = 0;
		if (IsWin2kOrHigher())
		{
			//Windows 2000 or better, we can use KLF_SETFORPROCESS.
			flags = KLF_SETFORPROCESS;
		}
#ifdef Tracing_KeybdSelection
		StrAnsi sta;
		sta.Format("LgTextServices::SetKeyboard(%d) - "
			"::ActivateKeyboardLayout(%x, %x) [nLangId = %d]\n",
			lcid, hkl, flags, nLangId);
		::OutputDebugStringA(sta.Chars());
#endif
		::ActivateKeyboardLayout(hkl, flags);
		Assert(sizeof(int) >= sizeof(hkl));
	}
}
开发者ID:,项目名称:,代码行数:45,代码来源:

示例5: TransFuncDump

/*----------------------------------------------------------------------------------------------
	This function can be installed to translate windows exceptions into C++ internal error
	exceptions. Only the main program should do this. To install, just call
	_set_se_translator(TransFuncDump);.

	This is of dubious value because if the error occurs inside a COM component, the Throwable
	exception will not be recognized, and exception handling will just catch "..." and generate
	a new stack dump. However, installing it at least achieves better stack dumps for errors
	in code linked into the main program.

	We could install at the start of every COM interface method, and restore upon return.
	However this would be computationally expensive. Consider doing this in a particular method
	if you are trying to track down a problem in that method.

	We could have each module install this function on being loaded, and check whether the
	error occurs in its own code, and if not call the previous error handler. But this
	only works reliably if modules are never unloaded, or only in reverse order of loading,
	which I don't see how to ensure.

	We could also get really fancy, with some sort of central manager which knows which error
	translator to use for each module. This has not seemed worthwhile to me so far.
----------------------------------------------------------------------------------------------*/
void TransFuncDump( unsigned int u, EXCEPTION_POINTERS * pExp)
{
#ifdef WIN32
	HANDLE hThread;
	DWORD dwCode = pExp->ExceptionRecord->ExceptionCode;
	StrUni stuException = ConvertException(dwCode);
	DuplicateHandle( GetCurrentProcess(), GetCurrentThread(),
		GetCurrentProcess(), &hThread, 0, false, DUPLICATE_SAME_ACCESS );
	StrAnsi staMsg;
	staMsg.Format("Stack Dump for exception: %S (%d)", stuException.Chars(), dwCode);
	StackDumper::ShowStack( hThread, *(pExp->ContextRecord), const_cast<char *>(staMsg.Chars()) );
	CloseHandle( hThread );
	StrUni stuMsg(staMsg.Chars());
	throw ThrowableSd(E_UNEXPECTED, stuMsg.Chars(), 0, StackDumper::GetDump());
#endif
}
开发者ID:FieldDB,项目名称:FieldWorks,代码行数:38,代码来源:StackDumper.cpp

示例6: Commit

/*----------------------------------------------------------------------------------------------
	${IActionHandler#Commit}
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::Commit()
{
	BEGIN_COM_METHOD;

	HRESULT hr = E_FAIL;
	HRESULT hrFinal = S_OK;
	if (m_vquact.Size())
	{
		// JohnT 10/22/01: this can happen, typically if the only thing in the sequence is a
		// position mark. We could try to check for that but it doesn't seem worth it. Nothing
		// actually depends on having at least one sequence start here.
		//Assert(m_viSeqStart.Size() > 0);

		// Commit all actions.
		for (int i = 0; i <= m_iuactCurr; i++)
		{
			// If for some reason, we cannot commit an action that is part of a sequence, it's
			// just too bad.  We can't undo a commited action so we might as well just amble on
			// and hope for the best.
			IgnoreHr(hr = m_vquact[i]->Commit());
			if (FAILED(hr))
			{
				hrFinal = hr;
			}
		}

		EmptyStack();
	}

#ifdef DEBUG_ACTION_HANDLER
	StrAnsi sta;
	sta.Format("Commit:");
	sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
		m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
	::OutputDebugStringA(sta.Chars());
#endif//DEBUG_ACTION_HANDLER

	return hrFinal;

	END_COM_METHOD(g_factActh, IID_IActionHandler);
}
开发者ID:agran147,项目名称:FieldWorks,代码行数:44,代码来源:ActionHandler.cpp

示例7: Mark

/*----------------------------------------------------------------------------------------------
	Inserts a mark and returns a handle that can be used later to discard all Undo items
	back to the mark. Handle will never be zero.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::Mark(int * phMark)
{
	BEGIN_COM_METHOD;
	ChkComOutPtr(phMark);

	// It's only valid to place a mark while no action sequence is in progress.
	if (m_nDepth > 0 && !m_fStartedNext)
		ThrowHr(WarnHr(E_UNEXPECTED));

	m_fCanContinueTask = false; // Can't merge another action into the current task.

	// For now, we are only supporting one mark at a time.
	Assert(m_viMarks.Size() == 0);

	m_viMarks.Push(m_iuactCurr + 1); // index of next action to be added
	*phMark = m_viMarks.Size();

	//StrAnsi sta;
	//sta.Format("mark location: %d\n", m_iuactCurr + 1);
	//::OutputDebugStringA(sta.Chars());

	//::OutputDebugStringA("MARK\n");
	//StrAnsi sta;
	//sta.Format("depth = %d; m_fStartedNext = %d; action %d of %d; seq %d of %d; marks %d%n",
	//	m_nDepth, m_fStartedNext, m_iuactCurr, m_vquact.Size(), m_iCurrSeq, m_viSeqStart.Size(), m_viMarks.Size());
	//::OutputDebugStringA(sta.Chars());

#ifdef DEBUG_ACTION_HANDLER
	StrAnsi sta;
	sta.Format("Mark:%d", *phMark);
	sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
		m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
	::OutputDebugStringA(sta.Chars());
#endif//DEBUG_ACTION_HANDLER

	END_COM_METHOD(g_factActh, IID_IActionHandler);
}
开发者ID:agran147,项目名称:FieldWorks,代码行数:41,代码来源:ActionHandler.cpp

示例8: Redo

/*----------------------------------------------------------------------------------------------
	${IActionHandler#Redo}
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::Redo(UndoResult * pures)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pures);

	*pures = kuresSuccess;
	// Do not allow actions to be redone if they have not been undone.
	Assert(m_viSeqStart.Size() > 0);
	Assert(m_iCurrSeq <= m_viSeqStart.Size() - 1);

	m_fCanContinueTask = false; // Can't 'continue' the previous task from before the Undo.
	m_fUndoOrRedoInProgress = true;
	HRESULT hrFinal = S_OK;
	int iSeqToRedo = m_iCurrSeq + 1;

	try // to ensure in progress gets cleared.
	{
		int handle;
		// Start a 'transaction' if possible to group together all the stuff we're going to Undo.
		if (m_qundg)
		{
			m_qundg->BeginGroup(&handle);
		}

		// Determine the last action to be redone; The last action to redo is the action
		// before the next redo sequence. Or the last existing action if there is not a
		// redo sequence after the sequence we are about to redo.
		int iLastRedoAct = m_vquact.Size() - 1;
		if (iSeqToRedo <= m_viSeqStart.Size() - 2)
			iLastRedoAct = m_viSeqStart[iSeqToRedo + 1] - 1;

		// Loop through all of the actions that are about to be redone and see if any of them
		// require a refresh.
		for (int i = m_viSeqStart[iSeqToRedo]; i <= iLastRedoAct; i++)
		{
			CheckHr(m_vquact[i]->put_SuppressNotification(true));
		}

		// Redo all the actions in the next action sequence that change data.
		hrFinal = CallRedo(pures, true, iSeqToRedo, iLastRedoAct);

		// Now do all the PropChangeds
		for (int i = m_viSeqStart[iSeqToRedo]; i <= iLastRedoAct; i++)
		{
			CheckHr(m_vquact[i]->put_SuppressNotification(false));
		}

		// REVIEW (TimS/EberhardB): What do we do if the call to CallRedo above failed somewhere?
		// Should we do this at all? Or just until the failed action? Or everything?
		UndoResult uresTmp = kuresSuccess;
		// Redo all the actions in the next action sequence that don't change data.
		HRESULT hr;
		IgnoreHr(hr = CallRedo(&uresTmp, false, iSeqToRedo, iLastRedoAct));
		if (FAILED(hr))
		{
			hrFinal = hr;
			*pures = uresTmp;
		}
		else if (uresTmp == kuresFailed)
		{
			*pures = uresTmp;
		}

		// dlh testing
		if (*pures == kuresError || * pures == kuresFailed)
		{
			if (m_qundg)
				m_qundg->CancelGroup(handle);
			EmptyStack();
		}
		else // normal success case
		{
			// Set the current sequence and action.
			m_iCurrSeq++;
			m_iuactCurr = m_vquact.Size() - 1;
			if (m_iCurrSeq < m_viSeqStart.Size() - 1)
			{
				m_iuactCurr = m_viSeqStart[m_iCurrSeq + 1] - 1;
			}
			if (m_qundg)
				m_qundg->EndGroup(handle);
		}


#ifdef DEBUG_ACTION_HANDLER
		StrAnsi sta;
		sta.Format("Redo:");
		sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
			m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
		::OutputDebugStringA(sta.Chars());
#endif //DEBUG_ACTION_HANDLER
	}
	catch(...)
	{
		m_fUndoOrRedoInProgress = false;
		throw;
	}
//.........这里部分代码省略.........
开发者ID:agran147,项目名称:FieldWorks,代码行数:101,代码来源:ActionHandler.cpp

示例9: Undo

/*----------------------------------------------------------------------------------------------
	${IActionHandler#Undo}
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::Undo(UndoResult * pures)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pures);

	*pures = kuresSuccess;

	Assert(m_iCurrSeq >= 0);
	Assert(m_vquact.Size() > 0);

	HRESULT hr = E_FAIL;
	HRESULT hrFinal = S_OK;

	m_fCanContinueTask = false; // Can't 'continue' the previous task from before the Undo.
	m_fUndoOrRedoInProgress = true;

	try // to ensure in progress gets cleared.
	{
		int handle;
		// Start a 'transaction' if possible to group together all the stuff we're going to Undo.
		if (m_qundg)
		{
			m_qundg->BeginGroup(&handle);
		}

		// Loop through all of the actions that are about to be undone and see if any of them
		// require a refresh.
		Vector<long> vhvoCreatedObjects;
		for (int i = m_iuactCurr; (m_iCurrSeq >= 0) && (i >= m_viSeqStart[m_iCurrSeq]); i--)
		{
			CheckHr(m_vquact[i]->put_SuppressNotification(true));
		}

		// Undo all actions from the current action back to the first action of the current action
		// sequence.
		bool fRedoable = true;
		IgnoreHr(hrFinal = CallUndo(pures, fRedoable, true));

		// Now do all the PropChangeds
		for (int i = m_iuactCurr; (m_iCurrSeq >= 0) && (i >= m_viSeqStart[m_iCurrSeq]); i--)
		{
			CheckHr(m_vquact[i]->put_SuppressNotification(false));
		}

		// REVIEW (TimS/EberhardB): What do we do if the call to CallUndo above failed somewhere?
		// Should we do this at all? Or just until the failed action? Or everything?
		UndoResult uresTmp;
		IgnoreHr(hr = CallUndo(&uresTmp, fRedoable, false));
		if (FAILED(hr))
		{
			hrFinal = hr;
			*pures = uresTmp;
		}
		else if (uresTmp == kuresFailed)
		{
			*pures = uresTmp;
		}

		// dlh testing
		if (*pures == kuresError || * pures == kuresFailed)
		{
			if (m_qundg)
				m_qundg->CancelGroup(handle);
			EmptyStack();
		}
		else // normal success case
		{
			// Set the current action and start of the current action sequence.
			if (m_iCurrSeq >= 0)
			{
				m_iuactCurr = m_viSeqStart[m_iCurrSeq] - 1;
				m_iCurrSeq = m_iCurrSeq - 1;
			}
			if (m_qundg)
				m_qundg->EndGroup(handle);
		}

		// Delete any marks that now point after current undo action
		CleanUpMarks();

		if (!fRedoable)
			CleanUpRedoActions(true);

#ifdef DEBUG_ACTION_HANDLER
		StrAnsi sta;
		sta.Format("Undo:");
		sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
			m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
		::OutputDebugStringA(sta.Chars());
#endif//DEBUG_ACTION_HANDLER
	}
	catch(...)
	{
		CleanUpMarks();
		m_fUndoOrRedoInProgress = false;
		throw;
	}
//.........这里部分代码省略.........
开发者ID:agran147,项目名称:FieldWorks,代码行数:101,代码来源:ActionHandler.cpp

示例10: DiscardToMark

/*----------------------------------------------------------------------------------------------
	Discard all Undo items back to the specified mark (or the most recent mark, if any,
	if handle is zero).
----------------------------------------------------------------------------------------------*/
STDMETHODIMP ActionHandler::DiscardToMark(int hMark)
{
	BEGIN_COM_METHOD;
	// It's only valid to discard while no action sequence is in progress.
	if (m_nDepth > 0)
	{
		ThrowHr(WarnHr(E_UNEXPECTED));
	}
	m_fCanContinueTask = false; // Can't merge another action into the current task.

	// The handle hMark is 1 + the position of the mark in the mark stack.
	int iMarkGoal = (hMark == 0) ? m_viMarks.Size() - 1 : hMark - 1;

	if (iMarkGoal >= m_viMarks.Size() || iMarkGoal < 0)
		return E_INVALIDARG;

	//::OutputDebugStringA("Entering DiscardToMark\n");
	//StrAnsi sta;
	//sta.Format("depth = %d; m_fStartedNext = %d; action %d of %d; seq %d of %d; marks %d%n",
	//	m_nDepth, m_fStartedNext, m_iuactCurr, m_vquact.Size(), m_iCurrSeq, m_viSeqStart.Size(), m_viMarks.Size());
	//::OutputDebugStringA(sta.Chars());

	int iuactMark = m_viMarks[iMarkGoal];
	int iuact;
	for (iuact = m_vquact.Size() - 1; iuact >= iuactMark; iuact--)
	{
		m_vquact.Delete(iuact);
	}
	m_iuactCurr = min(m_iuactCurr, m_vquact.Size() - 1);

	for (iuact = m_viSeqStart.Size() - 1; iuact >= 0; iuact--)
	{
		if (m_viSeqStart[iuact] < m_vquact.Size())
			break;
		m_viSeqStart.Delete(iuact);
		m_vstuUndo.Delete(iuact);
		m_vstuRedo.Delete(iuact);
	}
	m_iCurrSeq = min(m_iCurrSeq, m_viSeqStart.Size() - 1);

	// Delete the mark(s).
	for (int iMarkTmp = m_viMarks.Size() - 1; iMarkTmp >= iMarkGoal; iMarkTmp--)
	{
		m_viMarks.Delete(iMarkTmp);
	}

	//::OutputDebugStringA("After DiscardToMark\n");
	//sta.Format("depth = %d; m_fStartedNext = %d; action %d of %d; seq %d of %d; marks %d%n",
	//	m_nDepth, m_fStartedNext, m_iuactCurr, m_vquact.Size(), m_iCurrSeq, m_viSeqStart.Size(), m_viMarks.Size());
	//::OutputDebugStringA(sta.Chars());

	// For now, we are only supporting one mark at a time:
	Assert(m_viMarks.Size() == 0);

	// If the depth is greater than zero, we're in the middle of recording a task, so
	// get back in the state where we can close it out.
	if (m_nDepth > 0)
	{
		Assert(m_viSeqStart.Size() == m_vstuUndo.Size());
		Assert(m_viSeqStart.Size() == m_vstuRedo.Size());

		m_fStartedNext = true;

		//::OutputDebugStringA("Leaving DiscardToMark\n");
		//sta.Format("depth = %d; m_fStartedNext = %d; action %d of %d; seq %d of %d; marks %d%n",
		//	m_nDepth, m_fStartedNext, m_iuactCurr, m_vquact.Size(), m_iCurrSeq, m_viSeqStart.Size(), m_viMarks.Size());
		//::OutputDebugStringA(sta.Chars());
	}

#ifdef DEBUG_ACTION_HANDLER
	StrAnsi sta;
	sta.Format("DiscardToMark:%d", hMark);
	sta.FormatAppend(" m_iCurrSeq=%d, m_viSeqStart=%d, m_iuactCurr=%d, m_vquact=%d, m_viMarks=%d, m_nDepth=%d\n",
		m_iCurrSeq, m_viSeqStart.Size(), m_iuactCurr, m_vquact.Size(), m_viMarks.Size(), m_nDepth);
	::OutputDebugStringA(sta.Chars());
#endif//DEBUG_ACTION_HANDLER

	END_COM_METHOD(g_factActh, IID_IActionHandler);
}
开发者ID:agran147,项目名称:FieldWorks,代码行数:83,代码来源:ActionHandler.cpp

示例11: SetKeyboard_Keyman

/*----------------------------------------------------------------------------------------------
	Set a keyman keyboard
----------------------------------------------------------------------------------------------*/
HRESULT SetKeyboard_Keyman(int lcid, BSTR bstrKeymanKbd, BSTR * pbstrActiveKeymanKbd,
	ComBool * pfSelectLangPending)
{
#ifdef Tracing_KeybdSelection
	StrAnsi sta;
	sta.Format("LgTextServices::SetKeyboard(%d) [setting Keyman kbd]%n", lcid);
	::OutputDebugStringA(sta.Chars());
#endif
	int nLangId = LANGIDFROMLCID(lcid);
	HRESULT hr = S_OK;
	ILgKeymanHandlerPtr qkh;
	qkh.CreateInstance(CLSID_LgKeymanHandler);
	// Tell Keyman about the particular keyboard (but only if it changed).
	if (IsKeyboardDifferent(bstrKeymanKbd, *pbstrActiveKeymanKbd))
	{
		// Activate the particular layout we want.
		// John Durdin says this next step is necessary.
		//::ActivateKeyboardLayout(::GetKeyboardLayout(0), 0);
		// JohnT: discovered that if we've never set a keyboard before, the current one
		// won't be right, but forcing the right langid into the low word seems to help.
		// Keyman always uses the US English keyboard, which is the magic number we're
		// stuffing into the high word.
		HKL hklDesired = (HKL)(0x04090000 | (nLangId & 0xffff));
#ifdef Tracing_KeybdSelection
		StrAnsi sta;
		sta.Format("LgTextServices::SetKeyboard(%d) - "
			"::ActivateKeyboardLayout(%d [%x], 0) for keyman setup\n",
			lcid, hklDesired, hklDesired);
		::OutputDebugStringA(sta.Chars());
#endif
		::ActivateKeyboardLayout(hklDesired, 0);

		try
		{
			CheckHr(qkh->put_ActiveKeyboardName(bstrKeymanKbd));
#ifdef TRACING_KEYMAN
			StrUni stuMsg;
			stuMsg.Format(L"%b is now the active Keyman keyboard.\n",
				bstrKeymanKbd);
			::OutputDebugStringW(stuMsg.Chars());
#endif
			if (*pbstrActiveKeymanKbd)
				::SysFreeString(*pbstrActiveKeymanKbd);
			CopyBstr(pbstrActiveKeymanKbd, bstrKeymanKbd);
			*pfSelectLangPending = true;
		}
		catch (Throwable& thr)
		{
			hr = thr.Result();
#ifdef TRACING_KEYMAN
			StrAnsi staMsg;
			staMsg.Format("Cannot make %B the active Keyman keyboard!?\n",
				bstrKeymanKbd);
			::OutputDebugStringA(staMsg.Chars());
#endif
			if (BstrLen(*pbstrActiveKeymanKbd))
			{
				// We failed, so ensure it's turned off.
				TurnOffKeymanKbd(pbstrActiveKeymanKbd);
				*pfSelectLangPending = true;
			}
		}
	}
	return hr;
}
开发者ID:,项目名称:,代码行数:68,代码来源:

示例12: SetKeyboard_TSF

/*----------------------------------------------------------------------------------------------
	Set the keyboard through TSF
----------------------------------------------------------------------------------------------*/
bool SetKeyboard_TSF(bool fDoingKeyman, int lcid, int * pnActiveLangId)
{
#ifdef Tracing_KeybdSelection
	StrAnsi sta;
	sta.Format("LgTextServices::SetKeyboard(%d) [making TSF calls]%n", lcid);
	::OutputDebugStringA(sta.Chars());
	sta.Format("LgTextServices::SetKeyboard(%d) - ::GetKeyboardLayout() = %x%n",
		lcid, ::GetKeyboardLayout(0));
	::OutputDebugStringA(sta.Chars());
#endif
	HRESULT hr = S_OK;
	ITfInputProcessorProfilesPtr qtfipp;
	int nLangId = LANGIDFROMLCID(lcid);
	bool fSetInputLang = false;
	// Don't check the HR or use CreateInstance; I (JohnT) think this may fail if TSF is not
	// fully active.
	::CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_ALL,
		IID_ITfInputProcessorProfiles, (void **)&qtfipp);
	if (!qtfipp)
	{
		Warn("Could not get ITfInputProcessorProfiles to set Keyman text service\n");
	}
	else
	{
		// Have to make the language active before we can set the profile;
		// and want to set the language even if we aren't doing Keyman.
		if (*pnActiveLangId != (LANGID)nLangId)
		{
			// Do NOT do this if the right langID is already current. In some bizarre cases
			// during WM_INPUTLANGCHANGED it can lead to a new input-lang-changed in a
			// DIFFERENT language and an infinite loop.
			*pnActiveLangId = (LANGID)nLangId;
			IgnoreHr(hr = qtfipp->ChangeCurrentLanguage((LANGID)nLangId));
		}
#ifdef Tracing_KeybdSelection
		sta.Format(
			"LgTextServices::SetKeyboard(%d) [qtfipp->ChangeCL(%d) => hr = %x]%n",
			lcid, nLangId, hr);
		::OutputDebugStringA(sta.Chars());
#endif
		if (FAILED(hr))
		{
			Warn("failed to change language\n");
		}
		else if (fDoingKeyman)
		{
			// Make sure the Keyman text service is turned on. For some bizarre reason there is
			// no API to just ask for the service to turn on for the langid, we have to do our
			// own search for the profile that corresponds to this langid and text service.
			IEnumTfLanguageProfilesPtr qenum;
	#ifdef Tracing_KeybdSelection
			sta.Format("LgTextServices::SetKeyboard(%d) [qtfipp->EnumLP(%d)]%n",
				lcid, nLangId);
			::OutputDebugStringA(sta.Chars());
			sta.Format("LgTextServices::SetKeyboard(%d) - ::GetKeyboardLayout() = %x%n",
				lcid, ::GetKeyboardLayout(0));
			::OutputDebugStringA(sta.Chars());
	#endif
			IgnoreHr(hr = qtfipp->EnumLanguageProfiles((LANGID)nLangId, &qenum));
			if (FAILED(hr))
			{
				Warn("Could not get enumerator for language profiles\n");
			}
			else
			{
				// If doing keyman try to turn on Keyman text service.
				TF_LANGUAGEPROFILE profile;
				for ( ; ; )
				{
					ULONG cprofile;
					IgnoreHr(hr = qenum->Next(1, &profile, &cprofile));
					if (FAILED(hr) || cprofile != 1)
					{
						Warn("failed to find language profiled for Keyman\n");
						break;
					}
					if (kclsidKMTipTextService == profile.clsid)
					{
						// got it at last!
#ifdef Tracing_KeybdSelection
						StrAnsi sta;
						sta.Format("LgTextServices::SetKeyboard(%d) - "
							"qtfipp->ActivateLanguageProfile(nLangId = %d)\n",
							lcid, nLangId);
						::OutputDebugStringA(sta.Chars());
#endif
						IgnoreHr(hr = qtfipp->ActivateLanguageProfile(
							kclsidKMTipTextService, (LANGID)nLangId, profile.guidProfile));
						if (FAILED(hr))
						{
							Warn("failed to activate language profile\n");
						}
						else
						{
							fSetInputLang = true;
						}
						break;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例13: WndProc

/*----------------------------------------------------------------------------------------------
	This static method provides the basic window procedure used in this application framework.

	@param hwnd Handle of the window to which the message is directed.
	@param wm Window message identifier.
	@param wp First message parameter -- depends on the message.
	@param lp Second message parameter -- depends on the message.

	@return Result of the message processing -- depends on the message.
----------------------------------------------------------------------------------------------*/
LRESULT CALLBACK AfWnd::WndProc(HWND hwnd, uint wm, WPARAM wp, LPARAM lp)
{
	Assert(hwnd);

	AfWndPtr qwnd = reinterpret_cast<AfWnd *>(::GetWindowLong(hwnd, GWL_USERDATA));
	AssertPtrN(qwnd);
#ifdef _DEBUG
	if (DebugWindowMessages)
	{
		const type_info & myTypeInfo (typeid(*(qwnd.Ptr())));
		StrAnsi staT;
		staT.Format("Message %x sent to %s (%x)\n", wm, myTypeInfo.name(), hwnd);
		::OutputDebugStringA(staT.Chars());
	}
#endif

	if (!qwnd)
	{
		if (wm != WM_CREATE)
			return ::DefWindowProc(hwnd, wm, wp, lp);

		CREATESTRUCT * pcs = reinterpret_cast<CREATESTRUCT *>(lp);
		if (!pcs || !pcs->lpCreateParams)
			return ::DefWindowProc(hwnd, wm, wp, lp);

		AssertPtr(pcs);
		AfWndCreate * pafwc = reinterpret_cast<AfWndCreate *>(pcs->lpCreateParams);
		AssertPtr(pafwc);
		qwnd = pafwc->pwnd;
		AssertPtr(qwnd);

		try
		{
			qwnd->AttachHwnd(hwnd);
		}
		catch (...)
		{
			Warn("AttachHwnd failed.");
			return -1;
		}

		// Put the user-defined value back into pcs so that the subclass will have it.
		pcs->lpCreateParams = pafwc->pv;
	}

	Assert(qwnd->m_hwnd == hwnd);

	bool fRet;
	long lnRet = 0;

	BEGIN_TOP_LEVEL_ACTION
		// Call the pre non-virtual WndProc.
		fRet = qwnd->FWndProcPre(wm, wp, lp, lnRet);

		// Call the virtual window proc.
		if (!fRet)
			fRet = qwnd->FWndProc(wm, wp, lp, lnRet);

		qwnd->WndProcPost(fRet, hwnd, wm, wp, lp, lnRet);
	END_TOP_LEVEL_ACTION

	// Assert(_CrtCheckMemory()); //Not a bad place to insert this if having memory troubles.
	return lnRet;
}
开发者ID:,项目名称:,代码行数:74,代码来源:

示例14: Process

/*----------------------------------------------------------------------------------------------
	Crawl through the database and rename/delete the given styles.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP FwDbMergeStyles::Process(DWORD hWnd)
{
	BEGIN_COM_METHOD;
	Assert(m_vstuOldNames.Size() == m_vstuNewNames.Size());

	if (!m_hvoRoot)
		return E_UNEXPECTED;
	if (!m_pclsidApp)
		return E_UNEXPECTED;

	if (LogFile())
	{
		ULONG cbLog;
		StrAnsi staLog;
		staLog.Format("Changing style names in %S (%S)%n",
			DbName().Chars(), ServerName().Chars());
		LogFile()->Write(staLog.Chars(), staLog.Length(), &cbLog);
	}

	m_qprog->DoModeless((HWND)hWnd);
	StrUni stuMsg(kstidChgStyleLabel);
	m_qprog->put_Title(stuMsg.Bstr());

	ResetConnection();
	BeginTrans();
	CreateCommand();

	SetPercentComplete(0);

	// We want to affect only a subset of the formatting and style information in the database,
	// based on which program is currently running, since different programs may be using
	// different sets of styles.  This information is derived from m_hvoRoot and m_pclsidApp.
	// (Unfortunately, there's no way to derive one of these values from the other one.)  The
	// current scheme works for Data Notebook, List Editor, TE, and LexText.  Additional
	// programs may introduce even more complexities.
	// 1. Find all the owners of StStyle objects.  This should match up to LangProject (Data
	//    Notebook and List Editor), Scripture (TE), or LexDb (LexText).
	// 2. If an owner equals m_hvoRoot, then only those objects owned by m_hvoRoot have the
	//    string and paragraph formatting fixed.  Except that LexText also wants to fix all the
	//    Text objects owned by the LangProject in addition to all the objects owned by the
	//    LexDb, so those have to be added to the collection of objects.
	// 3. If none of the owners equals m_hvoRoot, we must be dealing with Data Notebook or List
	//    Editor, which share a common set of styles owned by the LangProject itself.  In
	//    this case, we want all the objects owned by the LangProject except those owned by
	//    another owner of styles (or the LangProject Text objects, since those use the
	//    LexText styles even though they're not owned by the root object).  (This isn't quite
	//    right if either TE or LexText does not actually own any styles yet, but we won't worry
	//    about this nicety.)
	// 4. After creating a temp table containing just the ids of those objects of interest, we
	//    can then process all the relevant string formatting (via a string crawler) and
	//    paragraph StyleRules (later in this method)
	// 5. Finally, we may need to fix the Style fields of the relevant UserViewField objects.
	//    These are limited by the psclsidApp argument, since the UserView objects are specific
	//    to specific applications.  If pssclidApp indicates either Data Notebook or List
	//    Editor, then UserViewField objects belonging to both of those programs are fixed.
	//    Otherwise, only those UserViewField objects belonging to the specific program
	//    identified by psclsidApp are fixed.

	ComBool fMoreRows;
	UINT cbSpaceTaken;
	ComBool fIsNull;
	int hobj = 0;
	int clid = 0;
	bool fFixOwned = false;
	int clidOwned = 0;
	int hvoLangProj = 0;
	Vector<int> vhvoOwners;
	Vector<int> vclidOwners;
	Vector<int> vhvoTexts;
	StrUni stuCmd;
	stuCmd.Format(L"SELECT DISTINCT c.Owner$, co.Class$ "
		L"FROM CmObject c "
		L"JOIN CmObject co on co.Id = c.Owner$ "
		L"WHERE c.Class$ = %d",
		kclidStStyle);
	CheckHr(GetOleDbCommand()->ExecCommand(stuCmd.Bstr(), knSqlStmtSelectWithOneRowset));
	CheckHr(GetOleDbCommand()->GetRowset(0));
	CheckHr(GetOleDbCommand()->NextRow(&fMoreRows));
	while (fMoreRows)
	{
		CheckHr(GetOleDbCommand()->GetColValue(1, reinterpret_cast <BYTE *>(&hobj),
			isizeof(hobj), &cbSpaceTaken, &fIsNull, 0));
		CheckHr(GetOleDbCommand()->GetColValue(2, reinterpret_cast <BYTE *>(&clid),
			isizeof(clid), &cbSpaceTaken, &fIsNull, 0));
		if (hobj == m_hvoRoot)
		{
			fFixOwned = true;
			clidOwned = clid;
		}
		else if (clid == kclidLangProject)
		{
			hvoLangProj = hobj;
		}
		else
		{
			vhvoOwners.Push(hobj);
			vclidOwners.Push(clid);
//.........这里部分代码省略.........
开发者ID:agran147,项目名称:FieldWorks,代码行数:101,代码来源:FwDbMergeStyles.cpp

示例15: WriteBulNumFontInfo

/*----------------------------------------------------------------------------------------------
	Write the given FontInfo string text property value in readable XML format.

	@param pstrm Pointer to an IStream for output.
	@param bstrVal
----------------------------------------------------------------------------------------------*/
void FwXml::WriteBulNumFontInfo(IStream * pstrm, BSTR bstrVal, int cchIndent)
{
	AssertPtr(pstrm);
	Assert(cchIndent >= 0);
	int cchProps = ::SysStringLen(bstrVal);
	if (!cchProps)
		return;

	Vector<char> vchIndent;
	vchIndent.Resize(cchIndent + 1);
	memset(vchIndent.Begin(), ' ', cchIndent);

	const OLECHAR * pchProps = bstrVal;
	const OLECHAR * pchPropsLim = pchProps + cchProps;

	FormatToStream(pstrm, "%s<BulNumFontInfo", vchIndent.Begin());
	StrAnsi staItalic;
	StrAnsi staBold;
	StrAnsi staSuperscript;
	StrAnsi staUnderline;
	StrAnsi staFontsize;
	StrAnsi staOffset;
	StrAnsi staForecolor;
	StrAnsi staBackcolor;
	StrAnsi staUndercolor;
	StrAnsi staXXX;
	int tpt;
	while (pchProps < pchPropsLim)
	{
		tpt = *pchProps++;
		if (tpt == ktptFontFamily)
			break;

		int nVal = *pchProps + ((*(pchProps + 1)) << 16);
		pchProps += 2;
		switch (tpt)
		{
		case ktptItalic:
			staItalic.Format(" italic=\"%s\"", ToggleValueName((byte)nVal));
			break;
		case ktptBold:
			staBold.Format(" bold=\"%s\"", ToggleValueName((byte)nVal));
			break;
		case ktptSuperscript:
			staSuperscript.Format(" superscript=\"%s\"", SuperscriptValName((byte)nVal));
			break;
		case ktptUnderline:
			staUnderline.Format(" underline=\"%s\"", UnderlineTypeName((byte)nVal));
			break;
		case ktptFontSize:
			staFontsize.Format(" fontsize=\"%dmpt\"", nVal);
			break;
		case ktptOffset:
			staOffset.Format(" offset=\"%dmpt\"", nVal);
			break;
		case ktptForeColor:
			staForecolor.Format(" forecolor=\"%s\"", ColorName(nVal));
			break;
		case ktptBackColor:
			staBackcolor.Format(" backcolor=\"%s\"", ColorName(nVal));
			break;
		case ktptUnderColor:
			staUndercolor.Format(" undercolor=\"%s\"", ColorName(nVal));
			break;
		default:
			staXXX.FormatAppend(" prop_%u=\"%d\"", tpt, nVal);
			break;
		}
	}
	ULONG cb;
	// Write the integer valued properties in alphabetical order.
	if (staBackcolor.Length())
		pstrm->Write(staBackcolor.Chars(), staBackcolor.Length(), &cb);
	if (staBold.Length())
		pstrm->Write(staBold.Chars(), staBold.Length(), &cb);
	if (staFontsize.Length())
		pstrm->Write(staFontsize.Chars(), staFontsize.Length(), &cb);
	if (staForecolor.Length())
		pstrm->Write(staForecolor.Chars(), staForecolor.Length(), &cb);
	if (staItalic.Length())
		pstrm->Write(staItalic.Chars(), staItalic.Length(), &cb);
	if (staOffset.Length())
		pstrm->Write(staOffset.Chars(), staOffset.Length(), &cb);
	if (staSuperscript.Length())
		pstrm->Write(staSuperscript.Chars(), staSuperscript.Length(), &cb);
	if (staUndercolor.Length())
		pstrm->Write(staUndercolor.Chars(), staUndercolor.Length(), &cb);
	if (staUnderline.Length())
		pstrm->Write(staUnderline.Chars(), staUnderline.Length(), &cb);
	if (staXXX.Length())
		pstrm->Write(staXXX.Chars(), staXXX.Length(), &cb);
	// Write the string valued property (if it exists).
	if (tpt == ktptFontFamily && pchProps < pchPropsLim)
	{
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的StrAnsi::Format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。