コード例 #1
0
ファイル: TssEdit.cpp プロジェクト: FieldDB/FieldWorks
/*----------------------------------------------------------------------------------------------
	With no scroll bar, the only way this happens is when the user drags outside the window.
	We need to override because the superclass does nothing when there is no scroll bar.
----------------------------------------------------------------------------------------------*/
bool TssEdit::OnHScroll(int nSBCode, int nPos, HWND hwndSbar)
{
	// NB - DON'T use nPos; it has only a 16-bit range.
	int dxdPos = m_dxpScrollOffset; // Where the window thinks it is now.
	// ENHANCE JohnT: use actual resolution.
	int dxdLine = 30 * 96/72; // 30 points seems a useful size increment.

	switch (nSBCode)
	{
	case SB_LINELEFT:
		dxdPos -= dxdLine;
		break;
	case SB_LINERIGHT:
		dxdPos += dxdLine;
		break;
	default:
		dxdPos = 0;
		Assert(false); // others should not happen
		break;
	}
	// Try to stop it scrolling too far. This is unfortunately not easy to do. Try getting
	// the width of a selection of the whole thing and limit it to a bit more than that.
	IVwSelectionPtr qvwsel;
	CheckHr(m_qrootb->MakeSimpleSel(true, false, true, false, &qvwsel));
	HoldGraphics hg(this);
	Rect rdPrimary;
	Rect rdSecondary;
	ComBool fSplit;
	ComBool fEndBeforeAnchor;
	CheckHr(qvwsel->Location(hg.m_qvg, hg.m_rcSrcRoot, hg.m_rcDstRoot, &rdPrimary,
		&rdSecondary, &fSplit, &fEndBeforeAnchor));
	Rect rcClient;
	::GetClientRect(m_hwnd, &rcClient);
	int dxpMax = rdPrimary.Width() - rcClient.Width() + 20;
	if (dxdPos > dxpMax)
		dxdPos = dxpMax;

	// In this class we don't have to worry about a max.
	if (dxdPos < 0)
		dxdPos = 0;

	int dxdScrollBy = dxdPos - m_dxpScrollOffset;

	// Update the scroll position.
	m_dxpScrollOffset = dxdPos;

	ScrollBy(dxdScrollBy, 0);
	return true;
}
コード例 #2
0
ファイル: TssEdit.cpp プロジェクト: FieldDB/FieldWorks
/*----------------------------------------------------------------------------------------------
	Set pptss to the string being shown in the edit box. Return the length of the string.
	Message: FW_EM_GETTEXT.
----------------------------------------------------------------------------------------------*/
int TssEdit::GetText(ITsString ** pptss)
{
	AssertPtr(pptss);
	Assert(!*pptss);

	// Commit the selection so that we can access the data from the cache.
	IVwSelectionPtr qvwsel;
	ComBool fOk;
	CheckHr(m_qrootb->get_Selection(&qvwsel));
	if (qvwsel)
		CheckHr(qvwsel->Commit(&fOk));

	CheckHr(m_qcda->get_StringProp(khvoString, ktagString, pptss));
	int cch;
	CheckHr((*pptss)->get_Length(&cch));
	return cch;
}
コード例 #3
0
ファイル: TssEdit.cpp プロジェクト: FieldDB/FieldWorks
/*----------------------------------------------------------------------------------------------
	Trap a character so that we can call the OnUpdate and OnChange methods.
----------------------------------------------------------------------------------------------*/
void TssEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	SuperClass::OnChar(nChar, nRepCnt, nFlags);

	IVwSelectionPtr qvwsel;
	AssertPtr(m_qrootb);
	CheckHr(m_qrootb->get_Selection(&qvwsel));
	if (qvwsel)
	{
		ComBool fOk;
		CheckHr(qvwsel->Commit(&fOk));
	}

	OnUpdate();
	::UpdateWindow(m_hwnd);
	OnChange();
}
コード例 #4
0
ファイル: TssEdit.cpp プロジェクト: FieldDB/FieldWorks
/*----------------------------------------------------------------------------------------------
	Replace the current selection with the specified text.
	Message: FW_EM_REPLACESEL.
----------------------------------------------------------------------------------------------*/
void TssEdit::ReplaceSel(ITsString * ptss)
{
	AssertPtr(ptss);
	AssertPtr(m_qrootb);

	IVwSelectionPtr qvwsel;
	CheckHr(m_qrootb->get_Selection(&qvwsel));
	if (!qvwsel)
	{
		// If there's not a selection, try to create one at the beginning of the string!
		CheckHr(m_qrootb->MakeTextSelection(0, 0, NULL, ktagString, 0, 0, 0, 0, true, -1, NULL,
			true, &qvwsel));
		if (!qvwsel)
			return;
	}
	CheckHr(qvwsel->ReplaceWithTsString(ptss));

	// ReplaceWithTsString should handle this (JohnT, 8-22-01).
	//CheckHr(m_qcda->PropChanged(NULL, kpctNotifyAll, khvoString, ktagString, 0, 0, 0));
	OnUpdate();
	::UpdateWindow(m_hwnd);
	OnChange();
}
コード例 #5
0
ファイル: TssEdit.cpp プロジェクト: FieldDB/FieldWorks
/*----------------------------------------------------------------------------------------------
	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;
}
コード例 #6
0
ファイル: TssEdit.cpp プロジェクト: FieldDB/FieldWorks
/*----------------------------------------------------------------------------------------------
	Scroll to make the selection visible.
	In general, scroll the minimum distance to make it entirely visible.
	If the selection is higher than the window, scroll the minimum distance to make it
	fill the window.
	If the window is too small to show both primary and secondary, show primary.
	Note: subclasses for which scrolling is disabled should override.
	If psel is null, make the current selection visible.
----------------------------------------------------------------------------------------------*/
void TssEdit::MakeSelectionVisible1(IVwSelection * psel)
{
	//Assert(m_fVScrollEnabled);
	IVwSelectionPtr qvwsel;
	if (!m_qrootb)
	{
		return; // For paranoia.
	}
	if (psel)
		qvwsel = psel;
	else
	{
		CheckHr(m_qrootb->get_Selection(&qvwsel));
		if (!qvwsel)
		{
			return; // Nothing we can do.
		}
	}
	Rect rdPrimary;
	Rect rdSecondary;
	ComBool fSplit;
	ComBool fEndBeforeAnchor;
	Rect rcSrcRoot;
	Rect rcDstRoot;
	Rect rdIdeal;
	HoldGraphics hg(this);
	GetCoordRects(m_qvg, &rcSrcRoot, &rcDstRoot);
	CheckHr(qvwsel->Location(m_qvg, rcSrcRoot, rcDstRoot, &rdPrimary, &rdSecondary, &fSplit,
		&fEndBeforeAnchor));
	rdIdeal = rdPrimary;

	Rect rcClient;
	m_pwndSubclass->GetClientRect(rcClient);
	if (fSplit)
	{
		rdIdeal.Sum(rdSecondary);
		if (rdIdeal.Width() > rcClient.Width())
			rdIdeal = rdPrimary;
	}
	// OK, we want rdIdeal to be visible.

	// dx gets added to the scroll offset. This means a positive dx causes there to be more
	// of the view hidden left of the screen. This is the same effect as clicking a
	// right arrow, which paradoxically causes the window contents to move left.
	int dx = 0;
	int xdLeft = m_dxpScrollOffset; // Where the window thinks it is now.
	rdIdeal.Offset(xdLeft, 0); // Was in drawing coords, adjusted by left.
	int xdRight = xdLeft + rcClient.Width();

	// Is the selection partly off the left of the screen?
	if (rdIdeal.left < xdLeft)
	{
		// Is it bigger than the screen?
		if (rdIdeal.Width() > rcClient.Width() && !fEndBeforeAnchor)
		{
			// Left is off, and though it is too big to show entirely, we can show
			// more. Move the window contents right (negative dx).
			dx = rdIdeal.right - xdRight;
		}
		else
		{
			// Partly off left, and fits: move window contents right (less is hidden,
			// neg dx).
			dx = rdIdeal.left - xdLeft;
		}
	}
	else
	{
		// Left of selection is right of (or at) the left side of the screen.
		// Is right of selection right of the right side of the screen?
		if (rdIdeal.right > xdRight)
		{
			if (rdIdeal.Width() > rcClient.Width() && fEndBeforeAnchor)
			{
				// Left is visible, right isn't: move until lefts coincide to show as much
				// as possible. This is hiding more text left of the window: positive dx.
				dx = rdIdeal.left - xdLeft;
			}
			else
			{
				// Fits entirely: scroll left minimum to make right visible. This involves
				// hiding more text at the left: positive dx.
				dx = rdIdeal.right - xdRight;
			}
		}
		// Else it is already entirely visible, do nothing.
	}
	if (dx + m_dxpScrollOffset < 0)
		dx = -m_dxpScrollOffset; // make offset 0 if it would have been less than that
	if (dx)
	{
		// Update the actual position.
		m_dxpScrollOffset += dx;
	}
	ScrollBy(dx, 0);
}
コード例 #7
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::IsOkToClose(bool fWarn)
{
	CleMainWnd * pcmw = dynamic_cast<CleMainWnd *>(m_qadsc->MainWindow());
	Assert(pcmw);

	IVwSelectionPtr qvwsel;
	CheckHr(m_qrootb->get_Selection(&qvwsel));
	if (qvwsel)
	{
		ComBool fOk;
		CheckHr(qvwsel->Commit(&fOk));
	}

	PossListInfoPtr qpli = pcmw->GetPossListInfoPtr();
	int ipss = qpli->GetIndexFromId(m_hvoObj);
	StrUni stuNew;

	const OLECHAR * prgwch;
	int cch;
	ITsStringPtr qtss;
	CustViewDaPtr qcvd;

	GetDataAccess(&qcvd);
	AssertPtr(qcvd);
	int ws = m_qsvc->WritingSystems()[0];

	CheckHr(qcvd->get_MultiStringAlt(m_hvoObj, m_flid, ws, &qtss));
	Assert(qtss);
	qtss->LockText(&prgwch, &cch);
	qtss->UnlockText(prgwch);

	// Trim leading and trailing space characters.
	UnicodeString ust(prgwch, cch);
	ust.trim();
	stuNew.Assign(ust.getBuffer(), ust.length());

	//  Obtain pointer to IOleDbEncap interface.
	IOleDbEncapPtr qode;
	IOleDbCommandPtr qodc;
	StrUni stuSql;
	ComBool fIsNull;
	ComBool fMoreRows;
	AssertPtr(m_qadsc->MainWindow());
	AfLpInfo * plpi = m_qadsc->MainWindow()->GetLpInfo();
	AssertPtr(plpi);
	AfDbInfo * pdbi = plpi->GetDbInfo();
	AssertPtr(pdbi);
	pdbi->GetDbAccess(&qode);
	AssertPtr(qode);
	CheckHr(qode->CreateCommand(&qodc));
	int cpii = qpli->GetCount();

	if ((m_flid == kflidCmPossibility_Name) || (m_flid == kflidCmPossibility_Abbreviation))
	{
		// Make sure it does not have a ":" or a " - " in the string
		int ich = stuNew.FindStr(L":");
		StrUni stuTmp;
		bool fFixed = false;
		while (ich > 0)
		{
			stuNew.Replace(ich,ich + 1,"-");
			fFixed = true;
			ich = stuNew.FindStr(L":");
		}
		ich = stuNew.FindStr(L" - ");
		while (ich > 0)
		{
			stuNew.Replace(ich,ich + 3,"-");
			fFixed = true;
			ich = stuNew.FindStr(L" - ");
		}
		if (fFixed)
		{
			if (fWarn)
			{
				ITsStrFactoryPtr qtsf;
				qtsf.CreateInstance(CLSID_TsStrFactory);
				qtsf->MakeStringRgch(stuNew.Chars(), stuNew.Length(), pcmw->UserWs(), &qtss);
				CheckHr(qcvd->SetMultiStringAlt(m_hvoObj, m_flid, ws, qtss));
				CheckHr(qcvd->PropChanged(NULL, kpctNotifyAll, m_hvoObj, m_flid, 0, 1, 1));
				StrApp strMsg(kstidFixedStr);
				StrApp strTitle(kstidFixedStrTitle);
				::MessageBox(m_hwnd, strMsg.Chars(), strTitle.Chars(),
					MB_OK | MB_ICONINFORMATION);
			}
			return false;
		}
	}

	if (qpli->GetAllowDup())
		return true;

	ILgWritingSystemFactoryPtr qwsf;
	pdbi->GetLgWritingSystemFactory(&qwsf);
	AssertPtr(qwsf);
	switch (m_flid)
	{
		case kflidCmPossibility_Name:
		{
			for (int ipii = 0; ipii < cpii; ipii++)
			{
				if (ipii == ipss)
					continue;
				PossItemInfo * ppii = qpli->GetPssFromIndex(ipii);
				AssertPtr(ppii);
				StrUni stu;
				ppii->GetName(stu, kpntName);
				if (stu == stuNew)
				{
					stuSql.Format(L"select ws from CmPossibility_Name "
						L"where obj = %d and ws = %d",
						ppii->GetPssId(), ws);
					CheckHr(qode->CreateCommand(&qodc));
					CheckHr(qodc->ExecCommand(stuSql.Bstr(), knSqlStmtSelectWithOneRowset));
					CheckHr(qodc->GetRowset(0));
					CheckHr(qodc->NextRow(&fMoreRows));

					if (fMoreRows)
					{
						if (fWarn)
						{
							// this name already exists
							IWritingSystemPtr qws;
							CheckHr(qwsf->get_EngineOrNull(ws, &qws));
							AssertPtr(qws);
							SmartBstr sbstr;
							qws->get_Name(ws, &sbstr);

							StrUni stu(kstidDupItemName);
							StrUni stuMsg;
							stuMsg.Format(stu,sbstr.Chars());
							StrApp str(stuMsg);
							StrApp strTitle(kstidDupItemTitle);
							::MessageBox(m_hwnd, str.Chars(), strTitle.Chars(),
								MB_OK | MB_ICONINFORMATION);
						}
						return false;
					}
				}
			}
			break;
		}
		case kflidCmPossibility_Abbreviation:
		{
			for (int ipii = 0; ipii < cpii; ipii++)
			{
				if (ipii == ipss)
					continue;
				PossItemInfo * ppii = qpli->GetPssFromIndex(ipii);
				AssertPtr(ppii);
				StrUni stu;
				ppii->GetName(stu, kpntAbbreviation);
				if (stu == stuNew)
				{
					stuSql.Format(L"select ws from CmPossibility_Abbreviation "
						L"where obj = %d and ws = %d",
						ppii->GetPssId(), ws);
					CheckHr(qode->CreateCommand(&qodc));
					CheckHr(qodc->ExecCommand(stuSql.Bstr(), knSqlStmtSelectWithOneRowset));
					CheckHr(qodc->GetRowset(0));
					CheckHr(qodc->NextRow(&fMoreRows));

					if (fMoreRows)
					{
						if (fWarn)
						{
							// this abbreviation already exists
							IWritingSystemPtr qws;
							CheckHr(qwsf->get_EngineOrNull(ws, &qws));
							AssertPtr(qws);
							SmartBstr sbstr;
							qws->get_Name(ws, &sbstr);

							StrUni stu(kstidDupItemAbbr);
							StrUni stuMsg;
							stuMsg.Format(stu,sbstr.Chars());
							StrApp str(stuMsg);
							StrApp strTitle(kstidDupItemTitle);
							::MessageBox(m_hwnd, str.Chars(), strTitle.Chars(),
								MB_OK | MB_ICONINFORMATION);
						}
						return false;
					}
				}
			}
			break;
		}
	}
	return true;
}