📄 dhtmleditdemodlg.cpp
字号:
pi_Editor->Save();
break;
case IDC_BUTTON_LOAD:
mCtrl_EditUrl.GetWindowText(s_Text);
pi_Editor->Navigate(s_Text);
break;
case IDC_BUTTON_GOBACK:
pi_Editor->GoBack();
break;
case IDC_BUTTON_GOFORWARD:
pi_Editor->GoForward();
break;
case IDC_BUTTON_HELP:
pi_Editor->NavigateToEmbeddedResource(_T("Html_Help"));
break;
case IDC_CHECK_DESIGN:
case IDC_CHECK_SOURCE:
pi_Editor->SetDisplayMode(mCtrl_CheckSource.GetCheck(),
mCtrl_CheckDesign.GetCheck());
break;
// ################## Text formatting ##################
case IDC_BUTTON_FORECOLOR:
b_SelOK = pi_Editor->ExecSetCommand(IDM_FORECOLOR, _T("red"));
break;
case IDC_BUTTON_BACKCOLOR:
b_SelOK = pi_Editor->ExecSetCommand(IDM_BACKCOLOR, _T("#AAFFBB"));
break;
case IDC_BUTTON_REMOVEFORMAT:
b_SelOK = pi_Editor->ExecSetCommand(IDM_REMOVEFORMAT);
break;
case IDC_CHECK_BOLD:
b_SelOK = pi_Editor->ExecSetCommand(IDM_BOLD);
break;
case IDC_CHECK_ITALIC:
b_SelOK = pi_Editor->ExecSetCommand(IDM_ITALIC);
break;
case IDC_CHECK_UNDERLINE:
b_SelOK = pi_Editor->ExecSetCommand(IDM_UNDERLINE);
break;
case IDC_CHECK_LEFTALIGN:
b_SelOK = pi_Editor->ExecSetCommand(IDM_JUSTIFYLEFT);
break;
case IDC_CHECK_CENTERALIGN:
b_SelOK = pi_Editor->ExecSetCommand(IDM_JUSTIFYCENTER);
break;
case IDC_CHECK_RIGHTALIGN:
b_SelOK = pi_Editor->ExecSetCommand(IDM_JUSTIFYRIGHT);
break;
case IDC_CHECK_UNORDERLIST:
b_SelOK = pi_Editor->ExecSetCommand(IDM_UNORDERLIST);
break;
case IDC_CHECK_ORDERLIST:
b_SelOK = pi_Editor->ExecSetCommand(IDM_ORDERLIST);
break;
// ################## Table ##################
case IDC_BUTTON_TABLE:
// ---- comment out one of the following lines ! ----
b_SelOK = pi_Editor->GetDocument()->PasteIntoSelection(s_NewTable);
// b_SelOK = pi_Editor->GetDocument().InsertTable(2,2); // insert empty table 2 x 2 cells
break;
case IDC_BUTTON_TABLEPROP:
SetTableProperties();
break;
case IDC_BUTTON_ROW_ABOVE:
pi_Doc->InsertNewTableRow(FALSE);
break;
case IDC_BUTTON_ROW_BELOW:
pi_Doc->InsertNewTableRow(TRUE);
break;
case IDC_BUTTON_COL_LEFT:
pi_Doc->InsertNewTableColumn(FALSE);
break;
case IDC_BUTTON_COL_RIGHT:
pi_Doc->InsertNewTableColumn(TRUE);
break;
case IDC_BUTTON_DELETE_ROW:
i_Table.DeleteRow(i_Cell.GetRowIndex());
break;
case IDC_BUTTON_DELETE_COL:
i_Table.DeleteColumn(i_Cell.GetColIndex());
break;
case IDC_BUTTON_BGCOLOR_CELL:
i_Cell.SetBgColor(_T("#CC8855"));
break;
case IDC_BUTTON_COMBINE:
if (!i_Cell.Combine())
MessageBox(_T("You can only combine cells which have a right neighbour."), _T("Error"), MB_ICONSTOP);
break;
case IDC_BUTTON_SPLIT:
i_Cell.Split();
break;
// ############### other HTML stuff ##################
case IDC_BUTTON_BGCOLOR:
pi_Doc->GetBody(TRUE).SetAttribute(_T("bgcolor"), _T("#FFDDAA"));
break;
case IDC_BUTTON_HR:
b_SelOK = pi_Editor->ExecSetCommand(IDM_HORIZONTALLINE);
break;
case IDC_BUTTON_HRPROP:
SetHRproperties();
break;
case IDC_BUTTON_IMAGE:
b_SelOK = pi_Editor->ExecSetCommand(IDM_IMAGE);
break;
case IDC_BUTTON_LINK:
b_SelOK = pi_Editor->ExecSetCommand(IDM_HYPERLINK);
break;
case IDC_BUTTON_NOBR:
b_SelOK = pi_Doc->AddToSelection(_T("<Nobr>"), _T("</Nobr>"));
break;
}
if (!b_SelOK)
MessageBox(_T("The selection or cursor position is invalid for this function!"), _T("Error"), MB_ICONSTOP);
}
// This message is posted from cHtmlEditor::cMsieWnd
// Set the checkboxes according to the current selection / cursor position
// This function is called with every keypress of the user so it is speed optimized
void CDHtmlEditDemoDlg::OnUpdateUI(WPARAM wParam)
{
if (wParam == HTMLEDIT_INIT_DONE)
{
/*
Put any code here you want to execute after the HTML Editor is ready initialized
For example any code that loads content into the editor
*/
return;
}
// Called after every CleanUp (e.g. after Navigation)
if (wParam == HTMLEDIT_SETDEFAULT)
{
cHtmlDocument *pi_Doc = pi_Editor->GetDocument();
pi_Doc->SetDocumentDefault(_T("BODY"), cHtmlStyle::E_FontSize, _T("14"));
pi_Doc->SetDocumentDefault(_T("TABLE"), cHtmlStyle::E_FontSize, _T("14"));
pi_Doc->SetDocumentDefault(_T("BODY"), cHtmlStyle::E_FontFamily, _T("Arial"));
pi_Doc->SetDocumentDefault(_T("TABLE"), cHtmlStyle::E_FontFamily, _T("Arial"));
cHtmlElement i_Body = pi_Doc->GetBody(FALSE);
if (i_Body.Valid())
{
i_Body.SetAttribute(_T("topMargin"), _T("2"));
i_Body.SetAttribute(_T("leftMargin"), _T("3"));
}
return;
}
if (wParam == HTMLEDIT_KILLFOCUS)
{
/*
Put any code here you want to execute when the Html Editor loses focus
For example any code to automatically save user changes
*/
return;
}
// Display the new URL in Edit box after a navigation took place
// Replace Mime encoding ("%20" --> " ")
if (wParam == HTMLEDIT_NAVIGATED)
{
mCtrl_EditUrl.SetWindowText(cMisc::DecodeMime(pi_Editor->GetDocument()->GetUrl()));
return;
}
// illegal message
if (wParam != HTMLEDIT_UPDATE_UI)
return;
// ---------------- Enable / Disable -------------------
UINT u32_CurDisplay = pi_Editor->GetDisplayMode();
static UINT u32_LastDisplay = 0;
if (u32_LastDisplay != u32_CurDisplay) // do nothing if unchanged
{
u32_LastDisplay = u32_CurDisplay;
BOOL b_DesignMode = (u32_CurDisplay == IDM_EDITMODE);
BOOL b_BrowseMode = (u32_CurDisplay == IDM_BROWSEMODE);
BOOL b_SourceMode = (u32_CurDisplay == IDM_VIEWSOURCE);
mCtrl_CheckBold .EnableWindow(b_DesignMode);
mCtrl_CheckItalic .EnableWindow(b_DesignMode);
mCtrl_CheckUnderline .EnableWindow(b_DesignMode);
mCtrl_CheckLeftAlign .EnableWindow(b_DesignMode);
mCtrl_CheckCenterAlign.EnableWindow(b_DesignMode);
mCtrl_CheckRightAlign .EnableWindow(b_DesignMode);
mCtrl_CheckOrderList .EnableWindow(b_DesignMode);
mCtrl_CheckUnOrderList.EnableWindow(b_DesignMode);
mCtrl_ComboFontName .EnableWindow(b_DesignMode);
mCtrl_ComboFontSize .EnableWindow(b_DesignMode);
mCtrl_BgText .EnableWindow(b_DesignMode);
mCtrl_BgBody .EnableWindow(b_DesignMode);
mCtrl_BgCell .EnableWindow(b_DesignMode);
mCtrl_ColLeft .EnableWindow(b_DesignMode);
mCtrl_ColRight .EnableWindow(b_DesignMode);
mCtrl_Combine .EnableWindow(b_DesignMode);
mCtrl_DeleteCol .EnableWindow(b_DesignMode);
mCtrl_DeleteRow .EnableWindow(b_DesignMode);
mCtrl_ForeColor .EnableWindow(b_DesignMode);
mCtrl_Hr .EnableWindow(b_DesignMode);
mCtrl_HrProp .EnableWindow(b_DesignMode);
mCtrl_Image .EnableWindow(b_DesignMode);
mCtrl_Link .EnableWindow(b_DesignMode);
mCtrl_NoBr .EnableWindow(b_DesignMode);
mCtrl_RemoveFormat .EnableWindow(b_DesignMode);
mCtrl_RowAbove .EnableWindow(b_DesignMode);
mCtrl_RowBelow .EnableWindow(b_DesignMode);
mCtrl_Split .EnableWindow(b_DesignMode);
mCtrl_Table .EnableWindow(b_DesignMode);
mCtrl_TableProp .EnableWindow(b_DesignMode);
mCtrl_EditUrl .EnableWindow(b_BrowseMode);
mCtrl_Load .EnableWindow(b_BrowseMode);
mCtrl_GoBack .EnableWindow(b_BrowseMode);
mCtrl_GoForward .EnableWindow(b_BrowseMode);
mCtrl_StaticUrl .EnableWindow(b_BrowseMode);
mCtrl_Save .EnableWindow(!b_SourceMode);
mCtrl_Help .EnableWindow(!b_SourceMode);
mCtrl_Clear .EnableWindow(!b_SourceMode);
mCtrl_CheckDesign .EnableWindow(!b_SourceMode);
}
// ---------- Set dynamic checkboxes (buttons) ---------
// Arrays for all checkboxes, their state and their MSIE commands
static UINT u32_bCmd[] = { IDM_VIEWSOURCE, IDM_EDITMODE, IDM_BOLD, IDM_ITALIC, IDM_UNDERLINE, IDM_JUSTIFYLEFT, IDM_JUSTIFYCENTER, IDM_JUSTIFYRIGHT, IDM_ORDERLIST, IDM_UNORDERLIST };
static CButton *p_Check[] = { &mCtrl_CheckSource, &mCtrl_CheckDesign, &mCtrl_CheckBold, &mCtrl_CheckItalic, &mCtrl_CheckUnderline, &mCtrl_CheckLeftAlign, &mCtrl_CheckCenterAlign, &mCtrl_CheckRightAlign, &mCtrl_CheckOrderList, &mCtrl_CheckUnOrderList };
ASSERT(sizeof(u32_bCmd) == sizeof(mb_CheckStatus)); // illegal _CheckBoxCount
// Set the checkboxes according to the current selection / cursor position
for (UINT b=0; b<_CheckBoxCount; b++)
{
BOOL b_Active = (pi_Editor->QueryStatus(u32_bCmd[b]) & OLECMDF_LATCHED) > 0;
if (b_Active == mb_CheckStatus[b])
continue;
mb_CheckStatus[b] = b_Active;
p_Check[b]->SetCheck(b_Active);
}
if (u32_CurDisplay != IDM_EDITMODE)
return;
// ---------- Set dynamic comboboxes (font) ---------
static UINT u32_cCmd[] = { IDM_FONTNAME, IDM_FONTSIZE_STYLE };
static CComboBox *p_Combo[] = { &mCtrl_ComboFontName, &mCtrl_ComboFontSize };
static BOOL b_DropList[] = { TRUE, /*DropList*/ FALSE /*DropDown*/ };
ASSERT(sizeof(u32_cCmd) == sizeof(ms_ComboStatus)); // illegal _ComboBoxCount
// Set font name and size according to the current selection / cursor position
CString s_Value;
for (UINT c=0; c<_ComboBoxCount; c++)
{
if (pi_Editor->ExecGetCommandStr(u32_cCmd[c], &s_Value))
{
if (s_Value == ms_ComboStatus[c] || s_Value.GetLength() == 0)
continue;
if (p_Combo[c]->GetDroppedState()) // If combobox not currently dropped down
continue;
ms_ComboStatus[c] = s_Value;
// Depending on the style of the ComboBox we must choose another function here
if (b_DropList[c]) p_Combo [c]->SelectString(0, s_Value);
else p_Combo [c]->SetWindowText(s_Value);
}
}
}
// set properties of a <HR> element (horizontal line)
void CDHtmlEditDemoDlg::SetHRproperties()
{
cHtmlDocument *pi_Doc = pi_Editor->GetDocument();
cHtmlHR i_HR = pi_Doc->GetSelection();
if (!i_HR.Valid())
{
MessageBox(_T("Please select a <HR> element. (horizontal line)"), _T("Error"), MB_ICONSTOP);
return;
}
CHrProperties i_Prop(this);
i_Prop.ms_Color = i_HR.GetProperty(cHtmlHR::E_Color);
i_Prop.ms_Width = i_HR.GetProperty(cHtmlHR::E_Width);
i_Prop.ms_Size = i_HR.GetProperty(cHtmlHR::E_Size);
i_Prop.ms32_Shade = i_HR.GetShade() ? 1 : 0;
if (IDOK == i_Prop.DoModal())
{
i_HR.SetProperty(cHtmlHR::E_Color, i_Prop.ms_Color);
i_HR.SetProperty(cHtmlHR::E_Width, i_Prop.ms_Width);
i_HR.SetProperty(cHtmlHR::E_Size, i_Prop.ms_Size);
i_HR.SetShade(i_Prop.ms32_Shade == 1);
}
}
// set properties of a table
void CDHtmlEditDemoDlg::SetTableProperties()
{
cHtmlElement i_Sel = pi_Editor->GetDocument()->GetSelection();
cHtmlTable i_Table = i_Sel.FindParent(_T("TABLE"));
if (!i_Table.Valid())
{
MessageBox(_T("Please set the cursor into a table!"), _T("Error"), MB_ICONSTOP);
return;
}
cHtmlStyle i_Style = i_Table.GetStyle();
CTableProperties i_Prop(this);
i_Prop.mu32_Rules = i_Table.GetBorderRules();
i_Prop.ms_BackgColor = i_Table.GetBgColor();
i_Prop.ms_BorderColor = i_Table.GetBorderColor();
i_Prop.ms_BorderWidth = i_Table.GetBorderWidth();
i_Prop.ms_CellSpacing = i_Table.GetCellSpacing();
i_Prop.ms_CellPadding = i_Table.GetCellPadding();
i_Prop.ms_Width = i_Style.GetProperty(cHtmlStyle::E_Width);
i_Prop.ms_Height = i_Style.GetProperty(cHtmlStyle::E_Height);
i_Prop.ms_Width. Replace(_T("px"), _T(""));
i_Prop.ms_Height.Replace(_T("px"), _T(""));
if (IDOK == i_Prop.DoModal())
{
i_Table.SetBorderRules((cHtmlTable::eRules)i_Prop.mu32_Rules);
i_Table.SetBgColor (i_Prop.ms_BackgColor);
i_Table.SetBorderColor(i_Prop.ms_BorderColor);
i_Table.SetBorderWidth(i_Prop.ms_BorderWidth);
i_Table.SetCellSpacing(i_Prop.ms_CellSpacing);
i_Table.SetCellPadding(i_Prop.ms_CellPadding);
if (i_Prop.ms_Width. GetLength() && i_Prop.ms_Width. Find(_T("%")) < 0)
i_Prop.ms_Width += _T("px");
if (i_Prop.ms_Height.GetLength() && i_Prop.ms_Height.Find(_T("%")) < 0)
i_Prop.ms_Height += _T("px");
i_Style.SetProperty(cHtmlStyle::E_Width, i_Prop.ms_Width);
i_Style.SetProperty(cHtmlStyle::E_Height, i_Prop.ms_Height);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -