-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrowserSys.h
202 lines (175 loc) · 5.62 KB
/
BrowserSys.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// ---------------------------------------------------------------------------
#ifndef BrowserSysH
#define BrowserSysH
#include <oaidl.h>
#include "SHDocVw_OCX.h"
#include <SHDocVw.hpp>
#include <mshtml.h>
#include <Vcl.Graphics.hpp>
#include "Style.h"
#include <oaidl.h>
#include <Vcl.Dialogs.hpp>
#include "mshtmhst.h"
#include "SHDocVw_OCX.h"
class MyDocHandler;
// êëàññ-îáåðòêà äëÿ webbrowser
class BrowserSys {
public:
BrowserSys(TCppWebBrowser *wb, TPopupMenu *popupmenu); // êîíñòðóêòîð ïîëó÷àåò
// *Webbrowser è óêàçàòåëü íà êîíòåêñòíîå ìåíþ
~BrowserSys();
bool InitInterfaces(); // èíèöèàëèçàöèÿ
void EditMode(bool on = true); // ïåðåâîä äîêóìåíòà â ðåæèì ðåäàêòèðîâàíèÿ
bool CanPaste(); // ìîæíî ëè âñòàâèòü â äîêóìåíò èç áóôåðà îáìåíà
bool CanCopy(); // ìîæíî ëè êîïèðîâàòü
bool CanCut(); // ìîæíî ëè âûðåçàòü â áóôåð
bool CanRedo(); // ìîæíî ëè ïîâòîðèòü îòìåíåííîå äåéñòâèå
bool CanUndo(); // îòìåíèòü ïîñëåäíåå äåéñòâèå
void Bold(); // óñòàíîâèòü ïîëóæèðíîå íàåðòàíèå âûäåëåííîãî òåêñòà
void Italic();
void Paste(); // âñòàâèòü èç áóôåðà
void Copy();
void Cut();
void UnderLine();
void InsertList(); // ïîìåòèòü êàê ñïèñîê
void HyperLink(); // ïîìåòèòü êàê ãèïåðññûëêó
void InsertImage(); // âñòàâèòü èçîáðàæåíèå
void Undo();
void Redo();
void SetSize(int size); // óòñàíîâèòü ðàçìåð òåêñòà
void SetFont(const String &font); // óñòàíîâèòü øðèôò
void SetColor(int color);
int GetSize(IHTMLTxtRange* TextRange); // óçíàòü ðàçìåð òåêñòà
String GetFont(IHTMLTxtRange* TextRange);
int GetColor(IHTMLTxtRange* TextRange);
bool isItalic(IHTMLTxtRange* TextRange); // ÿâëÿåòñÿ ëè òåêñò íàêëîííûì?
bool isBold(IHTMLTxtRange* TextRange);
bool isUnderline(IHTMLTxtRange* TextRange);
IHTMLTxtRange* TxtRange(); // ïîëó÷èòü òåêóùóþ âûäåëåííóþ îáëàñòü òåêñòà
void SetStyle(Style *style);
String GetText(); // èçâëå÷ü òåêñò èç webbrowser
void SetText(String s); // óñòàíîâèòü òåêñò
void OpenFile(String filename);
private:
TCppWebBrowser *wb;
IHTMLDocument2 *Editor;
MyDocHandler *dochandler;
VARIANT var;
VARIANT_BOOL rec;
const String HtmlColor(int color);
};
// ---------------------------------------------------------------------------
// íåáõîäèìî ðåàëèçîâàòü äëÿ óòàíîâêè ñîáñòâåííîãî ìåíþ è îòêëþ÷åíèÿ ñèñòåìíûõ
// ãîðÿ÷èõ êëàâèø
class MyDocHandler : public IDocHostUIHandler {
long refcount;
TPopupMenu *popup;
public:
MyDocHandler(TPopupMenu *popupmenu) : refcount(1) {
popup = popupmenu;
}
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID classid,
void** intf) {
if (classid == IID_IUnknown)
* intf = (IUnknown*)this;
else if (classid == IID_IDocHostUIHandler)
* intf = (IDocHostUIHandler*)this;
else
return E_NOINTERFACE;
return S_OK;
}
virtual ULONG STDMETHODCALLTYPE AddRef() {
InterlockedIncrement(&refcount);
return refcount;
}
virtual ULONG STDMETHODCALLTYPE Release() {
InterlockedDecrement(&refcount);
if (refcount == 0)
delete this;
return refcount;
}
// Returning S_OK tells the web browser that it need not display its
// own context menu, presumably because the application hosting it has
// displayed its own menu to replace it.
virtual HRESULT STDMETHODCALLTYPE ShowContextMenu(
/* [in] */ DWORD dwID,
/* [in] */ POINT __RPC_FAR *ppt,
/* [in] */ IUnknown __RPC_FAR *pcmdtReserved,
/* [in] */ IDispatch __RPC_FAR *pdispReserved) {
popup->Popup(ppt->x, ppt->y);
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE GetHostInfo(
/* [out][in] */ DOCHOSTUIINFO __RPC_FAR *pInfo) {
pInfo->dwFlags = 0x00000000;
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE ShowUI(
/* [in] */ DWORD dwID,
/* [in] */ IOleInPlaceActiveObject __RPC_FAR *pActiveObject,
/* [in] */ IOleCommandTarget __RPC_FAR *pCommandTarget,
/* [in] */ IOleInPlaceFrame __RPC_FAR *pFrame,
/* [in] */ IOleInPlaceUIWindow __RPC_FAR *pDoc) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE HideUI(void) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE UpdateUI(void) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE EnableModeless(
/* [in] */ BOOL fEnable) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE OnDocWindowActivate(
/* [in] */ BOOL fActivate) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE OnFrameWindowActivate(
/* [in] */ BOOL fActivate) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE ResizeBorder(
/* [in] */ LPCRECT prcBorder,
/* [in] */ IOleInPlaceUIWindow __RPC_FAR *pUIWindow,
/* [in] */ BOOL fRameWindow) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE TranslateAccelerator(
/* [in] */ LPMSG lpMsg,
/* [in] */ const GUID __RPC_FAR *pguidCmdGroup,
/* [in] */ DWORD nCmdID) {
// ShowMessage(GetKeyState(VK_CONTROL));
if (lpMsg->message == WM_KEYDOWN)
if ((GetKeyState(VK_CONTROL) & 0X80) == 0X80)
return S_OK;
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetOptionKeyPath(
/* [out] */ LPOLESTR __RPC_FAR *pchKey,
/* [in] */ DWORD dw) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetDropTarget(
/* [in] */ IDropTarget __RPC_FAR *pDropTarget,
/* [out] */ IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetExternal(
/* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE TranslateUrl(
/* [in] */ DWORD dwTranslate,
/* [in] */ OLECHAR __RPC_FAR *pchURLIn,
/* [out] */ OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE FilterDataObject(
/* [in] */ IDataObject __RPC_FAR *pDO,
/* [out] */ IDataObject __RPC_FAR *__RPC_FAR *ppDORet) {
return E_NOTIMPL;
}
};
#endif