示例#1
0
/*----------------------------------------------------------------------------------------------
	Set the values for the dialog controls based
----------------------------------------------------------------------------------------------*/
void TeStylesDlg::SetDialogValues()
{
	// Fill list combobox.
	StrApp staTemp;
	::SendMessage(m_hwndList, CB_RESETCONTENT, 0, 0);
	staTemp.Load(kstidTesdListBasic);
	::SendMessage(m_hwndList, CB_ADDSTRING, 0, (LPARAM)staTemp.Chars()); // 0
	staTemp.Load(kstidTesdListAll);
	::SendMessage(m_hwndList, CB_ADDSTRING, 0, (LPARAM)staTemp.Chars()); // 1
	staTemp.Load(kstidTesdListCustom);
	::SendMessage(m_hwndList, CB_ADDSTRING, 0, (LPARAM)staTemp.Chars()); // 2

	// Select the value in the combo box that represents the selected level.
	int nSelect;
	if (m_nCustomStyleLevel == 0)
		nSelect = ksttBasic;
	else if (m_nCustomStyleLevel > 10)
		nSelect = ksttAll;
	else
		nSelect = ksttCustom;

	::SendMessage(m_hwndList, CB_SETCURSEL, nSelect, 0);

	SuperClass::SetDialogValues();
}
示例#2
0
// Append to strDesc appropriate info about underline if any.
void AppendUnderlineInfo(StrApp & strDesc, COLORREF clrUnder, int unt, bool & fFirst)
{
	StrApp strColor;
	if (clrUnder != (COLORREF)knNinch)
		strColor.Load(g_ct.GetColorRid(g_ct.GetIndexFromColor(clrUnder)));
	StrApp strFmt;
	switch (unt)
	{
	case kuntDotted:
		strFmt.Load(kstidDottedUnderFmt);
		break;
	case kuntDashed:
		strFmt.Load(kstidDashedUnderFmt);
		break;
	case kuntStrikethrough:
		strFmt.Load(kstidStrikethroughUnderFmt);
		break;
	case kuntSingle:
		strFmt.Load(kstidSingleUnderFmt);
		break;
	case kuntDouble:
		strFmt.Load(kstidDoubleUnderFmt);
		break;
	default:
		return;
	}
	StrApp strT;
	strT.Format(strFmt.Chars(), strColor.Chars());
	AppendDescPart(strDesc, strT, fFirst);
}
示例#3
0
/*----------------------------------------------------------------------------------------------
	Add menu items for the right-click context Insert menu over tree pane.
----------------------------------------------------------------------------------------------*/
void CleDeSplitChild::AddContextInsertItems(HMENU & hmenu)
{
	StrApp str;

	CleMainWnd * pcmw = dynamic_cast<CleMainWnd *>(MainWindow());
	Assert(pcmw);

	PossListInfo * ppli = pcmw->GetPossListInfoPtr();
	AssertPtr(ppli);

	if (!ppli->GetIsSorted())
	{
		str.Assign(_T("List Item &Above"));
		::AppendMenu(hmenu, MF_STRING, kcidInsItemBef, str.Chars());
		str.Assign(_T("List Item &Below"));
		::AppendMenu(hmenu, MF_STRING, kcidInsItemAft, str.Chars());
	}
	else
	{
		str.Assign(_T("List &Item"));
		::AppendMenu(hmenu, MF_STRING, kcidInsItem, str.Chars());
	}
	if (ppli->GetDepth() != 1)
	{
		str.Assign(_T("List &Subitem"));
		::AppendMenu(hmenu, MF_STRING, kcidInsSubItem, str.Chars());
	}
}
示例#4
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;
}
示例#5
0
/*----------------------------------------------------------------------------------------------
	This method is called when the user presses Browse button.  It opens a dialog to browse for
	a help file, then if OK is pressed it puts that filename and path into the help edit box.
----------------------------------------------------------------------------------------------*/
void DetailsPropDlgTab::OnBrws()
{
	// Open file dialog.
	achar szFile[MAX_PATH];
	::ZeroMemory(szFile, MAX_PATH);
	OPENFILENAME ofn;
	::ZeroMemory(&ofn, sizeof(OPENFILENAME));
	// the constant below is required for compatibility with Windows 95/98 (and maybe NT4)
	ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
	ofn.Flags		= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
	ofn.hwndOwner	= m_hwnd;
	ofn.lpstrFilter	= _T("Compiled HTML Help Files (*.chm)\0*.chm\0");
	StrApp str(kstidOpenHelp);
	ofn.lpstrTitle	= str.Chars();

	StrApp strHelpPath = AfApp::Papp()->GetFwCodePath().Chars();
	strHelpPath.Append(_T("\\Helps\\"));

	ofn.lpstrInitialDir = strHelpPath.Chars();
	ofn.lpstrFile	= szFile;
	ofn.nMaxFile	= MAX_PATH;
	if (IDOK != ::GetOpenFileName(&ofn))
		return; // We do not save the results
	::SetWindowText(::GetDlgItem(m_hwnd, kctidDetailsPropTabHelpF), szFile);
	m_ppropd->SetHelpFile(szFile);
}
示例#6
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);
}
示例#7
0
/*----------------------------------------------------------------------------------------------
	Called by the framework to initialize the dialog. All one-time initialization should be
	done here (that is, all controls have been created and have valid hwnd's, but they
	need initial values.)

	See ${AfDialog#FWndProc}
	@param hwndCtrl (not used)
	@param lp (not used)

	@return true if Successful
----------------------------------------------------------------------------------------------*/
bool FwPropDlg::OnInitDlg(HWND hwndCtrl, LPARAM lp)
{
	StrApp str;
	str.Format(_T("%r %r"), AfApp::Papp()->GetAppPropNameId(), kstidPropProperties);
	::SendMessage(m_hwnd, WM_SETTEXT, 0, (LPARAM)str.Chars());

	m_pszHelpUrl = m_strHelpF.Chars();
	GeneralPropDlgTabPtr qgenp;
	qgenp.Attach(NewObj GeneralPropDlgTab(this, m_ctidName));
	qgenp->EnableLocation(true);
	qgenp->EnableSize(true);
	qgenp->EnableModified(true);
	qgenp->EnableDescription(true);
	AfDialogViewPtr qdlgv;
	qdlgv = qgenp;
	m_vqdlgv.Push(qdlgv);

	m_hwndTab = ::GetDlgItem(m_hwnd, kcidLangProjPropDlgTab);

	// WARNING: If this ever gets changed to anything but a fixed length buffer, make sure
	// ti.pszText is set after loading each string, since the memory pointed to by strb
	// could be different each time.
	StrAppBuf strb;
	TCITEM ti;
	ti.mask = TCIF_TEXT;
	ti.pszText = const_cast<achar *>(strb.Chars());

	// Add a tab to the tab control for each dialog view.
	strb.Load(kstidGeneralPropTab);
	TabCtrl_InsertItem(m_hwndTab, 0, &ti);

	// This section must be after at least one tab gets added to the tab control.
	RECT rcTab;
	::GetWindowRect(m_hwndTab, &rcTab);
	TabCtrl_AdjustRect(m_hwndTab, false, &rcTab);
	POINT pt = { rcTab.left, rcTab.top };
	::ScreenToClient(m_hwnd, &pt);
	m_dxsClient = pt.x;
	m_dysClient = pt.y;

	// Subclass the Help button.
	AfButtonPtr qbtn;
	qbtn.Create();
	qbtn->SubclassButton(m_hwnd, kctidHelp, kbtHelp, NULL, 0);

	ShowChildDlg(m_itabInitial);

	AfApp::Papp()->EnableMainWindows(false);

	::SetFocus(m_hwndTab);

	return SuperClass::OnInitDlg(hwndCtrl, lp);
}
示例#8
0
/*----------------------------------------------------------------------------------------------
	Selects the "basedOn" style of the specified style in the "basedOn" combobox
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::SetBasedOnStyleComboboxValue(StyleInfo & styi)
{
	StrApp strTemp; // Temporary string.
	bool fProtectedStyle = m_pafsd->IsStyleProtected(styi.m_stuName);

	// Select the "Based On" value from styi for the combobox.
	strTemp = m_pafsd->GetNameOfStyle(styi.m_hvoBasedOn);
	int icombobox = ::SendMessage(m_hwndBasedOn, CB_FINDSTRINGEXACT, 0,
		(LPARAM)strTemp.Chars());
	::SendMessage(m_hwndBasedOn, CB_SETCURSEL, icombobox, 0);
	// Disable the control for styles originally provided by FieldWorks.
	::EnableWindow(m_hwndBasedOn, !fProtectedStyle);
}
示例#9
0
/*----------------------------------------------------------------------------------------------
	The AfStylesDlg calls this when the user edits the name of a style.
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::SetName(StrApp & strNewName)
{
	StrApp strOldName;

	strOldName = GetName(); // Get the name from the editbox.

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

	::SetDlgItemText(m_hwnd, kctidFgEdName, strNewName.Chars());

	UpdateComboboxes(strOldName, strNewName); // Update the names in the comboboxes.
}
示例#10
0
/*----------------------------------------------------------------------------------------------
	Loads the "next" combobox for the specified style
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::LoadNextStyleCombobox(StyleInfo & styi)
{
	StrApp strTemp; // Temporary string.

	// "Next Style" combobox.
	::SendMessage(m_hwndNext, CB_RESETCONTENT, 0, 0);
	for (int istyi = 0; istyi < m_pafsd->m_vstyi.Size(); istyi++)
	{
		StyleInfo * pstyiTemp = &m_pafsd->m_vstyi[istyi];
		if (pstyiTemp->m_fDeleted)
			continue;
		strTemp = pstyiTemp->m_stuName;
		if (pstyiTemp->m_st == styi.m_st)
			::SendMessage(m_hwndNext, CB_ADDSTRING, 0, (LPARAM)strTemp.Chars());
	}
}
示例#11
0
void AppendOffsetInfo(StrApp & strDesc, int mpOffset, bool & fFirst)
{
	if (mpOffset && mpOffset != knNinch)
	{
		StrApp strFmt;
		if (mpOffset < 0)
			strFmt.Load(kstidLoweredFmt);
		else
			strFmt.Load(kstidRaisedFmt);
		StrApp strAmt;
		StrAppBuf strb;
		AfUtil::MakeMsrStr (abs(mpOffset) , knpt, &strb);
		StrApp strT;
		strT.Format(strFmt.Chars(), strb.Chars());
		AppendDescPart(strDesc, strT, fFirst);
	}
}
示例#12
0
/*----------------------------------------------------------------------------------------------
	Overrides the LoadNextStyleCombobox in the FmtGenDlg.cpp file so that we can limit the
	styles by context.
----------------------------------------------------------------------------------------------*/
void TeFmtGenDlg::LoadNextStyleCombobox(StyleInfo & styi)
{
	TeStylesDlg * ptesd = dynamic_cast<TeStylesDlg*>(m_pafsd);
	StrApp strTemp;

	// We have to refill the Next combo box to show only styles with compatible text styles.
	// "Next" styles are compatible if they have the same Context and a compatible Structure.
	::SendMessage(m_hwndNext, CB_RESETCONTENT, 0, 0);
	for (int istyi = 0; istyi < ptesd->m_vstyi.Size(); istyi++)
	{
		StyleInfo& styiTemp = ptesd->m_vstyi[istyi];
		if (styiTemp.m_fDeleted)
			continue;
		strTemp = styiTemp.m_stuName;
			if (CompatibleNextStyle(styi, styiTemp))
				::SendMessage(m_hwndNext, CB_ADDSTRING, 0, (LPARAM)strTemp.Chars());
	}
}
示例#13
0
/*----------------------------------------------------------------------------------------------
	Create a new TssEdit. ptss can be NULL if the control should start out empty.
----------------------------------------------------------------------------------------------*/
void TssEdit::Create(HWND hwndPar, int cid, DWORD dwStyle, HWND hwndToolTip, ITsString * ptss,
	ILgWritingSystemFactory * pwsf, int ws, IActionHandler * pacth)
{
	AssertPtr(pwsf);
	PreCreate(pwsf, ws, ptss, pacth);

	m_cid = cid;
	m_hwndToolTip = hwndToolTip;

	m_wsBase = ws;
	m_qwsf = pwsf;
	if (!m_wsBase)
		CheckHr(pwsf->get_UserWs(&m_wsBase));	// get the user interface writing system id.

	// Create the window.
	WndCreateStruct wcs;
	wcs.lpszClass = _T("AfVwWnd");
	wcs.hwndParent = hwndPar;
	wcs.SetWid(cid);
	wcs.style = dwStyle;
	CreateHwnd(wcs);

	// Add a tool tip.
	if (HasToolTip())
	{
		// Add the combo information to the tooltip.
		TOOLINFO ti = { isizeof(ti), TTF_IDISHWND };
#ifdef DEBUG
		static StrApp s_str;
		s_str.Format(_T("Missing a tooltip for edit control with ID %d"), m_cid);
		ti.lpszText = const_cast<achar *>(s_str.Chars());
#else // !DEBUG
		ti.lpszText = _T("Dummy text");
#endif // !DEBUG

		ti.hwnd = Hwnd();
		ti.uId = (uint)ti.hwnd;
		::GetClientRect(Hwnd(), &ti.rect);
		::SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
	}

	PostCreate(ptss);
}
示例#14
0
/*----------------------------------------------------------------------------------------------
	Selects the "next" style of the specified style in the "next" combobox
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::SetNextStyleComboboxValue(StyleInfo & styi)
{
	StrApp strTemp; // Temporary string.
	int icombobox;
	bool fProtectedStyle = m_pafsd->IsStyleProtected(styi.m_stuName);
	// Select the "Next Style" values from styi for the combobox.
	if (styi.m_st == kstCharacter)
	{
		icombobox = -1; // Makes it blank.
		::EnableWindow(m_hwndNext, false); // And disables it.
	}
	else
	{
		strTemp = m_pafsd->GetNameOfStyle(styi.m_hvoNext);
		icombobox = ::SendMessage(m_hwndNext, CB_FINDSTRINGEXACT, 0,
			(LPARAM)strTemp.Chars());
		// Disable the control for styles originally provided by FieldWorks.
		::EnableWindow(m_hwndNext, !fProtectedStyle);
	}
	::SendMessage(m_hwndNext, CB_SETCURSEL, icombobox, 0);
}
示例#15
0
/*----------------------------------------------------------------------------------------------
	Loads the "basedOn" combox for the specified style
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::LoadBasedOnStyleCombobox(StyleInfo & styi)
{
	StrApp strName = styi.m_stuName;
	StrApp strTemp; // Temporary string.
	// "Based On" combobox.
	::SendMessage(m_hwndBasedOn, CB_RESETCONTENT, 0, 0);
	for (int istyi = 0; istyi < m_pafsd->m_vstyi.Size(); istyi++)
	{
		StyleInfo * pstyiTemp = &m_pafsd->m_vstyi[istyi];
		if (pstyiTemp->m_fDeleted)
			continue;
		if ((pstyiTemp->m_nContext == knContextInternal ||
			pstyiTemp->m_nContext == knContextInternalMappable) && !styi.m_fBuiltIn)
			continue;
		strTemp = pstyiTemp->m_stuName;
		if (pstyiTemp->m_st == styi.m_st)
		{
			// The based-on list should not include any style that is already based on the
			// newly selected one, even indirectly.
			if (strName != strTemp && !m_pafsd->IsBasedOn(pstyiTemp, styi.m_hvoStyle))
				::SendMessage(m_hwndBasedOn, CB_ADDSTRING, 0, (LPARAM)strTemp.Chars());
		}
	}
}
示例#16
0
/*----------------------------------------------------------------------------------------------
	Replace strOldName with strNewName in the BasedOn and Next comboboxes.
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::UpdateComboboxes(StrApp & strOldName, StrApp & strNewName)
{
	if (!m_pafsd->StyleIsSelected())
		return;

	StyleInfo styiSelected = m_pafsd->SelectedStyle();
	StrApp strTemp;
	int icombobox;

	// Update the name in the BasedOn combobox if it is there.
	icombobox = ::SendMessage(m_hwndBasedOn, CB_FINDSTRINGEXACT, 0, (LPARAM)strOldName.Chars());
	if (CB_ERR != icombobox)
	{
		::SendMessage(m_hwndBasedOn, CB_DELETESTRING, icombobox, 0);
		::SendMessage(m_hwndBasedOn, CB_ADDSTRING, 0, (LPARAM)strNewName.Chars());
		// Select the BasedOn value.
		strTemp = m_pafsd->GetNameOfStyle(styiSelected.m_hvoBasedOn);
		icombobox = ::SendMessage(m_hwndBasedOn, CB_FINDSTRINGEXACT, 0,
			(LPARAM)strTemp.Chars());
		if (CB_ERR != icombobox)
			::SendMessage(m_hwndBasedOn, CB_SETCURSEL, icombobox, 0);
	}

	// Update the name in the Next combobox, but only for a paragraph style.
	if (kstParagraph == styiSelected.m_st)
	{
		icombobox = ::SendMessage(m_hwndNext, CB_FINDSTRINGEXACT, 0,
			(LPARAM)strOldName.Chars());
		if (CB_ERR != icombobox)
		{
			::SendMessage(m_hwndNext, CB_DELETESTRING, icombobox, 0);
			::SendMessage(m_hwndNext, CB_ADDSTRING, 0, (LPARAM)strNewName.Chars());
			// Select the "Next Style" value.
			strTemp = m_pafsd->GetNameOfStyle(styiSelected.m_hvoNext);
			icombobox = ::SendMessage(m_hwndNext, CB_FINDSTRINGEXACT, 0,
				(LPARAM)strTemp.Chars());
			if (CB_ERR != icombobox)
				::SendMessage(m_hwndNext, CB_SETCURSEL, icombobox, 0);
		}
	}
	return;
}
示例#17
0
/*----------------------------------------------------------------------------------------------
	Set up the crawler to work on a given database.

	@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(StrUni stuServerName, StrUni stuDatabase, IStream * pstrmLog,
	IAdvInd3 * padvi3)
{
	m_qstrmLog = pstrmLog;
	m_stuServerName = stuServerName;
	m_stuDatabase = stuDatabase;
	m_qadvi3 = padvi3;

	try
	{
		m_qode.CreateInstance(CLSID_OleDbEncap);
		// Get the IStream pointer for logging. NULL returned if no log file.
		StrUni stuMasterDb(L"master");
		CheckHr(m_qode->Init(m_stuServerName.Bstr(), stuMasterDb.Bstr(), m_qstrmLog,
			koltMsgBox, koltvForever));
		CreateCommand();
	}
	catch (...)
	{
		// Cannot connect to master database.
		StrApp strMsg;
		strMsg.Load(kstidCannotGetMasterDb);
		::MessageBox(NULL, strMsg.Chars(), m_strProgDlgTitle.Chars(), MB_OK | MB_ICONERROR);
		return false;
	}

	if (m_qadvi3)
		m_qadvi3->SetRange(0, 100);

#ifndef NO_AFMAINWINDOW
	if (!m_fDontCloseMainWnd)
	{
		m_fNeedRelaunch = true;
		// In closing the final window, FwTool is going to call
		// AfApp::DecExportedObjects() which would normally post a quit message to
		// the application if there is only one window open. We don't want it to
		// quit yet, so we need to temporarily add an extra count until we get our
		// new window open.
		AfApp::Papp()->IncExportedObjects();
		// Now close the current database with all its windows.
		AfApp::Papp()->CloseDbAndWindows(m_stuDatabase.Chars(), m_stuServerName.Chars(), false);

		// Give users time to log off, then force them off anyway:
		ComBool fDisconnected;
		try
		{
			IDisconnectDbPtr qdscdb;
			qdscdb.CreateInstance(CLSID_FwDisconnect);

			// Set up strings needed for disconnection:
			StrUni stuReason(kstidReasonDisconnectStrCrawl);
			// Get our own name:
			DWORD nBufSize = MAX_COMPUTERNAME_LENGTH + 1;
			achar rgchBuffer[MAX_COMPUTERNAME_LENGTH + 1];
			GetComputerName(rgchBuffer, &nBufSize);
			StrUni stuComputer(rgchBuffer);
			StrUni stuFmt(kstidRemoteReasonStrCrawl);
			StrUni stuExternal;
			stuExternal.Format(stuFmt.Chars(), stuComputer.Chars());

			qdscdb->Init(m_stuDatabase.Bstr(), stuServerName.Bstr(), stuReason.Bstr(),
				stuExternal.Bstr(), (ComBool)false, NULL, 0);
			qdscdb->DisconnectAll(&fDisconnected);
		}
		catch (...)
		{
			fDisconnected = false;
		}
		if (!fDisconnected)
		{
			// User canceled, or it was impossible to disconnect people. This will leave us in
			// possibly a funny state, and nothing will be changed, but at least we'll open up
			// a new window on the app.
			return false;
		}
	}
#endif
	return true;
}
示例#18
0
/*----------------------------------------------------------------------------------------------
	Handle a change in a combo box.
----------------------------------------------------------------------------------------------*/
bool FmtGenDlg::OnComboChange(NMHDR * pnmh, long & lnRet)
{
	AssertPtr(pnmh);

	// Do nothing if we're not handling a change in the based on style name combo.
	if (pnmh->idFrom != kctidFgCbBasedOn)
	{
		lnRet = 0;
		return true;
	}

	achar rgchaName[1024]; // Name in the combobox.
	Vector<achar> vch;
	achar * pszT;
	bool fKeepChange = true;

	// Get the name from the combobox.
	int index = ::SendMessage(m_hwndBasedOn, CB_GETCURSEL, 0, 0);
	int cch = ::SendMessage(m_hwndBasedOn, CB_GETLBTEXTLEN, index, (LPARAM)0);
	if (cch < 1024)
		pszT = rgchaName;
	else
	{
		vch.Resize(cch + 1);
		pszT = vch.Begin();
	}

	cch = ::SendMessage(m_hwndBasedOn, CB_GETLBTEXT, index, (long)pszT);
	if (cch < 0)
		pszT = _T("");

	// Trim leading and trailing space characters.
	StrApp strNewBasedOnName;
	StrUtil::TrimWhiteSpace(pszT, strNewBasedOnName);

	// Get the name of the style whose based on style is being changed.
	StrUni stuCurrStyleName(m_pafsd->GetNameOfSelectedStyle());

	// Get the HVO of the new based on style.
	StrUni stuName;
	stuName.Assign(strNewBasedOnName);
	HVO hvoNewBasedOn = m_pafsd->GetHvoOfStyleNamed(stuName);

	// Check that the selected style will not be based on itself.
	if (stuCurrStyleName.Equals(strNewBasedOnName))
		fKeepChange = false;
	else
	{
		int hvo = m_pafsd->GetBasedOnHvoOfStyle(hvoNewBasedOn);

		// Loop through the inheritance chain to make sure none of the based on
		// styles are the same as the currently selected style.
		while (hvo && fKeepChange)
		{
			if (stuCurrStyleName.Equals(m_pafsd->GetNameOfStyle(hvo)))
				fKeepChange = false;
			else
				hvo = m_pafsd->GetBasedOnHvoOfStyle(hvo);
		}
	}

	// If keeping the new based on style, then notify the styles dialog of its change.
	if (fKeepChange)
	{
		StyleInfo styi = m_pafsd->SelectedStyle();
		m_pafsd->SetBasedOn(styi, hvoNewBasedOn);
		m_pafsd->BasedOnStyleChangeNotification(hvoNewBasedOn);
		LoadNextStyleCombobox(styi);
		SetNextStyleComboboxValue(styi);
	}
	else
	{
		StrApp strMsg(kstidAfsdSameBasedOnMsg);
		StrApp strMsgTitle(kstidStyles);
		// Raise a message alerting the user to his mistake.
		::MessageBox(m_hwnd, strMsg.Chars(), strMsgTitle.Chars(), MB_OK | MB_ICONINFORMATION);

		// Return the combobox to its original value.
		strNewBasedOnName = m_pafsd->GetNameOfStyle(m_pafsd->SelectedStyle().m_hvoBasedOn);
		int index = ::SendMessage(m_hwndBasedOn, CB_FINDSTRINGEXACT, 0,
			(LPARAM)strNewBasedOnName.Chars());

		::SendMessage(m_hwndBasedOn, CB_SETCURSEL, index, 0);
	}

	lnRet = 0;
	return true;
} //:> FmtGenDlg::OnComboChange.
示例#19
0
/*----------------------------------------------------------------------------------------------
	Set the values for the dialog controls based on the style styi.
	@param vwsProj Union of the current Vernacular and Analysis encodings for the project.
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::SetDialogValues(StyleInfo & styi, Vector<int> & vwsProj)
{
	// During SetDialogValues we never need to handle loss of focus in the name control,
	// because if anything needed to be done about updating that, it was done during
	// GetDialogValues, which is always called before SetDialogValues. We need to suppress it
	// because during this call the current style index and the current value of the control
	// may not agree: the purpose of this method is to update the control from the new style.
	// The normal loss-of-focus code is trying to synchronize in the opposite direction, and
	// can cause problems, for example, when we are disabling the control. For example:
	//  - Disabling the window causes it to lose focus if it previously had focus.
	//  - There is a kill focus event that tries to make the contents of the box agree with
	//		the name of the current style.
	//	- when this method is called, the old style is still the current one, so if we
	//		already changed the text in the box, we wind up trying to rename the old style
	//		to the name of the 'provided' style and produce a name conflict error.

	try
	{
		m_vwsProj = vwsProj;

		StrApp strDesc;
		m_fSuppressLossOfFocus = true;
		StrApp strName = styi.m_stuName;
		StrApp strTemp; // Temporary string.
		bool fProtectedStyle = m_pafsd->IsStyleProtected(styi.m_stuName);

		// Name edit box.
		::SetDlgItemText(m_hwnd, kctidFgEdName, strName.Chars());
		// Diable the control for styles originally provided by FieldWorks.
		::EnableWindow(m_hwndName, !fProtectedStyle);

		// Style type ltext.
		switch (styi.m_st)
		{
		case kstParagraph:
			strTemp.Load(kstidParagraph);
			break;
		case kstCharacter:
			strTemp.Load(kstidCharacter);
			break;
		default:
			Assert(false); // Should not happen.
		}
		::SetWindowText(m_hwndType, strTemp.Chars());

		// Update the "next" and "basedOn" comboboxes
		LoadNextStyleCombobox(styi);
		SetNextStyleComboboxValue(styi);
		LoadBasedOnStyleCombobox(styi);
		SetBasedOnStyleComboboxValue(styi);

		// ENHANCE LarryW(JohnT): When shortcut is implemented initialize the value instead.
		::EnableWindow(m_hwndShortcut, false); // Disables it.

		// **************************************
		m_vesi.Clear();
		strDesc = m_pafsd->GetNameOfStyle(styi.m_hvoBasedOn);
		strDesc.Append(" + ");

		ITsTextProps * pttp = styi.m_qttp;
		if (pttp)
		{
			StrApp strT;
			StrAppBuf strb; // a temp, used for making strings with units

			// Add default font info
			bool fFirstPart = true;
			SmartBstr sbstr;
			CheckHr(pttp->GetStrPropValue(ktptFontFamily, &sbstr));
			StrUni stuFont(sbstr.Chars());
			AppendDescPart(strDesc, FwStyledText::FontStringMarkupToUi(false, stuFont), fFirstPart);
			int val, var;
			CheckHr(pttp->GetIntPropValues(ktptFontSize, &var, &val));
			if (var != -1)
			{
				AfUtil::MakeMsrStr (val , knpt, &strb);
				AppendDescPart(strDesc, strb, fFirstPart);
			}
			CheckHr(pttp->GetIntPropValues(ktptBold, &var, &val));
			if (val == kttvForceOn || val == kttvInvert)
				AppendDescPart(strDesc, kstidBold, fFirstPart);
			CheckHr(pttp->GetIntPropValues(ktptItalic, &var, &val));
			if (val == kttvForceOn || val == kttvInvert)
				AppendDescPart(strDesc, kstidItalic, fFirstPart);
			CheckHr(pttp->GetIntPropValues(ktptSuperscript, &var, &val));
			if (val == kssvSuper)
				AppendDescPart(strDesc, kstidFfdSuperscript, fFirstPart);
			else if (val == kssvSub)
				AppendDescPart(strDesc, kstidFfdSubscript, fFirstPart);

			AppendTextIs(strDesc, (COLORREF)ReadValOrNinch(pttp, ktptForeColor),
				(COLORREF)ReadValOrNinch(pttp, ktptBackColor), fFirstPart);

			AppendUnderlineInfo(strDesc, (COLORREF)ReadValOrNinch(pttp, ktptUnderColor),
				ReadValOrNinch(pttp, ktptUnderline), fFirstPart);

			AppendOffsetInfo(strDesc, ReadValOrNinch(pttp, ktptOffset), fFirstPart);

			// Add info about other tabs
			int nDir = ReadValOrNinch(pttp, ktptRightToLeft);
			AddIf(strDesc, nDir == 0, kstidLeftToRight, fFirstPart);
			AddIf(strDesc, nDir == 1, kstidRightToLeft, fFirstPart);

			static const Keyval rgkeyvals[] =
			{
				{ktalLeading, kstidFpAlignLead},
				{ktalLeft, kstidFpAlignLeft},
				{ktalCenter, kstidFpAlignCenter},
				{ktalRight, kstidFpAlignRight},
				{ktalTrailing, kstidFpAlignTrail},
				{ktalJustify, kstidFpAlignJustify}, //TODO: support when in use.
				{0, 0}
			};
			AddFromList(strDesc, ReadValOrNinch(pttp, ktptAlign), rgkeyvals, fFirstPart);

			int nLeadIndent = ReadValOrNinch(pttp, ktptLeadingIndent);
			int nTrailIndent = ReadValOrNinch(pttp, ktptTrailingIndent);
			int nFirstIndent = ReadValOrNinch(pttp, ktptFirstIndent);
			if (nLeadIndent != knNinch || nTrailIndent != knNinch || nFirstIndent != knNinch)
			{
				AppendDescPart(strDesc, kstidIndentColon, fFirstPart);
				AppendMeasurement(strDesc, nLeadIndent, m_nMsrSys, kstidLeadingFmt);
				if (nFirstIndent != knNinch)
				{
					if (nFirstIndent < 0)
						AppendMeasurement(strDesc, -nFirstIndent, m_nMsrSys, kstidHangingFmt);
					else
						AppendMeasurement(strDesc, nFirstIndent, m_nMsrSys, kstidFirstLineFmt);
				}
				AppendMeasurement(strDesc, nTrailIndent, m_nMsrSys, kstidTrailingFmt);
			}
			// line spacing
			CheckHr(pttp->GetIntPropValues(ktptLineHeight, &var, &val));
			StrApp strSpacing;
			StrApp strFmt;
			if (var == ktpvMilliPoint)
			{
				if (val < 0)
					strFmt.Load(kstidFpLsExactFmt);
				else
					strFmt.Load(kstidFpLsAtLeastFmt);
				StrAppBuf strb;
				AfUtil::MakeMsrStr (val , knpt, &strb);
				strSpacing.Format(strFmt.Chars(), strb.Chars());
			}
			else if (var == ktpvRelative)
			{
				if (val >= kdenTextPropRel * 2)
					strSpacing.Load(kstidFpLsDouble);
				else if (val >= kdenTextPropRel * 3 / 2)
					strSpacing.Load(kstidFpLs15Lines);
				else
					strSpacing.Load(kstidFpLsSingle);
			}
			if (strSpacing.Length() != 0)
			{
				strFmt.Load(kstidLineSpacingFmt);
				strT.Format(strFmt.Chars(), strSpacing.Chars());
				AppendDescPart(strDesc, strT, fFirstPart);
			}

			int mpBefore = ReadValOrNinch(pttp, ktptSpaceBefore);
			int mpAfter = ReadValOrNinch(pttp, ktptSpaceAfter);
			if (mpBefore != knNinch || mpAfter != knNinch)
			{
				AppendDescPart(strDesc, kstidSpace, fFirstPart);
				AppendMeasurement(strDesc, mpBefore, knpt, kstidBeforeFmt);
				AppendMeasurement(strDesc, mpAfter, knpt, kstidAfterFmt);
			}

			int bulnum = ReadValOrNinch(pttp, ktptBulNumScheme);
			AddIf(strDesc, bulnum >= kvbnBulletBase && bulnum < kvbnBulletMax,
				kstidBulleted, fFirstPart);
			AddIf(strDesc, bulnum >= kvbnNumberBase && bulnum < kvbnNumberMax,
				kstidNumbered, fFirstPart);

			int mpBTop = ReadValOrNinch(pttp, ktptBorderTop);
			int mpBB = ReadValOrNinch(pttp, ktptBorderBottom);
			int mpBL = ReadValOrNinch(pttp, ktptBorderLeading);
			int mpBTr = ReadValOrNinch(pttp, ktptBorderTrailing);

			if (mpBTop != knNinch || mpBB != knNinch || mpBL != knNinch || mpBTr != knNinch)
			{
				AppendDescPart(strDesc, kstidBorderColon, fFirstPart);
				int clrBorder = ReadValOrNinch(pttp, ktptBorderColor);
				bool fFirstBorder = true;
				if (clrBorder != knNinch)
				{
					StrApp strClr;
					strClr.Load(g_ct.GetColorRid(g_ct.GetIndexFromColor(clrBorder)));
					strDesc.Append(strClr.Chars());
					fFirstBorder = false;
				}
				AppendBorderInfo(strDesc, mpBTop, kstidTopBdrFmt, fFirstBorder);
				AppendBorderInfo(strDesc, mpBB, kstidBottomBdrFmt, fFirstBorder);
				AppendBorderInfo(strDesc, mpBL, kstidLeadingBdrFmt, fFirstBorder);
				AppendBorderInfo(strDesc, mpBTr, kstidTrailingBdrFmt, fFirstBorder);
			}


			// Add info about writing-system overrides of font info.
			Vector<int> vwsSoFar;


			// Get the appropropriate writing system factory.
			ILgWritingSystemFactoryPtr qwsf;
			AssertPtr(m_pafsd);
			m_pafsd->GetLgWritingSystemFactory(&qwsf);
			AssertPtr(qwsf);
		//-		IWritingSystemPtr qws;

			// Each iteration of this loop processes information about one writing system.
			SmartBstr sbstrCharStyles;
			CheckHr(pttp->GetStrPropValue(kspWsStyle, &sbstrCharStyles));
			if (sbstrCharStyles.Length())
			{
				FwStyledText::DecodeFontPropsString(sbstrCharStyles, m_vesi, vwsSoFar);

				SmartBstr sbstrWs;
				StrApp strWs;
				int wsUser;
				CheckHr(qwsf->get_UserWs(&wsUser));
				SmartBstr sbstrAbbr;
				for (int iesi = 0; iesi < m_vesi.Size(); iesi++)
				{
					WsStyleInfo & esi = m_vesi[iesi];
					if (vwsSoFar[iesi] == 0)
						continue;		// Ignore writing system set to 0.
					fFirstPart = true;
					StrApp strT;
					StrApp strT2;
					strT.Format(_T("\n"));
					// Use the abbreviation in the user ws if it exists.
					// else try for an abbreviation in each ws in m_vwsProj in turn,
					// else use the ICU locale name as a last resort.
					IWritingSystemPtr qws;
					CheckHr(qwsf->GetStrFromWs(vwsSoFar[iesi], &sbstrWs));
					CheckHr(qwsf->get_Engine(sbstrWs, &qws));
					CheckHr(qws->get_Abbr(wsUser, &sbstrAbbr));
					if (sbstrAbbr.Length() == 0)
					{
						for (int iws = 0; iws < m_vwsProj.Size(); ++iws)
						{
							CheckHr(qws->get_Abbr(m_vwsProj[iws], &sbstrAbbr));
							if (sbstrAbbr.Length() != 0)
								break;
						}
					}
					if (sbstrAbbr.Length() == 0)
						strWs.Assign(sbstrWs.Chars(), sbstrWs.Length());
					else
						strWs.Assign(sbstrAbbr.Chars(), sbstrAbbr.Length());
					strT2.Format(_T("%s: "), strWs.Chars());
					if (strT2 == _T("___: "))
						strT2.Load(kctidFgUnknown);
					strT.Append(strT2);
					strDesc.Append (strT);
					AppendDescPart(strDesc,
						FwStyledText::FontStringMarkupToUi(false, esi.m_stuFontFamily),
						fFirstPart);
					if (esi.m_mpSize != knNinch)
					{
						AfUtil::MakeMsrStr (esi.m_mpSize , knpt, &strb);
						AppendDescPart(strDesc, strb, fFirstPart);
					}
					if (esi.m_fBold == kttvForceOn || esi.m_fBold == kttvInvert)
						AppendDescPart(strDesc, kstidBold, fFirstPart);
					if (esi.m_fItalic == kttvForceOn || esi.m_fItalic == kttvInvert)
						AppendDescPart(strDesc, kstidItalic, fFirstPart);
					if (esi.m_ssv == kssvSuper)
						AppendDescPart(strDesc, kstidFfdSuperscript, fFirstPart);
					else if (esi.m_ssv == kssvSub)
						AppendDescPart(strDesc, kstidFfdSubscript, fFirstPart);
					AppendTextIs(strDesc, esi.m_clrFore, esi.m_clrBack, fFirstPart);

					AppendUnderlineInfo(strDesc, esi.m_clrUnder, esi.m_unt, fFirstPart);

					AppendOffsetInfo(strDesc, esi.m_mpOffset, fFirstPart);
				} // 'for' loop
			}
		}
		::SetDlgItemText(m_hwnd, kctidFgDescription, strDesc.Chars());
// **************************************
	}
	catch(...)
	{
		m_fSuppressLossOfFocus = false;
		throw;
	}
	m_fSuppressLossOfFocus = false;
} //:> FmtGenDlg::SetDialogValues.
示例#20
0
/*----------------------------------------------------------------------------------------------
	Get the final values for the dialog controls, after the dialog has been closed.
----------------------------------------------------------------------------------------------*/
void FmtGenDlg::GetDialogValues(StyleInfo & styi, bool & fBasedOnChanged)
{
	StrUni stuName = GetName();
	StrApp strName = stuName;
	achar rgcha[1024];
	Vector<achar> vch;
	achar * pszT;
	memcpy(rgcha, strName.Chars(), strName.Length() * isizeof(achar));
	if (stuName != styi.m_stuName)
	{
		StrApp strOldName(styi.m_stuName);
		StrApp strNewName(stuName);
		if (!m_pafsd->SetName(styi, stuName))
		{
			// Error: restore the old name.
			::SetDlgItemText(m_hwnd, kctidFgEdName, strOldName.Chars());
		}
		// Otherwise update the comboboxes for BasedOn and Next.
		// This allows the later code which reads from them to work correctly,
		// so it is worth doing even here in a read routine.
		// Also update the edit box to handle stripping of leading/trailing blanks.
		else
		{
			::SetDlgItemText(m_hwnd, kctidFgEdName, strNewName.Chars());
			UpdateComboboxes(strOldName, strNewName);
		}
	}

	int iitem = ::SendMessage(m_hwndBasedOn, CB_GETCURSEL, 0,0);
	// <0 means the item is blank (e.g., Normal is not based on anything).
	// But if we pass -1 to CB_GETLBTEXT, we get the text of the first item.
	// This can change Normal to be based on Normal, with bad consequences.
	//
	if (iitem < 0)
	{
		pszT = _T("");
	}
	else
	{
		int cch = ::SendMessage(m_hwndBasedOn, CB_GETLBTEXTLEN, (WPARAM)iitem, 0);
		if (cch < 1024)
		{
			pszT = rgcha;
		}
		else
		{
			vch.Resize(cch + 1);
			pszT = vch.Begin();
		}
		cch = ::SendMessage(m_hwndBasedOn, CB_GETLBTEXT, iitem, (long)pszT);
		if (cch < 0)
			pszT = _T("");
	}
	stuName = pszT;
	HVO hvoBasedOn = m_pafsd->GetHvoOfStyleNamed(stuName);
	if (styi.m_hvoBasedOn != hvoBasedOn)
	{
		m_pafsd->SetBasedOn(styi, hvoBasedOn); // Sets m_fDirty.

		// Note that this is initialised to false in AfStylesDlg::UpdateTabCtrl.
		fBasedOnChanged = true;
	}

	iitem = ::SendMessage(m_hwndNext, CB_GETCURSEL, 0,0);
	if (iitem < 0)
	{
		pszT = _T("");
	}
	else
	{
		int cch = ::SendMessage(m_hwndNext, CB_GETLBTEXTLEN, (WPARAM)iitem, 0);
		if (cch < 1024)
		{
			pszT = rgcha;
		}
		else
		{
			vch.Resize(cch + 1);
			pszT = vch.Begin();
		}
		cch = ::SendMessage(m_hwndNext, CB_GETLBTEXT, iitem, (long)pszT);
		if (cch < 0)
			pszT = _T("");
	}
	stuName = pszT;
	HVO hvoNext = m_pafsd->GetHvoOfStyleNamed(stuName);
	if ((styi.m_hvoNext != hvoNext) && (styi.m_st != kstCharacter))
	{
		m_pafsd->SetNext(styi, hvoNext); // Sets m_fDirty.
	}
} //:> FmtGenDlg::GetDialogValues.