]>
Commit | Line | Data |
---|---|---|
1 | Lindsay Mathieson | |
2 | Email : <lmathieson@optusnet.com.au> | |
3 | ||
4 | This is prelimanary stuff - the controls need extra methods and events etc, | |
5 | feel free to email with suggestions &/or patches. | |
6 | ||
7 | Tested with wxWindows 2.3.2. | |
8 | Built with MS Visual C++ 6.0 & DevStudio | |
9 | Minor use of templates and STL | |
10 | ||
11 | ----------------------------------------------------------- | |
12 | This sample illustrates using wxActiveX and wxIEHtmlWin too: | |
13 | 1. Host an arbitrary ActiveX control | |
14 | 1.1 - Capture and logging of all events from control | |
15 | 2. Specifically host the MSHTML Control | |
16 | ||
17 | ||
18 | wxActiveX: | |
19 | ========== | |
20 | wxActiveX is used to host and siplay any activeX control, all the wxWindows developer | |
21 | needs to know is either the ProgID or CLSID of the control in question. | |
22 | ||
23 | Derived From: | |
24 | - wxWindow | |
25 | ||
26 | Include Files: | |
27 | - wxactivex.h | |
28 | ||
29 | Source Files: | |
30 | - wxactivex.cpp | |
31 | ||
32 | Event Handling: | |
33 | --------------- | |
34 | - EVT_ACTIVEX(id, eventName, handler) (handler = void OnActiveX(wxActiveXEvent& event)) | |
35 | - EVT_ACTIVEX_DISPID(id, eventDispId, handler) (handler = void OnActiveX(wxActiveXEvent& event)) | |
36 | class wxActiveXEvent : public wxNotifyEvent | |
37 | wxString EventName(); | |
38 | int ParamCount() const; | |
39 | wxString ParamType(int idx); | |
40 | wxString ParamName(int idx); | |
41 | wxVariant operator[] (int idx) const; // parameter by index | |
42 | wxVariant& operator[] (int idx); | |
43 | wxVariant operator[] (wxString name) const; // named parameters | |
44 | wxVariant& operator[] (wxString name); | |
45 | ||
46 | ||
47 | Members: | |
48 | -------- | |
49 | wxActiveX::wxActiveX(wxWindow * parent, REFCLSID clsid, wxWindowID id = -1); | |
50 | - Creates a activeX control identified by clsid | |
51 | e.g | |
52 | wxFrame *frame = new wxFrame(this, -1, "test"); | |
53 | wxActiveX *X = new wxActiveX(frame, CLSID_WebBrowser); | |
54 | ||
55 | wxActiveX::wxActiveX(wxWindow * parent, wxString progId, wxWindowID id = -1); | |
56 | - Creates a activeX control identified by progId | |
57 | e.g. | |
58 | wxFrame *frame = new wxFrame(this, -1, "test"); | |
59 | wxActiveX *X = new wxActiveX(frame, "MSCAL.Calendar"); | |
60 | ||
61 | ||
62 | wxActiveX::~wxActiveX(); | |
63 | - Destroys the control | |
64 | - disconnects all connection points | |
65 | ||
66 | - int GetEventCount() const; | |
67 | Number of events generated by control | |
68 | ||
69 | - const FuncX& GetEvent(int idx) const; | |
70 | Names, Params and Typeinfo for events | |
71 | ||
72 | HRESULT wxActiveX::ConnectAdvise(REFIID riid, IUnknown *eventSink); | |
73 | - Connects a event sink. Connections are automaticlly diconnected in the destructor | |
74 | e.g. | |
75 | FS_DWebBrowserEvents2 *events = new FS_DWebBrowserEvents2(iecontrol); | |
76 | hret = iecontrol->ConnectAdvise(DIID_DWebBrowserEvents2, events); | |
77 | if (! SUCCEEDED(hret)) | |
78 | delete events; | |
79 | ||
80 | ||
81 | Sample Events: | |
82 | -------------- | |
83 | EVT_ACTIVEX(ID_MSHTML, "BeforeNavigate2", OnMSHTMLBeforeNavigate2X) | |
84 | ||
85 | void wxIEFrame::OnMSHTMLBeforeNavigate2X(wxActiveXEvent& event) | |
86 | { | |
87 | wxString url = event["Url"]; | |
88 | ||
89 | int rc = wxMessageBox(url, "Allow open url ?", wxYES_NO); | |
90 | ||
91 | if (rc != wxYES) | |
92 | event["Cancel"] = true; | |
93 | }; | |
94 | ||
95 | ||
96 | wxIEHtmlWin: | |
97 | ============ | |
98 | wxIEHtmlWin is a specialisation of the wxActiveX control for hosting the MSHTML control. | |
99 | ||
100 | Derived From: | |
101 | - wxActiveX | |
102 | - wxWindow | |
103 | ||
104 | Event Handling: | |
105 | --------------- | |
106 | - see wxActiveX | |
107 | Members: | |
108 | -------- | |
109 | wxIEHtmlWin::wxIEHtmlWin(wxWindow * parent, wxWindowID id = -1); | |
110 | - Constructs and initialises the MSHTML control | |
111 | - LoadUrl("about:blank") is called | |
112 | ||
113 | wxIEHtmlWin::~wxIEHtmlWin(); | |
114 | - destroys the control | |
115 | ||
116 | void wxIEHtmlWin::LoadUrl(const wxString&); | |
117 | - Attempts to browse to the url, the control uses its internal (MS) | |
118 | network streams | |
119 | ||
120 | bool wxIEHtmlWin::LoadString(wxString html); | |
121 | - Load the passed HTML string | |
122 | ||
123 | bool wxIEHtmlWin::LoadStream(istream *strm); | |
124 | - load the passed HTML stream. The control takes ownership of | |
125 | the pointer, deleting when finished. | |
126 | ||
127 | bool wxIEHtmlWin::LoadStream(wxInputStream *is); | |
128 | - load the passed HTML stream. The control takes ownership of | |
129 | the pointer, deleting when finished. | |
130 | ||
131 | void wxIEHtmlWin::SetCharset(wxString charset); | |
132 | - Sets the charset of the loaded document | |
133 | ||
134 | void wxIEHtmlWin::SetEditMode(bool seton); | |
135 | - Sets edit mode. | |
136 | NOTE: This does work, but is bare bones - we need more events exposed before | |
137 | this is usable as an HTML editor. | |
138 | ||
139 | bool wxIEHtmlWin::GetEditMode(); | |
140 | - Returns the edit mode setting | |
141 | ||
142 | wxString wxIEHtmlWin::GetStringSelection(bool asHTML = false); | |
143 | - Returns the currently selected text (plain or HTML text) | |
144 | ||
145 | wxString GetText(bool asHTML = false); | |
146 | - Returns the body text (plain or HTML text) | |
147 | ||
148 | Lindsay Mathieson | |
149 | Email : <lmathieson@optusnet.com.au> |