Ejemplo n.º 1
0
/*----------------------------------------------------------------------------------------------
	This initializes the string based after the pssl and pss have been set. It takes into
	account whether the view is hierarchical or not.
	@param fHier
	@param pnt
----------------------------------------------------------------------------------------------*/
void AfDeFeCliRef::InitContents(bool fHier, PossNameType pnt)
{
	Assert(m_hvoPssl); // This must be set prior to calling this method.
	Assert(pnt < kpntLim);

	SuperClass::Init(); // Initialize the superclass.

	m_fHier = fHier;
	m_pnt = pnt;

	if (!m_pss)
		return; // If the reference isn't set, we don't have anything to display.

	ITsStringPtr qtss;
	ITsStrFactoryPtr qtsf;
	StrUni stu;
	PossListInfoPtr qpli;
	PossItemInfo * ppii;
	int ipss;

	qtsf.CreateInstance(CLSID_TsStrFactory);
	GetLpInfo()->LoadPossList(m_hvoPssl, m_wsMagic, &qpli);
	AssertPtr(qpli);
	ipss = qpli->GetIndexFromId(m_pss);
	ppii = qpli->GetPssFromIndex(ipss);
	AssertPtr(ppii);
	if (m_fHier)
		ppii->GetHierName(qpli, stu, m_pnt);
	else
		ppii->GetName(stu, m_pnt);
	int ws = ppii->GetWs();
	qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss);
	m_qtss = qtss;
	qpli->AddNotify(this);
}
Ejemplo n.º 2
0
/*----------------------------------------------------------------------------------------------
	Get the version information for a module. It is passed the path name to the module.
----------------------------------------------------------------------------------------------*/
StrUni GetModuleVersion(const OLECHAR * pchPathName)
{
	StrUni stuRet;
#ifdef WIN32
	StrApp staPathName = pchPathName;
	achar * pchaPathName = const_cast<achar *>(staPathName.Chars());

	DWORD dwDum; // Always set to zero.
	DWORD cb = GetFileVersionInfoSize(pchaPathName, &dwDum);

	LPVOID pBlock = (LPVOID) _alloca(cb);

	if (!GetFileVersionInfo(pchaPathName, 0, cb, pBlock))
		return stuRet; // Can't get requested info

	VS_FIXEDFILEINFO * pffi;
	uint nT;
	::VerQueryValue(pBlock, _T("\\"), (void **)&pffi, &nT);

	stuRet.Format(L"Version: %d, %d, %d, %d", HIWORD(pffi->dwFileVersionMS),
		LOWORD(pffi->dwFileVersionMS), HIWORD(pffi->dwFileVersionLS),
		LOWORD(pffi->dwFileVersionLS));
#endif
	return stuRet;
}
Ejemplo n.º 3
0
void TestCollatingEngine::TestCompare(StrUni stuVal1, StrUni stuVal2, int nExpected)
{
	HRESULT hr;
	int nActual1, nActual2;
	SmartBstr sbstrKey1, sbstrKey2;
	SmartBstr sbstrVal1 = (stuVal1 ? stuVal1.Bstr() : NULL);
	SmartBstr sbstrVal2 = (stuVal2 ? stuVal2.Bstr() : NULL);

	// First comparison method
	hr = m_qcoleng->Compare(sbstrVal1, sbstrVal2, fcoDefault, &nActual1);
	TestHrFail(hr, "String compare");

	// Make sure we get the same result with the other method:
	// by getting the keys themselves and comparing them.
	hr = m_qcoleng->get_SortKey(sbstrVal1, fcoDefault, &sbstrKey1);
	TestFailZero(sbstrKey1, "get_SortKey");
	TestHrFail(hr, "getting SortKey on string 1");
	hr = m_qcoleng->get_SortKey(sbstrVal2, fcoDefault, &sbstrKey2);
	TestFailZero(sbstrKey2, "get_SortKey");
	TestHrFail(hr, "getting SortKey on string 2");

	nActual2 = wcscmp(sbstrKey1, sbstrKey2);

	if (sgn(nActual1) != sgn(nActual2))
		Failure("String comparison yielded inconsistent results");

	if (sgn(nActual1) != sgn(nExpected))
	{
		FailureFormat(L"Comparison of %s to %s gave %d instead of %d.",
			(sbstrVal1 ? sbstrVal1 : L"NULL"), (sbstrVal2 ? sbstrVal2 : L"NULL"),
			nActual1, nExpected);
	}

	return;
}
Ejemplo n.º 4
0
StrUni ConvertException(DWORD dwExcept)
{
	StrUni stuResult;
	OLECHAR * pszSimple = ConvertSimpleException(dwExcept);

	if (NULL != pszSimple)
	{
		stuResult = pszSimple;
	}
	else
	{
		LPTSTR lpstrMsgBuf;
		::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
			NULL,
			dwExcept,
			0, // smart search for useful languages
			reinterpret_cast<achar *>(&lpstrMsgBuf),
			0,
			NULL);
		stuResult = lpstrMsgBuf;
		int cch = stuResult.Length();
		if (cch > 1 && stuResult[cch - 2] == '\r')
			stuResult.Replace(cch - 2, cch, (OLECHAR *)NULL);

		// Free the buffer.
		::LocalFree( lpstrMsgBuf );
	}
	return stuResult;
}
Ejemplo n.º 5
0
/*----------------------------------------------------------------------------------------------
	Initialize the data from the given file, or create a new empty string.
----------------------------------------------------------------------------------------------*/
void WpDa::InitNew(StrAnsi staFileName)
{
	if (staFileName == "")
	{
		InitNewEmpty();
		return;
	}

	Vector<StrUni> vstu;
	ReadTextFromFile(staFileName, vstu);

	HVO * prghvoPara = NewObj HVO[vstu.Size()];
	for (int istu = 0; istu < vstu.Size(); istu++)
		prghvoPara[istu] = istu + 2;
	CacheVecProp(1, kflidStText_Paragraphs, prghvoPara, vstu.Size());
	ITsStrFactoryPtr qtsf;
	qtsf.CreateInstance(CLSID_TsStrFactory);
	int enc = 100; // replace by the right number when we figure out what it is

	for (istu = 0; istu < vstu.Size(); istu++)
	{
		StrUni stuPara = vstu[istu];
		ITsStringPtr qtss;
		CheckHr(qtsf->MakeStringRgch(stuPara.Chars(), stuPara.Length(), enc, &qtss));
		CacheStringProp(istu + 2, kflidStTxtPara_Contents, qtss);
	}

	ITsPropsBldrPtr qtpb;
	qtpb.CreateInstance(CLSID_TsPropsBldr);
	StrUni stuNormal = L"Normal";
	CheckHr(qtpb->SetStrPropValue(kspNamedStyle,stuNormal.Bstr()));

	delete[] prghvoPara;
}
Ejemplo n.º 6
0
void ViewTest1::TestFontName()
{
	// Trying to retrieve via get_ without a previous put_
	// Something to consider is if there can be a default font name in which case this
	// test would not apply
	SmartBstr sbstrName1;
	HRESULT hr = m_qxvoTest->get_FontName(&sbstrName1);
	TestHrFail(hr, "Function get_FontName failed when passed(by reference) a SmartBstr");
	if (sbstrName1 != NULL)
		Failure("get_FontName without initialization via put_ should have returned error");

	// Sending NULL pointers to functions
	// REVIEW LukeU This test is assuming that a font name of zero length is invalid
	hr = m_qxvoTest->put_FontName(NULL);
	if (!FAILED(hr))
		Failure("Call to function: put_FontName(NULL) should have returned error unless "
			"0 character font name is allowed");

	hr = m_qxvoTest->get_FontName(NULL);
	if (!FAILED(hr))
		Failure("Call to function: get_FontName(NULL) should have returned error on NULL "
			"pointer");

	// "put_ing" and "get_ing" and subsequent value comparison
	StrUni stuFontName = L"Garliz";
	hr = m_qxvoTest->put_FontName(stuFontName.Bstr());
	TestHrFail(hr, "Function put_FontName failed when passed(by value) a bstr");

	CheckHr(m_qxvoTest->get_FontName(&sbstrName1));
	if (wcscmp(stuFontName.Chars(), sbstrName1.Chars()))
		Failure("FontName returned wrong result");
}
Ejemplo n.º 7
0
/*----------------------------------------------------------------------------------------------
	Close the current editor, saving changes that were made. hwnd is the editor hwnd.
	@param fForce True if we want to force the editor closed without making any
		validity checks or saving any changes.
----------------------------------------------------------------------------------------------*/
void AfDeFeCliRef::EndEdit(bool fForce)
{
	if (!fForce)
	{
		if (!m_pss)
		{
			// The user added a new item.
			ITsStringPtr qtss;
			int cch;
			StrUni stu; // Name/Abbr string entered by user.
			OLECHAR * pchBuf;

			// Get the characters from the edit box.
			::SendMessage(m_hwnd, FW_EM_GETTEXT, 0, (LPARAM)&qtss);
			qtss->get_Length(&cch);
			stu.SetSize(cch, &pchBuf);
			qtss->FetchChars(0, cch, pchBuf);

			if (cch)
			{
				// If a non-null string is present, create a new item.
				m_fSaving = true; // Disable updates while adding a new item.
				// The user created a new item, so add it to the possibility list.
				m_pss = CreatePss(m_hvoPssl, stu.Chars(), m_pnt, m_fHier);
				Assert(m_pss); // What should we do if we have an error?
				m_fSaving = false;
			}
		}
	}
	// When we close the edit window, the squiggley will automatically be removed.
	SuperClass::EndEdit(fForce);
}
Ejemplo n.º 8
0
/*----------------------------------------------------------------------------------------------
	Load the data from the given file into an empty window.
----------------------------------------------------------------------------------------------*/
void WpDa::LoadIntoEmpty(StrAnsi staFileName, WpChildWnd * pwcw)
{
	Assert(staFileName != "");
	int ctss;
	CheckHr(get_VecSize(1, kflidStText_Paragraphs, &ctss));
	Assert(ctss <= 1);

	Vector<StrUni> vstu;
	ReadTextFromFile(staFileName, vstu);

	HVO * prghvoPara = NewObj HVO[vstu.Size()];
	for (int istu = 0; istu < vstu.Size(); istu++)
		prghvoPara[istu] = istu + 2;
	CacheVecProp(1, kflidStText_Paragraphs, prghvoPara, vstu.Size());
	ITsStrFactoryPtr qtsf;
	qtsf.CreateInstance(CLSID_TsStrFactory);
	int enc = 100; // replace by the right number when we figure out what it is

	for (istu = 0; istu < vstu.Size(); istu++)
	{
		StrUni stuPara = vstu[istu];
		ITsStringPtr qtss;
		CheckHr(qtsf->MakeStringRgch(stuPara.Chars(), stuPara.Length(), enc, &qtss));
		CacheStringProp(istu + 2, kflidStTxtPara_Contents, qtss);
	}

	ITsPropsBldrPtr qtpb;
	qtpb.CreateInstance(CLSID_TsPropsBldr);
	StrUni stuNormal = L"Normal";
	CheckHr(qtpb->SetStrPropValue(kspNamedStyle, stuNormal.Bstr()));

	delete[] prghvoPara;

	pwcw->ChangeNumberOfStrings(vstu.Size());
}
Ejemplo n.º 9
0
/*----------------------------------------------------------------------------------------------

	This method works like TrackPopupMenu (supplying m_hwnd as the menu argument, and the
	required nulls for the last two arguments), except that if we are in what's this help mode,
	it instead tries to find the 'what's this' help for the selected item and displays it.  If
	it does this, it also calls ToggleHelpMode when done.  For it to work, the cid must identify
	a string containing multi-part names from which the krstWhatsThisEnabled option can be
	retrieved.

	@param hMenu handle to shortcut menu
	@param uFlags options
	@param x horizontal position
	@param y vertical position
	@param wsUser user interface writing system id.
	@param ptpm contains the area not to overlap (defaults to NULL)
----------------------------------------------------------------------------------------------*/
BOOL AfWnd::TrackPopupWithHelp(HMENU hMenu, UINT uFlags, int x, int y, int wsUser,
	TPMPARAMS * ptpm)
{
	if (AfMainWnd::InHelpMode())
	{
		// Trackit without notifing the parent and get the command id.
		bool fReturnCmd = uFlags & TPM_RETURNCMD;
		uFlags |= TPM_NONOTIFY | TPM_RETURNCMD;
		// Do this BEFORE we show the menu, so it shows normally.
		AfMainWnd::ToggleHelpMode();
		// This is dirty trick played by Windows that works because BOOL is really a short.
		BOOL cid = ::TrackPopupMenuEx(hMenu, uFlags, x, y, m_hwnd, ptpm);
		StrApp staMsg;
		AfUtil::GetResourceStr(krstWhatsThisEnabled, cid, staMsg);
		StrUni stuMsg = staMsg;
		ITsStrFactoryPtr qtsf;
		qtsf.CreateInstance(CLSID_TsStrFactory);
		ITsStringPtr qtssMsg;
		qtsf->MakeStringRgch(stuMsg.Chars(), stuMsg.Length(), wsUser, &qtssMsg);
		AfContextHelpWndPtr qchw;
		qchw.Attach(NewObj AfContextHelpWnd);
		Point pt (x, y);
		qchw->Create(m_hwnd, qtssMsg, pt);
		if (fReturnCmd)
			return cid;
		else
			return cid ? TRUE : 0;
	}
	else
	{
		return ::TrackPopupMenuEx(hMenu, uFlags, x, y, m_hwnd, ptpm);
	}
}
Ejemplo n.º 10
0
	// Create a backup file, returning false if unable to do so (probably because the
	// original file doesn't exist).
	bool CreateBackupFile(const wchar * pszFile)
	{
		StrUni stuBackup;
		stuBackup.Format(L"%s-testorig", pszFile);
		// If the backup is already there from a previous failed test,
		// we want to overwrite it.
		return ::CopyFileW(pszFile, stuBackup.Chars(), true);
	}
