📄 chtmleditor.h
字号:
BOOL InsertColumn(UINT Index);
BOOL GetSpanMap(UINT *pu32_Rows, UINT *pu32_Cols, UINT **ppu32_Map);
void CleanUp();
UINT GetColumnCount();
UINT GetRowCount();
cHtmlTableCell GetCell(UINT u32_Row, UINT u32_Column, BOOL b_ReturnPrevious=FALSE);
CString GetCellPadding();
BOOL SetCellPadding(CString s_Padding);
CString GetCellSpacing();
BOOL SetCellSpacing(CString s_Spacing);
CString GetBorderWidth();
BOOL SetBorderWidth(CString s_Width);
CString GetBorderColor();
BOOL SetBorderColor(CString s_Color);
eRules GetBorderRules();
BOOL SetBorderRules(eRules e_Rules);
protected:
CComQIPtr<IHTMLTable, &IID_IHTMLTable> mi_Table;
};
// ####################################################
class cHtmlImg : public cHtmlElement
{
public:
cHtmlImg(CComPtr<IHTMLElement> i_Elem);
virtual BOOL Valid();
CString GetUrl();
BOOL SetSrc(CString s_Src);
protected:
CComQIPtr<IHTMLImgElement, &IID_IHTMLImgElement> mi_Img;
};
// ####################################################
class cHtmlHR : public cHtmlElement
{
public:
cHtmlHR(CComPtr<IHTMLElement> i_Elem);
enum eAction
{
E_Color,
E_Size, // the height of the line in pixel
E_Width, // the length of the line in pixel or percent
E_Align
};
virtual BOOL Valid();
void SetProperty(eAction e_Action, CString s_Value);
CString GetProperty(eAction e_Action);
BOOL GetShade();
void SetShade(BOOL b_Shade);
protected:
CComQIPtr<IHTMLHRElement, &IID_IHTMLHRElement> mi_HR;
};
// ####################################################
class cHtmlDocument : public cHtmlDomNode
{
public:
cHtmlDocument();
void Assign(CComPtr<IDispatch> D_Doc, CHtmlEditor *pi_Editor);
virtual BOOL Valid();
cHtmlStyleSheet GetStyleSheet();
BOOL SetDocumentDefault(CString s_Selector, cHtmlStyle::eProp e_Prop, CString s_Value);
BOOL IsModified();
cHtmlElement GetElementByID(CString s_ID);
UINT QueryStatus(UINT u32_Command);
CString GetTitle();
CString GetUrl();
BOOL ExecSetCommand(UINT u32_Command, CComVariant v_In=0, BOOL b_PromtUser=TRUE);
BOOL ExecGetCommand(UINT u32_Command, CComVariant *pv_Out);
CString GetHtml();
cHtmlElement GetHtmlTag();
cHtmlElement GetHead();
cHtmlElement GetBody(BOOL b_Create);
void CleanUpTags();
cHtmlElement GetSelection(BOOL b_AllowEmptySel=TRUE);
UINT GetElementCollection(CString s_TagName, CComQIPtr<IHTMLElementCollection> &i_Collect);
BOOL PasteIntoSelection(CString s_Html);
BOOL AddToSelection(CString s_BeginHtml, CString s_EndHtml);
BOOL SetHtml(CString s_HTML);
BOOL InsertTable(UINT u32_Rows, UINT u32_Cols);
BOOL SetDesignMode(BOOL b_Design);
BOOL GetDesignMode();
cHtmlTableCell GetSelectedCell();
void InsertNewTableColumn(BOOL b_Right);
void InsertNewTableRow(BOOL b_Below);
BOOL InsertNewImage(CString s_Path);
BOOL SetSelectionFontSize(UINT u32_Size);
UINT GetSelectionFontSize();
UINT GetDefaultFontSize();
UINT ConvertFontSize(CString s_Size);
void MakeImagesAbsolute();
protected:
void RecursiveSetFontSize(cHtmlElement &i_Parent, CString *ps_Size);
void RecursiveCleanUpChilds(cHtmlElement &i_Elem, CString *ps_Removed);
BOOL ReplaceHeading(CString s_Tag, cHtmlElement &i_Elem);
BOOL ReplaceParagraph(cHtmlElement &i_Elem);
CHtmlEditor *mp_Editor;
CComQIPtr<IHTMLDocument2> mi_Doc2;
CComQIPtr<IHTMLDocument3> mi_Doc3;
CComQIPtr<IPersistStreamInit> mi_PStream;
CComQIPtr<IOleCommandTarget> mi_CmdTarg;
int ms32_DefaultFontSize;
};
// #####################################################
class CMsieWnd : public CWnd
{
public:
void SetEditor(CHtmlEditor *p_Editor);
protected:
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL PreTranslateMessage(MSG* pMsg);
private:
CHtmlEditor *mp_Editor;
};
// #####################################################
class CUniRichEdit : public CWnd, public cMisc
{
public:
CUniRichEdit();
virtual ~CUniRichEdit();
void SetEditor(CHtmlEditor *p_Editor);
BOOL CreateEx(DWORD u32_ExStyle, DWORD u32_Style, const RECT& k_Rect, CWnd* p_Parent, UINT u32_ID);
void SetWindowText(CString s_Text);
private:
virtual BOOL PreTranslateMessage(MSG* pMsg);
HINSTANCE mh_Dll32;
HINSTANCE mh_Dll20;
CHtmlEditor *mp_Editor;
};
// #####################################################
class cStreamReader : public IStream, public cMisc
{
public:
cStreamReader();
virtual ~cStreamReader();
void SetData(LPCTSTR szData);
ULONG STDMETHODCALLTYPE AddRef();
ULONG STDMETHODCALLTYPE Release();
STDMETHOD(QueryInterface)(REFIID iid, void **ppUnk);
STDMETHOD(Read)(void *pv_Buffer, ULONG u32_BufSize, ULONG *pu32_ReadBytes);
STDMETHOD(Write)(const void *pv_Buffer, ULONG u32_BufSize, ULONG *pcbWritten);
STDMETHOD(Seek)(LARGE_INTEGER, DWORD, ULARGE_INTEGER*);
STDMETHOD(SetSize)(ULARGE_INTEGER);
STDMETHOD(CopyTo)(IStream *, ULARGE_INTEGER, ULARGE_INTEGER*, ULARGE_INTEGER*);
STDMETHOD(Commit)(DWORD);
STDMETHOD(Revert)();
STDMETHOD(LockRegion)(ULARGE_INTEGER, ULARGE_INTEGER, DWORD);
STDMETHOD(UnlockRegion)(ULARGE_INTEGER, ULARGE_INTEGER, DWORD);
STDMETHOD(Stat)(STATSTG*, DWORD);
STDMETHOD(Clone)(IStream**);
protected:
char *mps8_Data;
UINT mu32_DataLen;
UINT mu32_Index;
};
// END embedded classes
// ####################################################
// class CHtmlEditor :
DECLARE_DYNCREATE(CHtmlEditor)
public:
CHtmlEditor();
virtual ~CHtmlEditor();
virtual BOOL Valid();
void Clear();
void Save();
BOOL ExecSetCommand(UINT u32_Command, CComVariant v_In=0, BOOL b_PromtUser=TRUE);
BOOL ExecGetCommand(UINT u32_Command, CComVariant *pv_Out);
BOOL ExecGetCommandStr(UINT u32_Command, CString *ps_Out);
UINT QueryStatus(UINT u32_Command);
BOOL CreateEditor(CWnd *p_Static, CWnd *p_NotificationWnd, BOOL b_EditOnlyBody, BOOL b_EnableThemes);
void ResetMsieSettings();
void SetDisplayMode(BOOL b_SourceMode, BOOL b_DesignMode);
void EnableEditor(BOOL b_Enable);
void MoveWindow(int Left, int Top, int Width, int Height, UINT u32_Flags=0);
void MoveWindow(CRect k_Rect, UINT u32_Flags=0);
void ReplaceParagraphs(UINT u32_VirtKeyCode);
cHtmlDocument* GetDocument();
BOOL NavigateToEmbeddedResource(CString s_RsrcName);
BOOL Navigate(LPCTSTR t_URL, DWORD dwFlags=0, LPCTSTR lpszTargetFrameName=0, LPCTSTR lpszHeaders=0, LPVOID lpvPostData=0, DWORD dwPostDataLen=0);
UINT GetDisplayMode();
void NotifyParent(UINT u32_CommandID, BOOL b_Post);
UINT GetMsieVersion();
BOOL IsPlatformNT();
void DelayCeanUp();
protected:
virtual void OnBeforeNavigate2(LPCTSTR t_URL, DWORD u32_Flags, LPCTSTR t_TargetFrame, CByteArray& i_PostedData, LPCTSTR t_Headers, BOOL *pb_Cancel);
virtual void OnNavigateComplete2(LPCTSTR t_URL);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
BOOL mb_SourceMode;
BOOL mb_Enabled;
cHtmlDocument mi_HtmDoc;
CMsieWnd mi_MSIE;
CUniRichEdit mi_RichEdit;
CWnd *mp_NotificationWnd;
CWnd *mp_Static;
BOOL mb_EditOnlyBody;
BOOL mb_InitDone;
BOOL mb_CleanUp;
BOOL mb_SubClassed;
BOOL mb_EnableThemes;
BOOL mb_PlatformNT;
BOOL mb_ParaReplaced;
};
// these typedefs avoid that you have to tpye "CHtmlEditor::cHtmlTable" each time
// instead of simply typing "cHtmlTable"
typedef CHtmlEditor::cMisc cMisc;
typedef CHtmlEditor::cHtmlStyle cHtmlStyle;
typedef CHtmlEditor::cHtmlStyleSheet cHtmlStyleSheet;
typedef CHtmlEditor::cHtmlDomNode cHtmlDomNode;
typedef CHtmlEditor::cHtmlElement cHtmlElement;
typedef CHtmlEditor::cHtmlTableCell cHtmlTableCell;
typedef CHtmlEditor::cHtmlTableRow cHtmlTableRow;
typedef CHtmlEditor::cHtmlTable cHtmlTable;
typedef CHtmlEditor::cHtmlHR cHtmlHR;
typedef CHtmlEditor::cHtmlImg cHtmlImg;
typedef CHtmlEditor::cHtmlDocument cHtmlDocument;
typedef CHtmlEditor::CUniRichEdit CUniRichEdit;
typedef CHtmlEditor::CMsieWnd CMsieWnd;
typedef CHtmlEditor::cStreamReader cStreamReader;
#endif // !defined(HTML_EDITOR_H__AF3E29B6_2B28_46D0_9D37_74D6C9E41B4A__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -