Beispiel #1
0
/*----------------------------------------------------------------------------------------------
	Set the text of the control to be equal to ptss. If ptss is NULL, the edit box is cleared.
	Message: FW_EM_SETTEXT.
----------------------------------------------------------------------------------------------*/
void TssEdit::SetText(ITsString * ptss)
{
	AssertPtrN(ptss); // NULL can be used to clear string.
	Assert(m_qcda);

	ITsStringPtr qtss = ptss;
	if (!ptss)
	{
		ITsStrFactoryPtr qtsf;
		qtsf.CreateInstance(CLSID_TsStrFactory);
		CheckHr(qtsf->MakeStringRgch(L"", 0, m_wsBase, &qtss));
	}
	ITsStringPtr qtssOld;
	CheckHr(m_qcda->get_StringProp(khvoString, ktagString, &qtssOld));
	int cchOld;
	CheckHr(qtssOld->get_Length(&cchOld));
	CheckHr(m_qcda->CacheStringProp(khvoString, ktagString, qtss));
	int cchNew;
	CheckHr(qtss->get_Length(&cchNew));
	// Pretend the whole length has been deleted and the whole new inserted.
	CheckHr(m_qcda->PropChanged(NULL, kpctNotifyAll, khvoString, ktagString, 0, cchNew, cchOld));
	OnUpdate();
	::UpdateWindow(m_hwnd);
	OnChange();
}
Beispiel #2
0
/*----------------------------------------------------------------------------------------------
	Decode the toggle enum value represented by the input string, which must either be a
	standard term, or a decimal number.

	@param pszToggle String containing a toggle enum value, either a name or a decimal value.
	@param ppsz Address of pointer to the end of the comparison or computation.

	@return The toggle value represented by the input string.
----------------------------------------------------------------------------------------------*/
int FwXml::DecodeTextToggleVal(const char * pszToggle, const char ** ppsz)
{
	AssertPtr(pszToggle);
	AssertPtrN(ppsz);

	if (!_strnicmp(pszToggle, "off", 3))
	{
		if (ppsz)
			*ppsz = pszToggle + 3;
		return kttvOff;
	}
	else if (!_strnicmp(pszToggle, "on", 2))
	{
		if (ppsz)
			*ppsz = pszToggle + 2;
		return kttvForceOn;
	}
	else if (!_strnicmp(pszToggle, "invert", 6))
	{
		if (ppsz)
			*ppsz = pszToggle + 6;
		return kttvInvert;
	}
	else
	{
		return (int)strtol(pszToggle, const_cast<char **>(ppsz), 10);
	}
}
Beispiel #3
0
/*----------------------------------------------------------------------------------------------
	Initialize variables prior to creating the control, i.e. create/attach a ISilDataAccess
	and add TsString to cache
	(may be explicitly called when created by ATL, because in this case TssEdit::Create() will
	not be called)
----------------------------------------------------------------------------------------------*/
void TssEdit::PreCreate(ILgWritingSystemFactory * pwsf, int ws, ITsString * ptss,
	IActionHandler * pacth)
{
	AssertPtr(pwsf);
	AssertPtrN(ptss);

	ITsStringPtr qtss = ptss;
	if (!ptss)
	{
		ITsStrFactoryPtr qtsf;
		qtsf.CreateInstance(CLSID_TsStrFactory);
		CheckHr(qtsf->MakeStringRgch(L"", 0, ws, &qtss));
	}

	if (pacth)
	{
		// We want actions in this edit box to be undoable.
		VwUndoDaPtr quda;
		quda.Attach(NewObj VwUndoDa);
		CheckHr(quda->SetActionHandler(pacth));
		m_qcda.Attach(quda.Detach());
	}
	else
	{
		m_qcda.Attach(NewObj VwCacheDa);
	}
	m_qcda->putref_WritingSystemFactory(pwsf);
	m_qcda->CacheStringProp(khvoString, ktagString, qtss);
}
Beispiel #4
0
/*----------------------------------------------------------------------------------------------
	Get our thread local data.
----------------------------------------------------------------------------------------------*/
TextServGlobals * TextServGlobals::GetTsGlobals(void)
{
#if !WIN32
	// Ensure ProcessAttach is called exactly once
	static pthread_once_t once_control = PTHREAD_ONCE_INIT;
	pthread_once(&once_control, ProcessAttach);
#endif

#if WIN32
	TextServGlobals * ptsg = static_cast<TextServGlobals *>(TlsGetValue(s_luTls));
#else
	TextServGlobals * ptsg = static_cast<TextServGlobals *>(pthread_getspecific(s_luTls));
#endif //WIN32
	AssertPtrN(ptsg);

	if (!ptsg)
	{
		ptsg = NewObj TextServGlobals;
#if WIN32
		TlsSetValue(s_luTls, ptsg);
#else
		pthread_setspecific(s_luTls, ptsg);
#endif //WIN32
		AddToTsgVec(ptsg);
	}

	return ptsg;
}
Beispiel #5
0
/*----------------------------------------------------------------------------------------------
	A simple demonstration method which returns a fixed string.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP SampleInterface::get_HelloWorldString(BSTR * pbstr)
{
	AssertPtrN(pbstr);
	if (!pbstr)
		return E_POINTER;
	*pbstr = SysAllocString(L"Hello World from the SimpleDll");
	if (!*pbstr)
		return E_OUTOFMEMORY;
	return S_OK;
}
Beispiel #6
0
/*----------------------------------------------------------------------------------------------
	Make the root box.
----------------------------------------------------------------------------------------------*/
void TssEdit::MakeRoot(IVwGraphics * pvg, ILgWritingSystemFactory * pwsf, IVwRootBox ** pprootb)
{
	AssertPtr(pvg);
	AssertPtrN(pwsf);
	AssertPtr(pprootb);

	*pprootb = NULL;

	IVwRootBoxPtr qrootb;
	qrootb.CreateInstance(CLSID_VwRootBox);
	CheckHr(qrootb->SetSite(this));
	HVO hvo = khvoString;
	int frag = kfrString;

	// Set up a new view constructor.
	ComBool fRTL = FALSE;
	IWritingSystemPtr qws;
	Assert(pwsf == m_qwsf.Ptr());
	CheckHr(pwsf->get_EngineOrNull(m_wsBase, &qws));
	if (qws)
		CheckHr(qws->get_RightToLeft(&fRTL));
	TssEditVcPtr qtevc;
	qtevc.Attach(NewObj TssEditVc(this, m_nEditable, m_fShowTags, fRTL));

	CheckHr(m_qcda->putref_WritingSystemFactory(pwsf));
	CheckHr(qrootb->putref_DataAccess(m_qcda));

	AfMainWnd * pafw = MainWindow();
	AssertPtrN(pafw);
	AfStylesheet * pss = NULL;
	AfLpInfo * plpi = pafw->GetLpInfo();
	if (plpi)
	{
		pss = plpi->GetAfStylesheet();
		// This allows it to receive updates to style defns.
		pafw->RegisterRootBox(qrootb);
	}
	IVwViewConstructor * pvvc = qtevc;
	CheckHr(qrootb->SetRootObjects(&hvo, &pvvc, &frag, pss, 1));

	*pprootb = qrootb.Detach();
}
Beispiel #7
0
	bool Vector<T>::Pop(T * peRet)
{
	AssertObj(this);
	AssertPtrN(peRet);

	if (!m_ieLim)
		return false;

	Delete(m_ieLim - 1, m_ieLim, peRet);
	return true;
}
Beispiel #8
0
/*----------------------------------------------------------------------------------------------
	Static method to find a class factory (from the given CLSID) from all the class factories
	that are in the linked list. If the requested class factory is not found, *ppv is set
	to NULL and CLASS_E_CLASSNOTAVAILABLE is returned.
----------------------------------------------------------------------------------------------*/
HRESULT ModuleEntry::ModuleGetClassObject(REFCLSID clsid, REFIID iid, void ** ppv)
{
	AssertPtrN(ppv);
	if (!ppv)
		return WarnHr(E_POINTER);
	*ppv = NULL;

	// This block of code is largely copied from the AssertNoErrorInfo method in throwable.h.
	// Here, however, we don't assert, but just dump a warning to the output window and
	// discard the spurious error info. This prevents asserts if Windows.Forms calls
	// a class factory (as it has been known to do) with spurious error info registered.
#ifdef DEBUG
	IErrorInfo * pIErrorInfo = NULL;
	HRESULT hr = GetErrorInfo(0, &pIErrorInfo);
	Assert(SUCCEEDED(hr));

	if(pIErrorInfo != NULL) {
		BSTR bstr;
		hr = pIErrorInfo->GetDescription(&bstr);
		Assert(SUCCEEDED(hr));
		::OutputDebugString(bstr);
		::SysFreeString(bstr);
		hr = pIErrorInfo->GetSource(&bstr);
		Assert(SUCCEEDED(hr));
		::OutputDebugString(bstr);
		::SysFreeString(bstr);
		pIErrorInfo->Release();
	}
#endif

	ModuleEntry * pme;

	try
	{
		for (pme = s_pmeFirst; pme; pme = pme->m_pobjNext)
		{
			AssertPtr(pme);
			pme->GetClassFactory(clsid, iid, ppv);
			if (*ppv)
				return S_OK;
		}
	}
	catch (const Throwable & thr)
	{
		return thr.Error();
	}
	catch (...)
	{
		return WarnHr(E_FAIL);
	}

	return CLASS_E_CLASSNOTAVAILABLE;
}
Beispiel #9
0
/*----------------------------------------------------------------------------------------------
	Retrieve the anchor and end character positions of the current selection.
	NOTE: *pichAnchor could be greater than *pichEnd.
	Returns true if there is a selection.
	Message: EM_GETSEL.
----------------------------------------------------------------------------------------------*/
bool TssEdit::GetSel(int * pichAnchor, int * pichEnd, bool * pfAssocPrev)
{
	AssertPtrN(pichAnchor);
	AssertPtrN(pichEnd);
	AssertPtrN(pfAssocPrev);
	AssertPtr(m_qrootb);

	int ichDummy;
	bool fDummy;
	if (!pichAnchor)
		pichAnchor = &ichDummy;
	if (!pichEnd)
		pichEnd = &ichDummy;
	if (!pfAssocPrev)
		pfAssocPrev = &fDummy;
	*pichAnchor = 0;
	*pichEnd = 0;
	*pfAssocPrev = true;

	IVwSelectionPtr qvwsel;
	CheckHr(m_qrootb->get_Selection(&qvwsel));
	if (!qvwsel)
		return false;

	int ihvoRoot;
	PropTag tagTextProp;
	int cpropPrevious;
	int ws;
	ComBool fAssocPrev;
	int ihvoEnd;

	CheckHr(qvwsel->AllTextSelInfo(&ihvoRoot, 0, NULL, &tagTextProp,
		&cpropPrevious, pichAnchor, pichEnd, &ws, &fAssocPrev, &ihvoEnd, NULL));
	*pfAssocPrev = (bool)fAssocPrev;

	return true;
}
Beispiel #10
0
/*----------------------------------------------------------------------------------------------
	Create a new TssEdit. psz can be NULL if the control should start out empty.
----------------------------------------------------------------------------------------------*/
void TssEdit::Create(HWND hwndPar, int cid, DWORD dwStyle, HWND hwndToolTip, const achar * psz,
	ILgWritingSystemFactory * pwsf, int ws, IActionHandler * pacth)
{
	AssertPtrN(psz);
	AssertPtr(pwsf);

	ITsStringPtr qtss;
	if (psz)
	{
		ITsStrFactoryPtr qtsf;
		qtsf.CreateInstance(CLSID_TsStrFactory);
		StrUni stu(psz);
		CheckHr(qtsf->MakeString(stu.Bstr(), ws, &qtss));
	}
	Create(hwndPar, cid, dwStyle, hwndToolTip, qtss, pwsf, ws, pacth);
}
Beispiel #11
0
/*----------------------------------------------------------------------------------------------
	Display TsString in the control
	(may be explicitly called when created by ATL, because in this case TssEdit::Create() will
	not be called)
----------------------------------------------------------------------------------------------*/
void TssEdit::PostCreate(ITsString * ptss)
{
	AssertPtrN(ptss);

	if (ptss)
	{
		int cch;
		ITsStringPtr qtss = ptss;
		CheckHr(qtss->get_Length(&cch));
		// Treat as inserting all the characters, since the cache previously had nothing.
		CheckHr(m_qcda->PropChanged(NULL, kpctNotifyAll, khvoString, ktagString, 0, cch, 0));
		OnUpdate();
		::UpdateWindow(m_hwnd);
		OnChange();
	}
}
Beispiel #12
0
/*----------------------------------------------------------------------------------------------
	Remove the last element from the ComVector.  If the provided pointer is not NULL, copy the
	stored COM interface pointer to that location and don't call Release.  Otherwise, Release
	is called before the memory location is cleared.
----------------------------------------------------------------------------------------------*/
bool BaseOfComVector::Pop(IUnknown ** ppunkRet)
{
	AssertObj(this);
	AssertPtrN(ppunkRet);
	if (m_ce > 0)
	{
		IUnknown ** peLast = m_peFirst + m_ce - 1;
		if (NULL != ppunkRet)
			*ppunkRet = *peLast;
		else
			_DestroyRange(peLast, peLast + 1);
		--m_ce;
		return true;
	}
	else
		return false;
}
Beispiel #13
0
void AfDeFeSt::MakeRoot(IVwGraphics * pvg, ILgWritingSystemFactory * pwsf, IVwRootBox ** pprootb)
{
	AssertPtrN(pwsf);
	*pprootb = NULL;

	// Do we have a real text object? If not, make a fake one.
	int cpara = 0;
	ISilDataAccessPtr qsda = m_qcvd;
	if (m_hvoText)
		CheckHr(qsda->get_VecSize(m_hvoText, kflidStText_Paragraphs, &cpara));
	if (!cpara)
	{
		// We make a dummy text that is complete enough to edit, in a separate data access
		// object. On loss of focus, if this data access is dirty, we make corresponding
		// real objects.
		if (!m_hvoText)
			m_hvoText = -1;
		HVO hvoPara = -2;
		m_qvcdMissing.CreateInstance(CLSID_VwCacheDa);
		CheckHr(m_qvcdMissing->QueryInterface(IID_ISilDataAccess, (void **)&qsda));
		m_qvcdMissing->CacheVecProp(m_hvoText, kflidStText_Paragraphs, &hvoPara,1);
		ITsStrFactoryPtr qtsf;
		qtsf.CreateInstance(CLSID_TsStrFactory);
		ITsStringPtr qtssMissing;
		CheckHr(qtsf->MakeStringRgch(L"", 0, m_ws, &qtssMissing));
		m_qvcdMissing->CacheStringProp(hvoPara, kflidStTxtPara_Contents, qtssMissing);
	}

	IVwRootBoxPtr qrootb;
	qrootb.CreateInstance(CLSID_VwRootBox);
	CheckHr(qrootb->SetSite(this)); // pass root site
	int frag = kfrText;
	IVwViewConstructor * pvvc = m_qstvc;
	if (pwsf)
		CheckHr(qsda->putref_WritingSystemFactory(pwsf));
	CheckHr(qrootb->putref_DataAccess(qsda));
	CheckHr(qrootb->SetRootObjects(&m_hvoText, &pvvc, &frag,
		GetLpInfo()->GetAfStylesheet(), 1));
	*pprootb = qrootb;
	(*pprootb)->AddRef();

	RecMainWnd * prmw = dynamic_cast<RecMainWnd *>(m_qadsc->MainWindow());
	if (prmw)
		prmw->RegisterRootBox(qrootb);
}
Beispiel #14
0
/*----------------------------------------------------------------------------------------------
	Free our thread local data. Note that we are not guaranteed this is called for every
	thread; it is called if a thread is explicitly killed, but not if the library is unloaded
	or the process ends.
----------------------------------------------------------------------------------------------*/
void TextServGlobals::ThreadDetach(void)
{
#if WIN32
	TextServGlobals * ptsg = static_cast<TextServGlobals *>(TlsGetValue(s_luTls));
#else
	TextServGlobals * ptsg = static_cast<TextServGlobals *>(pthread_getspecific(s_luTls));
#endif //WIN32
	AssertPtrN(ptsg);
	if (ptsg)
	{
		delete ptsg;
#if WIN32
		TlsSetValue(s_luTls, NULL);
#else
		pthread_setspecific(s_luTls, 0);
#endif //WIN32
		RemoveFromTsgVec(ptsg);
	}
}
Beispiel #15
0
	static bool FParseSilTime(const XChar * prgch, int cch, XChar chDateSep, XChar chSep,
		XChar chTimeSep, const XChar ** ppchLim, bool fUtc, SilTime * pstim)
{
	// REVIEW SteveMc: Should we do range checking and report errors?
	AssertArray(prgch, cch);
	AssertPtrN(ppchLim);
	AssertPtr(pstim);

	SilTimeInfo sti;
	ClearItems(&sti, 1);

	const XChar * pch = prgch;
	const XChar * pchLim = prgch + cch;

	// Get the year.
	if (pch < pchLim && *pch == '-')
		pch++;
	while (pch < pchLim && '0' <= *pch && *pch <= '9')
		sti.year = sti.year * 10 + (*pch++ - '0');
	if (cch > 0 && *prgch == chDateSep)
		sti.year = -sti.year;

	if (pch < pchLim && *pch == chDateSep)
	{
		pch++;
		while (pch < pchLim && '0' <= *pch && *pch <= '9')
			sti.ymon = sti.ymon * 10 + (*pch++ - '0');
		if (pch < pchLim && *pch == chDateSep)
		{
			pch++;
			while (pch < pchLim && '0' <= *pch && *pch <= '9')
				sti.mday = sti.mday * 10 + (*pch++ - '0');
		}
	}

	if (pch < pchLim && *pch == chSep)
	{
		pch++;
		while (pch < pchLim && '0' <= *pch && *pch <= '9')
			sti.hour = sti.hour * 10 + (*pch++ - '0');
		if (pch < pchLim && *pch == chTimeSep)
		{
			pch++;
			while (pch < pchLim && '0' <= *pch && *pch <= '9')
				sti.min = sti.min * 10 + (*pch++ - '0');
			if (pch < pchLim && *pch == chTimeSep)
			{
				pch++;
				while (pch < pchLim && '0' <= *pch && *pch <= '9')
					sti.sec = sti.sec * 10 + (*pch++ - '0');
				if (pch < pchLim && *pch == '.')
				{
					pch++;
					if ('0' <= *pch && *pch <= '9')
					{
						sti.msec += (*pch++ - '0') * 100;
						if ('0' <= *pch && *pch <= '9')
						{
							sti.msec += (*pch++ - '0') * 10;
							if ('0' <= *pch && *pch <= '9')
								sti.msec += (*pch++ - '0');
						}
					}
				}
			}
		}
	}

	if (ppchLim)
		*ppchLim = pch;

	pstim->SetTimeInfo(sti, true);
	return true;
}
Beispiel #16
0
/*----------------------------------------------------------------------------------------------
	Decode the color value represented by the input string, which must either be a standard
	English color name, or a 6/8-digit hexadecimal number.

	@param pszColor String containing a color value, either a name or a hexadecimal (RGB?)
					value.
	@param ppsz Address of pointer to the end of the comparison or computation.

	@return The color value represented by the input string.
----------------------------------------------------------------------------------------------*/
int FwXml::DecodeTextColor(const char * pszColor, const char ** ppsz)
{
	AssertPtr(pszColor);
	AssertPtrN(ppsz);

	if (!_strnicmp(pszColor, "white", 5))
	{
		if (ppsz)
			*ppsz = pszColor + 5;
		return kclrWhite;
	}
	else if (!_strnicmp(pszColor, "black", 5))
	{
		if (ppsz)
			*ppsz = pszColor + 5;
		return kclrBlack;
	}
	else if (!_strnicmp(pszColor, "red", 3))
	{
		if (ppsz)
			*ppsz = pszColor + 3;
		return kclrRed;
	}
	else if (!_strnicmp(pszColor, "green", 5))
	{
		if (ppsz)
			*ppsz = pszColor + 5;
		return kclrGreen;
	}
	else if (!_strnicmp(pszColor, "blue", 4))
	{
		if (ppsz)
			*ppsz = pszColor + 4;
		return kclrBlue;
	}
	else if (!_strnicmp(pszColor, "yellow", 6))
	{
		if (ppsz)
			*ppsz = pszColor + 6;
		return kclrYellow;
	}
	else if (!_strnicmp(pszColor, "magenta", 7))
	{
		if (ppsz)
			*ppsz = pszColor + 7;
		return kclrMagenta;
	}
	else if (!_strnicmp(pszColor, "cyan", 4))
	{
		if (ppsz)
			*ppsz = pszColor + 4;
		return kclrCyan;
	}
	else if (!_strnicmp(pszColor, "transparent", 11))
	{
		if (ppsz)
			*ppsz = pszColor + 11;
		return kclrTransparent;
	}
	else
	{
#if 1
		if (strspn(pszColor, "0123456789ABCDEFabcdef") == 6)
		{
			// Interpret the hexadecimal value as "RRGGBB" (compatible with XHTML).
			unsigned nBigEndian = strtoul(pszColor, const_cast<char **>(ppsz), 16);
			unsigned nBlue = (nBigEndian & 0xFF) << 16;
			unsigned nGreen = (nBigEndian & 0xFF00);
			unsigned nRed = (nBigEndian & 0xFF0000) >> 16;
			return nBlue | nGreen | nRed;
		}
		else
		{
Beispiel #17
0
/*----------------------------------------------------------------------------------------------
	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;
}