Ejemplo n.º 11
0
/*----------------------------------------------------------------------------------------------
	Construct the view constructor. Pass the RecordSpec of the view it is for, which allows it
	to find its block specs.
	ENHANCE JohnT: This is a rather low level object to know about the application and its list
	of views. Should we just pass in the list of block specs?
----------------------------------------------------------------------------------------------*/
CleCustDocVc::CleCustDocVc(UserViewSpec * puvs, AfLpInfo * plpi, CleMainWnd * pcmw)
	: VwCustDocVc(puvs, plpi, 0, kflidCmPossibilityList_Possibilities)
{
	ITsStrFactoryPtr qtsf;
	qtsf.CreateInstance(CLSID_TsStrFactory);
	StrUni stu;

	stu.Load(kstidSpaces0);
	CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), m_qlpi->GetDbInfo()->UserWs(),
		&m_qtssMissing));

	ITsPropsBldrPtr qtpb;
	qtpb.CreateInstance(CLSID_TsPropsBldr);
	// Border thickness below about 1/96 inch, a single pixel on a typical display.
	CheckHr(qtpb->SetIntPropValues(ktptBorderTop, ktpvMilliPoint, kdzmpInch / 96));
	// About a line (say 12 point) of white space above and below the border.
	CheckHr(qtpb->SetIntPropValues(ktptPadTop, ktpvMilliPoint, 12000));
	CheckHr(qtpb->SetIntPropValues(ktptMarginTop, ktpvMilliPoint, 12000));
	CheckHr(qtpb->GetTextProps(&m_qttpMain));

	CheckHr(qtpb->SetIntPropValues(ktptBorderBottom, ktpvMilliPoint, kdzmpInch / 96));
	CheckHr(qtpb->SetIntPropValues(ktptPadBottom, ktpvMilliPoint, 12000));
	CheckHr(qtpb->GetTextProps(&m_qttpMainLast));

	qtpb.CreateInstance(CLSID_TsPropsBldr);
	CheckHr(qtpb->SetIntPropValues(ktptMarginTop, ktpvMilliPoint, 12000));
	CheckHr(qtpb->GetTextProps(&m_qttpMainFirst));

	qtpb.CreateInstance(CLSID_TsPropsBldr);
	// Border thickness below about 1/96 inch, a single pixel on a typical display.
	CheckHr(qtpb->SetIntPropValues(ktptBorderBottom, ktpvMilliPoint, kdzmpInch / 96));
	CheckHr(qtpb->SetIntPropValues(ktptPadBottom, ktpvMilliPoint, 12000));
	CheckHr(qtpb->SetIntPropValues(ktptMarginBottom, ktpvMilliPoint, 12000));
	CheckHr(qtpb->GetTextProps(&m_qttpMainFlat));

	// And make the one for subentries.
	qtpb.CreateInstance(CLSID_TsPropsBldr);
	CheckHr(qtpb->SetIntPropValues(ktptPadTop, ktpvMilliPoint, 12000));
	CheckHr(qtpb->SetIntPropValues(ktptBorderTop, ktpvMilliPoint, 0));
	CheckHr(qtpb->SetIntPropValues(ktptMarginBottom, ktpvMilliPoint, 0));
	// The value below is sort of a default for one level of indentation; it will be
	// adjusted for lower levels.
	CheckHr(qtpb->SetIntPropValues(ktptPadLeading, ktpvMilliPoint, kdzmpInch * 3 / 10));
	CheckHr(qtpb->GetTextProps(&m_qttpSub));

	CheckHr(qtpb->SetIntPropValues(ktptBorderBottom, ktpvMilliPoint, kdzmpInch / 96));
	CheckHr(qtpb->SetIntPropValues(ktptPadBottom, ktpvMilliPoint, 12000));
	CheckHr(qtpb->GetTextProps(&m_qttpSubLast));

	m_qRecVc.Attach(NewObj CleRecVc);
	m_qcmw.Attach(pcmw);
	AddRefObj(pcmw);
	PossListInfoPtr qpli;
	m_qlpi->LoadPossList(pcmw->GetHvoPssl(), pcmw->AnalysisEnc(), &qpli);
	m_hvoPssl = qpli->GetPsslId();
}
Ejemplo n.º 12
0
/*----------------------------------------------------------------------------------------------
	This method opens the given file according to the given mode settings.
	NOTE: This now creates a file if it doesn't already exist, but opens it if it does exist,
		  if STGM_READWRITE alone is set.
		@param pszFile Name (or path) of the desired file
		@param grfstgm Combination of flags kfstgmXxxx from enum in FileStrm.h
----------------------------------------------------------------------------------------------*/
void FileStream::Init(LPCOLESTR pszFile, int grfstgm)
{
	// To access another file this stream should be closed and another created.
	AssertPsz(pszFile);
	Assert(*pszFile);
	Assert(!m_hfile);

	HANDLE hfile = 0;
	DWORD dwDesiredAccess = 0;
	DWORD dwShareMode;
	DWORD dwCreationDisposition = 0;

	// Set the dwShareMode parameter.
	if (grfstgm & kfstgmShareDenyNone)
		dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
	else if (grfstgm & kfstgmShareDenyRead)
		dwShareMode = FILE_SHARE_WRITE;
	else if (grfstgm & kfstgmShareExclusive)
		dwShareMode = 0;
	else
		dwShareMode = FILE_SHARE_READ;

	if (grfstgm & kfstgmReadWrite)
		dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
	else if (grfstgm & kfstgmWrite)
		dwDesiredAccess = GENERIC_WRITE;
	else
		dwDesiredAccess = GENERIC_READ;

	if (dwDesiredAccess & GENERIC_WRITE)
	{
		if (grfstgm & kfstgmCreate)
			dwCreationDisposition = CREATE_ALWAYS;
		else if (grfstgm & kfstgmReadWrite)
			dwCreationDisposition = OPEN_ALWAYS;	// Allows writing to existing file.
		else
			dwCreationDisposition = CREATE_NEW;
	}
	else
		dwCreationDisposition = OPEN_EXISTING;
	hfile = ::CreateFileW(pszFile, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition,
		FILE_ATTRIBUTE_NORMAL, NULL);
	if (hfile == INVALID_HANDLE_VALUE)
	{
		HRESULT hr = (HRESULT)::GetLastError();
		int stid = ErrorStringId(hr);
		StrUni stuRes(stid);
		StrUni stuMsg;
		stuMsg.Format(L"%s%n%s", stuRes.Chars(), pszFile);
		ThrowHr(hr, stuMsg.Chars());	// Caller should handle. (This is not a COM method).
	}

	m_hfile = hfile;
	m_staPath = pszFile;
	m_grfstgm = grfstgm;  // Store the access mode for the stat method.
}
Ejemplo n.º 13
0
/*----------------------------------------------------------------------------------------------
	Get a path name for the help file for this module.
	By convention this is the path of the DLL changed to .chm.
----------------------------------------------------------------------------------------------*/
StrUni GetModuleHelpFilePath()
{
	StrUni stuHelpPath = ModuleEntry::GetModulePathName();
	int cch = stuHelpPath.Length();
	int ichStartRep = cch; // Add to end if no dot.
	if (cch >= 3 && stuHelpPath[cch - 4] == '.')
		ichStartRep = cch - 3;
	stuHelpPath.Replace(ichStartRep, cch, L"chm");
	return stuHelpPath;
}
Ejemplo n.º 14
0
/*----------------------------------------------------------------------------------------------
	Convert the Graphite character offset to the decomposed NFD
	character offset used internally by views code.
----------------------------------------------------------------------------------------------*/
int FwGrTxtSrc::GrToVwOffset(int grOffset)
{
	if (!m_useNFC)
	{
		// the Graphite offset is a NFD offset
		return grOffset;
	}
	else
	{
		// convert NFC offsets to internal NFD offsets
		if (grOffset == 0)
			return 0;

		HRESULT hr;
		int cch;
		IgnoreHr(hr = m_qts->get_Length(&cch));
		if (FAILED(hr))
			throw;

		if (grOffset > cch)
			// grOffset points beyond the available text, i.e. is invalid.
			return cch + 10; // arbitrary number that is bigger than NFD text

		StrUni stuNfd;
		wchar_t* pchNfd;
		stuNfd.SetSize(cch + 1, &pchNfd);
		IgnoreHr(hr = m_qts->Fetch(0, cch, pchNfd));
		if (FAILED(hr))
			throw;
		pchNfd[cch] = '\0';

		wchar_t szOut[kNFDBufferSize];
		UCharIterator iter;
		uiter_setString(&iter, pchNfd, -1);
		int curGrOffset = 0;
		while (iter.hasNext(&iter))
		{
			int index = iter.getIndex(&iter, UITER_CURRENT);
			if (curGrOffset >= grOffset)
				return index;
			UBool neededToNormalize;
			UErrorCode uerr = U_ZERO_ERROR;
			int outLen = unorm_next(&iter, szOut, kNFDBufferSize, UNORM_NFC, 0, TRUE, &neededToNormalize, &uerr);
			Assert(U_SUCCESS(uerr));
			curGrOffset++;
			for (int i = 1; i < outLen; i++)
			{
				if (curGrOffset >= grOffset)
					return index + i;
				curGrOffset++;
			}
		}
		return iter.getIndex(&iter, UITER_CURRENT);
	}
}
Ejemplo n.º 15
0
/*----------------------------------------------------------------------------------------------
	Process notifications from the user.
----------------------------------------------------------------------------------------------*/
bool FmtGenDlg::OnNotifyChild(int ctidFrom, NMHDR * pnmh, long & lnRet)
{
	AssertPtr(pnmh);

	switch (pnmh->code)
	{
	case EN_KILLFOCUS: // Edit control modified.
		// Suppress updating the style from the control when we are trying to update the
		// control from the style.
		if (m_fSuppressLossOfFocus)
			break;

		if (ctidFrom == kctidFgEdName)
		{
			if (!m_pafsd->StyleIsSelected())
				return true;
			StyleInfo & styiSelected = m_pafsd->SelectedStyle();
			StrApp strOldName(styiSelected.m_stuName); // Save old name.
			StrApp strNewName;
			StrUni stuName;

			strNewName = GetName();

			// If the name has not changed, there is nothing to do.
			if (strNewName.Equals(strOldName))
				return true;

			stuName.Assign(strNewName);

			// If the style cannot be named stuName, put the old name back into the control.
			if (!m_pafsd->SetName(styiSelected, stuName))
			{
				::SetDlgItemText(m_hwnd, kctidFgEdName, strOldName.Chars());
				return true;
			}
			// Otherwise update the comboboxes for BasedOn and Next. Also update the edit box
			// to handle stripping of leading/trailing blanks.
			else
			{
				::SetDlgItemText(m_hwnd, kctidFgEdName, strNewName.Chars());
				UpdateComboboxes(strOldName, strNewName);
			}
		}
		return true;

	case CBN_SELCHANGE: // Combo box item changed.
		return OnComboChange(pnmh, lnRet);

	default:
		break;
	}

	return AfWnd::OnNotifyChild(ctidFrom, pnmh, lnRet);
}
Ejemplo n.º 16
0
STDMETHODIMP VwAccessRoot::get_accValue(VARIANT varID, BSTR * pszValue)
{
	BEGIN_COM_METHOD;
	ChkComOutPtr(pszValue);
	if (!m_pbox)
		return CO_E_OBJECTNOTCONNECTED;

	StrUni stuDesc = m_pbox->Description();
	stuDesc.GetBstr(pszValue);

	END_COM_METHOD(g_fact, IID_IAccessible);
}
Ejemplo n.º 17
0
int FwGrTxtSrc::VwToGrOffset(int vwOffset, bool& badOffset)
{
	badOffset = false;
	if (!m_useNFC)
	{
		// the NFD offset is a Graphite offset
		return vwOffset;
	}
	else
	{
		// convert internal NFD offsets to NFC offsets
		if (vwOffset == 0)
			return 0;

		HRESULT hr;
		int cch;
		IgnoreHr(hr = m_qts->get_Length(&cch));
		if (FAILED(hr))
			throw;
		if (vwOffset > cch)
			return vwOffset;

		StrUni stuNfd;
		wchar_t* pchNfd;
		stuNfd.SetSize(cch + 1, &pchNfd);
		IgnoreHr(hr = m_qts->Fetch(0, cch, pchNfd));
		if (FAILED(hr))
			throw;
		pchNfd[cch] = '\0';

		wchar_t szOut[kNFDBufferSize];
		UCharIterator iter;
		uiter_setString(&iter, pchNfd, -1);
		int curGrOffset = 0;
		while (iter.hasNext(&iter))
		{
			int index = iter.getIndex(&iter, UITER_CURRENT);
			UBool neededToNormalize;
			UErrorCode uerr = U_ZERO_ERROR;
			int outLen = unorm_next(&iter, szOut, kNFDBufferSize, UNORM_NFC, 0, TRUE, &neededToNormalize, &uerr);
			Assert(U_SUCCESS(uerr));
			for (int i = 0; i < outLen; i++)
			{
				if (index + i + 1 > vwOffset)
					return curGrOffset;
				curGrOffset++;
			}
			if (neededToNormalize && iter.getIndex(&iter, UITER_CURRENT) > vwOffset)
				badOffset = true;
		}
		return curGrOffset;
	}
}
Ejemplo n.º 18
0
/*----------------------------------------------------------------------------------------------
	Set up the crawler to work on a given database connection.

	@param stuServerName - name of the database server
	@param stuDatabase - name of the database
	@param pstrmLog - pointer to the log stream (may be NULL)
	@param padvi3 - pointer to the progress report object (defaults to NULL)
----------------------------------------------------------------------------------------------*/
bool DbStringCrawler::Init(IOleDbEncap * pode, IStream *pstrmLog, IAdvInd3 * padvi3)
{
	m_qodeDb = pode;
	SmartBstr sbstrServer;
	StrUni stuServer;
	CheckHr(pode->get_Server(&sbstrServer));
	stuServer.Assign(sbstrServer.Chars(), sbstrServer.Length());
	SmartBstr sbstrDatabase;
	StrUni stuDatabase;
	CheckHr(pode->get_Database(&sbstrDatabase));
	stuDatabase.Assign(sbstrDatabase.Chars(), sbstrDatabase.Length());
	return Init(stuServer, stuDatabase, pstrmLog, padvi3);
}
Ejemplo n.º 19
0
/*----------------------------------------------------------------------------------------------
	Refresh the field from the data cache.
----------------------------------------------------------------------------------------------*/
void AfDeFeCliRef::UpdateField()
{
	// Get the item info from the cache.
	CustViewDaPtr qcvd;
	GetDataAccess(&qcvd);
	AssertPtr(qcvd);
	HVO hvoPss;
	CheckHr(qcvd->get_ObjectProp(m_hvoObj, m_flid, &hvoPss));
	m_pss = hvoPss;

	// Get the string from the poss cache.
	ITsStringPtr qtss;
	ITsStrFactoryPtr qtsf;
	StrUni stu;
	PossListInfoPtr qpli;
	PossItemInfo * ppii;
	int ipss;

	qtsf.CreateInstance(CLSID_TsStrFactory);
	int ws = m_ws;
	if (m_pss)
	{
		GetLpInfo()->LoadPossList(m_hvoPssl, m_wsMagic, &qpli);
		AssertPtr(qpli);
		ipss = qpli->GetIndexFromId(m_pss);
		if (ipss >= 0)
		{
			ppii = qpli->GetPssFromIndex(ipss);
			AssertPtr(ppii);
			if (m_fHier)
				ppii->GetHierName(qpli, stu, m_pnt);
			else
				ppii->GetName(stu, m_pnt);
			ws = ppii->GetWs();
		}
	}
	qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss);
	m_qtss = qtss;

	// If we have an edit box, update the contents.
	if (m_hwnd)
	{
		// Setting the property causes a recursive call to OnChange, so we want to block it
		// from making a further change. (e.g., when you backspace to set the string to null
		// then tab to the next field, we want it to stay null, not go to the first item in
		// the list.)
		m_fRecurse = true;
		::SendMessage(m_hwnd, FW_EM_SETTEXT, 0, (LPARAM)m_qtss.Ptr());
	}
}
Ejemplo n.º 20
0
/*----------------------------------------------------------------------------------------------
	Initialize an empty document. It has a document object (always ID 1!) and one paragraph
	containing (implicitly) an empty string. Style is set to Normal
	Review SharonC(JohnT): what encoding should the empty string have??
----------------------------------------------------------------------------------------------*/
void WpDa::InitNewEmpty()
{
	HVO hvoPara = 2;
	CacheVecProp(1, kflidStText_Paragraphs, &hvoPara, 1);
	ITsStrFactoryPtr qtsf;
	qtsf.CreateInstance(CLSID_TsStrFactory);
	ITsStringPtr qtss;
	int enc = 100;
	CheckHr(qtsf->MakeStringRgch(L"", 0, enc, &qtss));
	CacheStringProp(hvoPara, kflidStTxtPara_Contents, qtss);
	ITsPropsBldrPtr qtpb;
	qtpb.CreateInstance(CLSID_TsPropsBldr);
	StrUni stuNormal = L"Normal";
	CheckHr(qtpb->SetStrPropValue(kspNamedStyle, stuNormal.Bstr()));
}
Ejemplo n.º 21
0
/*----------------------------------------------------------------------------------------------
	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
}
Ejemplo n.º 22
0
/*----------------------------------------------------------------------------------------------
	The Ok button in the list chooser has been hit. Process the results from the list chooser.
	@param pplc Pointer to the dialog box being closed.
	----------------------------------------------------------------------------------------------*/
