📄 suggestdlg.cpp
字号:
/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomon and Yonat Sharon, and is */
/* bound by the MIT open source license. */
/* See License.txt or visit www.opensource.org/licenses/mit-license.html */
/***************************************************************************/
// SuggestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Spelly.h"
#include "SuggestDlg.h"
#include "spell.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSuggestDlg dialog
CSuggestDlg::CSuggestDlg(
const CString& inWord,
char** outSuggestions,
SIZE& inoutPosition,
CWnd* pParent)
: CDialog(CSuggestDlg::IDD, pParent),
m_Word(inWord), m_SugStrings(outSuggestions), m_Position(inoutPosition)
{
//{{AFX_DATA_INIT(CSuggestDlg)
//}}AFX_DATA_INIT
}
void CSuggestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSuggestDlg)
DDX_Control(pDX, IDC_WORD, m_DisplayedWord);
DDX_Control(pDX, IDC_SUGGESTIONS, m_Suggestions);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSuggestDlg, CDialog)
//{{AFX_MSG_MAP(CSuggestDlg)
ON_BN_CLICKED(IDIGNORE, OnIgnore)
ON_BN_CLICKED(IDIGNOREALL, OnIgnoreall)
ON_BN_CLICKED(IDLEARN, OnLearn)
ON_WM_DESTROY()
ON_BN_CLICKED(IDREPALL, OnReplaceAll)
ON_CBN_DBLCLK(IDC_SUGGESTIONS, OnDblclkSuggestions)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSuggestDlg message handlers
void CSuggestDlg::OnOK()
{
if (CheckReplacement())
CDialog::OnOK();
}
void CSuggestDlg::OnIgnore()
{
EndDialog(IDIGNORE);
}
BOOL CSuggestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// init the position of the dlg
GetWindowRect(&m_InitialRect);
MoveWindow(&(m_InitialRect+m_Position));
// show the misspelled word
m_DisplayedWord.SetText(m_Word);
m_DisplayedWord.SetFontBold(TRUE);
// insert all the suggestions to the combo box
int i;
for (i = 0; m_SugStrings[i][0] != '\0'; ++i)
m_Suggestions.AddString(m_SugStrings[i]);
if (i > 0)
m_Suggestions.SetCurSel(0);
else
m_Suggestions.SetWindowText(m_Word);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSuggestDlg::OnIgnoreall()
{
EndDialog(IDIGNOREALL);
}
void CSuggestDlg::OnLearn()
{
EndDialog(IDLEARN);
}
void CSuggestDlg::OnDestroy()
{
CDialog::OnDestroy();
// calculate new position
RECT rect;
GetWindowRect(&rect);
m_Position.cx = rect.left - m_InitialRect.left;
m_Position.cy = rect.top - m_InitialRect.top;
}
void CSuggestDlg::OnReplaceAll()
{
if (CheckReplacement())
EndDialog(IDREPALL);
}
bool CSuggestDlg::CheckReplacement()
{
m_Suggestions.GetDlgItem(1001)->GetWindowText(m_Replacement);
if (!spell_check(m_Replacement)) {
int ret = AfxMessageBox(
m_Replacement + " is not in the dictionary.\n"
"Would you like Spelly to learn it?", MB_YESNOCANCEL);
switch (ret) {
case IDYES:
spell_learn(m_Replacement);
break;
case IDNO:
// nothing to do
break;
case IDCANCEL:
// put new suggestions to the combo box
m_SugStrings = spell_suggest(m_Replacement);
for (int i = 0; m_SugStrings[i][0] != '\0'; ++i)
m_Suggestions.InsertString(i, m_SugStrings[i]);
___ ___ ___ return false;
} // end switch
} // end if misspelled
___ return true;
}
void CSuggestDlg::OnDblclkSuggestions()
{
m_Suggestions.GetDlgItem(1001)->GetWindowText(m_Replacement);
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -