]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/activex/wxie/wxActiveXFrame.cpp
fixed wxVsnprintf() to write as much as it can if the output buffer is too short
[wxWidgets.git] / wxPython / contrib / activex / wxie / wxActiveXFrame.cpp
1 /*
2 wxActiveX Library Licence, Version 3
3 ====================================
4
5 Copyright (C) 2003 Lindsay Mathieson [, ...]
6
7 Everyone is permitted to copy and distribute verbatim copies
8 of this licence document, but changing it is not allowed.
9
10 wxActiveX LIBRARY LICENCE
11 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
13 This library is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Library General Public Licence as published by
15 the Free Software Foundation; either version 2 of the Licence, or (at
16 your option) any later version.
17
18 This library is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
21 General Public Licence for more details.
22
23 You should have received a copy of the GNU Library General Public Licence
24 along with this software, usually in a file named COPYING.LIB. If not,
25 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
26 Boston, MA 02111-1307 USA.
27
28 EXCEPTION NOTICE
29
30 1. As a special exception, the copyright holders of this library give
31 permission for additional uses of the text contained in this release of
32 the library as licenced under the wxActiveX Library Licence, applying
33 either version 3 of the Licence, or (at your option) any later version of
34 the Licence as published by the copyright holders of version 3 of the
35 Licence document.
36
37 2. The exception is that you may use, copy, link, modify and distribute
38 under the user's own terms, binary object code versions of works based
39 on the Library.
40
41 3. If you copy code from files distributed under the terms of the GNU
42 General Public Licence or the GNU Library General Public Licence into a
43 copy of this library, as this licence permits, the exception does not
44 apply to the code that you add in this way. To avoid misleading anyone as
45 to the status of such modified files, you must delete this exception
46 notice from such code and/or adjust the licensing conditions notice
47 accordingly.
48
49 4. If you write modifications of your own for this library, it is your
50 choice whether to permit this exception to apply to your modifications.
51 If you do not wish that, you must delete the exception notice from such
52 code and/or adjust the licensing conditions notice accordingly.
53 */
54
55 // ----------------------------------------------------------------------------
56 // headers
57 // ----------------------------------------------------------------------------
58 // For compilers that support precompilation, includes "wx/wx.h".
59 #if defined(__WXGTK__) || defined(__WXMOTIF__)
60 #include "wx/wx.h"
61 #endif
62 #include "wx/wxprec.h"
63 #include "wx/filedlg.h"
64 #include "wx/textdlg.h"
65 #include "wxActiveXFrame.h"
66 #include <sstream>
67 using namespace std;
68 #include "wx/splitter.h"
69 #include "wx/textctrl.h"
70 #include "wx/clipbrd.h"
71 #include <wx/msgdlg.h>
72
73 enum
74 {
75 // menu items
76 MENU_GETTYPEINFO = 700,
77 MENU_INVOKEMETHOD,
78 MENU_TEST
79 };
80
81 BEGIN_EVENT_TABLE(wxActiveXFrame, wxFrame)
82 EVT_MENU(MENU_GETTYPEINFO, wxActiveXFrame::OnGetTypeInfo)
83 EVT_MENU(MENU_INVOKEMETHOD, wxActiveXFrame::OnInvokeMethod)
84 EVT_MENU(MENU_TEST, wxActiveXFrame::OnTest)
85 END_EVENT_TABLE()
86
87
88 wxActiveXFrame::wxActiveXFrame(wxWindow *parent, wxString title) :
89 wxFrame(parent, -1, title)
90 {
91 // create a menu bar
92 wxMenu *xMenu = new wxMenu("", wxMENU_TEAROFF);
93
94 xMenu->Append(MENU_GETTYPEINFO, "Get Type Info", "");
95 xMenu->Append(MENU_INVOKEMETHOD, "Invoke Method (no params)", "");
96 xMenu->Append(MENU_TEST, "Test", "For debugging purposes");
97
98 // now append the freshly created menu to the menu bar...
99 wxMenuBar *menuBar = new wxMenuBar();
100 menuBar->Append(xMenu, "&ActiveX");
101
102 // ... and attach this menu bar to the frame
103 SetMenuBar(menuBar);
104
105 wxSplitterWindow *sp = new wxSplitterWindow(this);
106 X = new wxActiveX(sp, title, 101);
107
108 textLog = new wxTextCtrl(sp, -1, "", wxPoint(0,0), wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
109
110 sp->SplitHorizontally(X, textLog, 0);
111
112 // conenct all events
113 for (int i = 0; i < X->GetEventCount(); i++)
114 {
115 const wxActiveX::FuncX& func = X->GetEventDesc(i);
116 const wxEventType& ev = RegisterActiveXEvent((DISPID) func.memid);
117 Connect(101, ev, (wxObjectEventFunction) OnActiveXEvent);
118 };
119 }
120
121 wxString VarTypeAsString(VARTYPE vt)
122 {
123 #define VT(vtype, desc) case vtype : return desc
124
125 if (vt & VT_BYREF)
126 vt -= VT_BYREF;
127
128 if (vt & VT_ARRAY)
129 vt -= VT_ARRAY;
130
131 switch (vt)
132 {
133 VT(VT_SAFEARRAY, "SafeArray");
134 VT(VT_EMPTY, "empty");
135 VT(VT_NULL, "null");
136 VT(VT_UI1, "byte");
137 VT(VT_I1, "char");
138 VT(VT_I2, "short");
139 VT(VT_I4, "long");
140 VT(VT_UI2, "unsigned short");
141 VT(VT_UI4, "unsigned long");
142 VT(VT_INT, "int");
143 VT(VT_UINT, "unsigned int");
144 VT(VT_R4, "real(4)");
145 VT(VT_R8, "real(8)");
146 VT(VT_CY, "Currency");
147 VT(VT_DATE, "wxDate");
148 VT(VT_BSTR, "wxString");
149 VT(VT_DISPATCH, "IDispatch");
150 VT(VT_ERROR, "SCode Error");
151 VT(VT_BOOL, "bool");
152 VT(VT_VARIANT, "wxVariant");
153 VT(VT_UNKNOWN, "IUknown");
154 VT(VT_VOID, "void");
155 VT(VT_PTR, "void *");
156 VT(VT_USERDEFINED, "*user defined*");
157
158 default:
159 {
160 wxString s;
161 s << "Unknown(" << vt << ")";
162 return s;
163 };
164 };
165
166 #undef VT
167 };
168
169 #define ENDL "\r\n"
170
171
172 void OutFunc(wxString& os, const wxActiveX::FuncX& func)
173 {
174 os << VarTypeAsString(func.retType.vt) << " " << func.name << "(";
175 for (unsigned int p = 0; p < func.params.size(); p++)
176 {
177 const wxActiveX::ParamX& param = func.params[p];
178 if (param.IsIn() && param.IsOut())
179 os << "[IN OUT] ";
180 else if (param.IsIn())
181 os << "[IN] ";
182 else if (param.IsIn())
183 os << "[OUT] ";
184 os << VarTypeAsString(param.vt) << " " << (param.isPtr ? "*" : "") << param.name;
185 if (p < func.params.size() - 1)
186 os << ", ";
187 };
188 os << ")" << ENDL;
189 };
190
191 void wxActiveXFrame::OnGetTypeInfo(wxCommandEvent& event)
192 {
193 wxString os;
194
195 int i =0;
196 os <<
197 "Props" << ENDL <<
198 "=====" << ENDL;
199 for (i = 0; i < X->GetPropCount(); i++)
200 {
201 wxActiveX::PropX prop = X->GetPropDesc(i);
202 os << VarTypeAsString(prop.type.vt) << " " << prop.name << "(";
203 if (prop.CanSet())
204 {
205 os << VarTypeAsString(prop.arg.vt);
206 };
207 os << ")" << ENDL;
208
209 };
210 os << ENDL;
211
212 os <<
213 "Events" << ENDL <<
214 "======" << ENDL;
215 for (i = 0; i < X->GetEventCount(); i++)
216 OutFunc(os, X->GetEventDesc(i));
217 os << ENDL;
218
219 os <<
220 "Methods" << ENDL <<
221 "=======" << ENDL;
222 for (i = 0; i < X->GetMethodCount(); i++)
223 OutFunc(os, X->GetMethodDesc(i));
224 os << ENDL;
225
226
227 if (wxTheClipboard->Open())
228 {
229 wxDataObjectSimple *wo = new wxTextDataObject(os);
230 wxTheClipboard->SetData(wo);
231 wxTheClipboard->Flush();
232 wxTheClipboard->Close();
233 };
234
235 wxMessageBox(os, "Type Info", wxOK, this);
236 };
237
238 void wxActiveXFrame::OnInvokeMethod(wxCommandEvent& event)
239 {
240 //wxTextEntryDialog dlg(this, "Method");
241 //if (dlg.ShowModal() == wxID_OK)
242 // X->CallMethod(dlg.GetValue());
243 };
244
245 void wxActiveXFrame::OnTest(wxCommandEvent& event)
246 {
247 // flash testing
248 wxVariant args[] = {0L, "http://www.macromedia.com/support/flash/ts/documents/java_script_comm/flash_to_javascript.swf"};
249 X->CallMethod("LoadMovie", args);
250 //X->Prop("Movie") = "http://www.macromedia.com/support/flash/ts/documents/java_script_comm/flash_to_javascript.swf";
251
252 // mc cal testing
253 //X->Prop("year") = 1964L;
254 //X->Prop("Value") = wxDateTime::Now();
255
256 // pdf testing
257 //wxVariant file = "C:\\WINNT\\wx2\\docs\\pdf\\dialoged.pdf";
258 //X->CallMethod("LoadFile", &file);
259 };
260
261 void wxActiveXFrame::OnActiveXEvent(wxActiveXEvent& event)
262 {
263 #ifdef UNICODE
264 wostringstream os;
265 #else
266 ostringstream os;
267 #endif
268
269 os << (const wxChar *) event.EventName() << wxT("(");
270
271 for (int p = 0; p < event.ParamCount(); p++)
272 {
273 os <<
274 (const wxChar *) event.ParamType(p) << wxT(" ") <<
275 (const wxChar *) event.ParamName(p) << wxT(" = ") <<
276 (const wxChar *) (wxString) event[p];
277 if (p < event.ParamCount() - 1)
278 os << wxT(", ");
279 };
280 os << wxT(")") << endl;
281 wxString data = os.str().c_str();
282 textLog->AppendText(data);
283 };
284