void AfDeFeCliRef::ChooserApplied(PossChsrDlg * pplc)
{
	// Get the output values.
	StrUni stu;
	ITsStringPtr qtss;
	ITsStrFactoryPtr qtsf;
	HVO pssId;
	qtsf.CreateInstance(CLSID_TsStrFactory);
	pplc->GetDialogValues(pssId);
	m_pss = pssId;
	m_fRecurse = true;
	if (pssId)
	{
		PossListInfoPtr qpli;
		AfLpInfo * plpi = GetLpInfo();
		AssertPtr(plpi);
		plpi->LoadPossList(m_hvoPssl, m_wsMagic, &qpli);
		AssertPtr(qpli);
		int ipss = qpli->GetIndexFromId(pssId);
		PossItemInfo * ppii = qpli->GetPssFromIndex(ipss);
		if (m_fHier)
			ppii->GetHierName(qpli, stu, m_pnt);
		else
			ppii->GetName(stu, m_pnt);
		int ws = ppii->GetWs();
		qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss);
		m_qtss = qtss;
		::SendMessage(m_hwnd, FW_EM_SETTEXT, 0, (LPARAM)qtss.Ptr());
	}
	else
	{
		m_qtss = NULL;
		::SendMessage(m_hwnd, FW_EM_SETTEXT, 0, NULL);
	}
	// I (KenZ) don't fully understand this. But if a user enters the chooser, and opens a
	// list editor from there and adds a new item, closes the list editor, checks the new
	// item in the chooser, selects OK, then moves to the next record without moving from
	// the field, the added item is lost. We get ksyncPossList and ksyncAddPss sync messages
	// from the list editor, but for some reason we are getting an extra ksyncPossList
	// message after this method completes. That extra message is calling ListChanged which
	// calls UpdateField, which reloads our temporary cache from the main cache and wipes out
	// the change we just made. So until we can do something better, we'll save the changes
	// here to make sure the UpdateField doesn't wipe out our change.
	SaveEdit();
	::InvalidateRect(m_hwnd, NULL, true);
}
Ejemplo n.º 23
0
void MacroBase::WriteUni(StrUni param)
{
	if (!m_outfile.is_open())	return;
	// All unicode strings are first transformed into ansi strings and then written to file as
	// an ansi
	StrAnsi staAnsi = param.Chars();
	m_outfile << staAnsi.Chars() << "_" << " ";
}
Ejemplo n.º 24
0
/*----------------------------------------------------------------------------------------------
	This method checks for duplicates in list names.  If the given name exists then return true.

	@param pszName name to check to see if it exists.
	@return True if name already exists.
----------------------------------------------------------------------------------------------*/
bool ListsPropDlg::CheckName(const achar * pszName)
{
	AfMainWnd * pafw = MainWindow();
	AssertPtr(pafw);
	AfLpInfo * plpi = pafw->GetLpInfo();
	AssertPtr(plpi);
	Vector<HVO> & vhvo = plpi->GetPsslIds();

	AfDbInfoPtr qdbi = plpi->GetDbInfo();
	AssertPtr(qdbi);
	IOleDbEncapPtr qode;
	qdbi->GetDbAccess(&qode);

	StrAnsi sta;
	int i;
	StrUni stuIds;
	int cv = vhvo.Size();
	Assert(cv);

	ComBool fIsNull;
	ComBool fMoreRows;
	ULONG cbSpaceTaken;
	IOleDbCommandPtr qodc;

	const int kcchBuffer = MAX_PATH;
	OLECHAR rgchName[kcchBuffer];
	HVO hvo;
	StrUni stu;
	for (i = 0; i < cv; ++i)
	{
		hvo = vhvo[i];
		stu.Format(L"exec GetOrderedMultiTxt '%d', %d",
			hvo, kflidCmMajorObject_Name);
		CheckHr(qode->CreateCommand(&qodc));
		CheckHr(qodc->ExecCommand(stu.Bstr(), knSqlStmtStoredProcedure));
		CheckHr(qodc->GetRowset(0));
		CheckHr(qodc->NextRow(&fMoreRows));
		Assert(fMoreRows); // This proc should always return something.
		CheckHr(qodc->GetColValue(1, reinterpret_cast <BYTE *>(rgchName),
			kcchBuffer * isizeof(OLECHAR), &cbSpaceTaken, &fIsNull, 2));
		sta = rgchName;
		if (hvo != m_hvoObj && sta.Equals(pszName))
			return false;
	}
	return true;
}
Ejemplo n.º 25
0
/*----------------------------------------------------------------------------------------------
	Change all the occurrences of the old styles names to the new names, and delete any
	obsolete names.
----------------------------------------------------------------------------------------------*/
bool FwDbMergeStyles::ProcessFormatting(ComVector<ITsTextProps> & vqttp,
	StrUni stuDelete)
{
	bool fAnyChanged = false;
	for (int ittp = 0; ittp < vqttp.Size(); ittp++)
	{
		SmartBstr sbstr;
		HRESULT hr;
		CheckHr(hr = vqttp[ittp]->GetStrPropValue(ktptNamedStyle, &sbstr));
		if (hr == S_OK && sbstr.Length() > 0)
		{
			ITsPropsBldrPtr qtpb = NULL;
			StrUni stuOld(sbstr.Chars());
			StrUni stuNew;
			if (Delete(stuOld))
			{
				CheckHr(vqttp[ittp]->GetBldr(&qtpb));
				if (stuDelete.Length() == 0)
				{
					// If the style name to delete is empty, we want to pass null
					// so that the named style string property is removed.
					CheckHr(qtpb->SetStrPropValue(ktptNamedStyle, NULL));
				}
				else
					CheckHr(qtpb->SetStrPropValue(ktptNamedStyle, stuDelete.Bstr()));

			}
			else if (Rename(stuOld, stuNew))
			{
				CheckHr(vqttp[ittp]->GetBldr(&qtpb));
				CheckHr(qtpb->SetStrPropValue(ktptNamedStyle, stuNew.Bstr()));
			}

			if (qtpb)
			{
				ITsTextPropsPtr qttpNew;
				CheckHr(qtpb->GetTextProps(&qttpNew));
				vqttp[ittp] = qttpNew;
				fAnyChanged = true;
			}
		}
	}

	return fAnyChanged;
}
Ejemplo n.º 26
0
/*----------------------------------------------------------------------------------------------
	Insert material as appropriate to display the specified object.
	This method has not yet been tested...maybe not even compiled?
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwBaseVc::DisplayEmbeddedObject(IVwEnv * pvwenv, HVO hvo)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pvwenv);
	// See if it is a CmPicture.
	ISilDataAccessPtr qsda;
	CheckHr(pvwenv->get_DataAccess(&qsda));
	int clsid;
	CheckHr(qsda->get_IntProp(hvo, kflidCmObject_Class, &clsid));
	if (clsid != kclidCmPicture)
		return S_OK; // don't know how to deal with it.
	StrUni stuRootDir = DirectoryFinder::FwRootDataDir();
	HVO hvoFile;
	CheckHr(qsda->get_ObjectProp(hvo, kflidCmPicture_PictureFile, &hvoFile));
	if (hvoFile == 0)
		return S_OK;
	SmartBstr sbstrFileName;
	CheckHr(qsda->get_UnicodeProp(hvoFile, kflidCmFile_InternalPath, &sbstrFileName));
	if (sbstrFileName.Length() == 0)
		return S_OK;
	StrUni stuPath;
	stuPath.Format(L"%s,%s,%s", stuRootDir.Chars(), L"\\", sbstrFileName.Chars());
	IPicturePtr qpic;
	try
	{
		IStreamPtr qstrm;
		FileStream::Create(stuPath, STGM_READ, &qstrm);
		STATSTG stg;
		CheckHr(qstrm->Stat(&stg, STATFLAG_NONAME));
		LONG cbdata = (LONG)stg.cbSize.QuadPart;
		CheckHr(::OleLoadPicture(qstrm, cbdata, FALSE, IID_IPicture, (LPVOID *)&qpic));
		CheckHr(pvwenv->AddPicture(qpic, ktagNotAnAttr, 0, 0));
	}
	catch (...)
	{
		return S_OK; // if anything goes wrong (e.g., file not found), just give up for now.
		// Todo: insert a 'file XXX not found string.
	}
	// Todo: also add the caption.

	END_COM_METHOD(g_fact, IID_IVwViewConstructor);
}
Ejemplo n.º 27
0
/*----------------------------------------------------------------------------------------------
	Check to see if the edit box has valid data.  if so return true.  If not then put up a
	message to the user, then return false.
----------------------------------------------------------------------------------------------*/
bool CleDeFeString::BeginEdit(HWND hwnd, Rect & rc, int dxpCursor, bool fTopCursor)
{
	SuperClass::BeginEdit(hwnd, rc, dxpCursor, fTopCursor);

	CleMainWnd * pcmw = dynamic_cast<CleMainWnd *>(m_qadsc->MainWindow());
	Assert(pcmw);
	PossListInfoPtr qpli = pcmw->GetPossListInfoPtr();
	int ipss = qpli->GetIndexFromId(m_hvoObj);
	PossItemInfo * ppii = qpli->GetPssFromIndex(ipss);
	AssertPtr(ppii);

	// Save the primary string for comparison.
	AfLpInfo * plpi = pcmw->GetLpInfo();
	AssertPtr(plpi);
	CustViewDaPtr qcvd = pcmw->MainDa();
	AssertPtr(qcvd);
	CheckHr(qcvd->get_MultiStringAlt(m_hvoObj, m_flid, plpi->ActualWs(qpli->GetWs()), &m_qtssOld));

	switch(m_flid)
	{
		case kflidCmPossibility_Name:
		{
			StrUni stu;
			ppii->GetName(stu, kpntName);
			StrUni stuNewItem(kstidNewItem);
			if (stu.Left(stuNewItem.Length()) == stuNewItem)
				m_qrootb->MakeSimpleSel(true, true, true, true, NULL);
			break;
		}
		case kflidCmPossibility_Abbreviation:
		{
			StrUni stu;
			ppii->GetName(stu, kpntAbbreviation);
			StrUni stuNew(kstidNew);
			if (stu.Left(stuNew.Length()) == stuNew)
				m_qrootb->MakeSimpleSel(true, true, true, true, NULL);
			break;
		}
	}
	return true;
}
Ejemplo n.º 28
0
// Initialize the root resource bundle. The path may be null to use the standard
// FieldWorks ICU data directory.
STDMETHODIMP LgIcuResourceBundle::Init(BSTR bstrPath, BSTR bstrLocale)
{
	BEGIN_COM_METHOD
	ChkComBstrArgN(bstrPath);
	ChkComBstrArg(bstrLocale);
	StrUtil::InitIcuDataDir();
	StrUni stuDir;
	UnicodeString usDir;
	if (bstrPath)
		stuDir = bstrPath;
		// Otherwise let ICU figure out the right directory
	usDir = stuDir.Chars();

	UErrorCode uerr = U_ZERO_ERROR;
	StrAnsi staLocale(bstrLocale);
	ResourceBundle rbt(usDir, Locale(staLocale.Chars()), uerr);
	if (U_FAILURE(uerr))
		ThrowHr(E_FAIL);
	m_rb = rbt;
	END_COM_METHOD(g_factRb, IID_ILgIcuResourceBundle);
}
Ejemplo n.º 29
0
DEFINE_THIS_FILE

//:>********************************************************************************************
//:>	FwGrTxtSrc
//:>********************************************************************************************

size_t FwGrTxtSrc::fetch(toffset ichMin, size_t cch, gr::utf16 * prgchwBuffer)
{
	HRESULT hr;
	int cchLen;
	IgnoreHr(hr = (gr::GrResult)m_qts->get_Length(&cchLen));
	if (FAILED(hr))
		throw;

	if (!m_useNFC)
	{
		int cchGet = min(cch, cchLen - ichMin);
		IgnoreHr(hr = (gr::GrResult)m_qts->Fetch(ichMin, ichMin + cchGet, (OLECHAR*)prgchwBuffer));
		if (FAILED(hr))
			throw;
		return cchGet;
	}
	else
	{
		int vwIchMin = GrToVwOffset(ichMin);
		int len = cchLen - vwIchMin;
		wchar_t* pchNfd;
		StrUni stuText;
		stuText.SetSize(len + 1, &pchNfd);
		IgnoreHr(hr = (gr::GrResult)m_qts->Fetch(vwIchMin, vwIchMin + len, pchNfd));
		if (FAILED(hr))
			throw;
		pchNfd[len] = '\0';
		stuText.SetSize(len, &pchNfd);
		StrUtil::NormalizeStrUni(stuText, UNORM_NFC);
		int cchGet = min((int) cch, stuText.Length());
		wcsncpy((wchar_t*) prgchwBuffer, stuText.Chars(), cchGet);
		return cchGet;
	}
}
Ejemplo n.º 30
0
/*----------------------------------------------------------------------------------------------
	General purpose method to set up and store an error, rather than throw an exception
	in the normal way.
----------------------------------------------------------------------------------------------*/
HRESULT StackDumper::RecordError(REFGUID iid, StrUni stuDescr, StrUni stuSource,
	int hcidHelpId, StrUni stuHelpFile)
{
	// We are going to make a new error info object.
	ICreateErrorInfoPtr qcerrinfo;
	IErrorInfoPtr qerrinfo;
	HRESULT hr;

	// If we can't get a new error object, the only documented cause is E_OUTOFMEMORY.
	if (FAILED(hr = ::CreateErrorInfo(&qcerrinfo)))
	{
		return E_OUTOFMEMORY;
	}
	if (FAILED(hr = qcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID FAR*) &qerrinfo)))
	{
		return E_UNEXPECTED;
	}

	hr = qcerrinfo->SetDescription(const_cast<OLECHAR *>(stuDescr.Chars()));
	if (FAILED(hr))
		return hr;
	hr = qcerrinfo->SetGUID(iid);
	if (FAILED(hr))
		return hr;
	hr = qcerrinfo->SetSource(const_cast<OLECHAR *>(stuSource.Chars()));
	if (FAILED(hr))
		return hr;
	hr = qcerrinfo->SetHelpFile(const_cast<OLECHAR *>(stuHelpFile.Chars()));
	if (FAILED(hr))
		return hr;
	if (!hcidHelpId)
		hcidHelpId = khcidNoHelpAvailable;
	hr = qcerrinfo->SetHelpContext(hcidHelpId);
	if (FAILED(hr))
		return hr;

	::SetErrorInfo(0, qerrinfo);
	return hr;
}