| 72 | | You can also process activex events through wxEVT_ACTIVEX or the |
| 73 | | corresponding message map macro EVT_ACTIVEX. |
| | 79 | You can also process activeX events through wxActiveXEvent. |
| | 80 | |
| | 81 | |
| | 82 | @section activexcontainer_example Example |
| | 83 | |
| | 84 | This is an example of how to use the Adobe Acrobat Reader ActiveX control to |
| | 85 | read PDF files (requires Acrobat Reader 4 and up). |
| | 86 | Controls like this are typically found and dumped from OLEVIEW.exe that is |
| | 87 | distributed with Microsoft Visual C++. |
| | 88 | This example also demonstrates how to create a backend for wxMediaCtrl. |
| | 89 | |
| | 90 | @code |
| | 91 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| | 92 | // |
| | 93 | // wxPDFMediaBackend |
| | 94 | // |
| | 95 | // http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/iac/IACOverview.pdf |
| | 96 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| | 97 | |
| | 98 | #include "wx/mediactrl.h" // wxMediaBackendCommonBase |
| | 99 | #include "wx/msw/ole/activex.h" // wxActiveXContainer |
| | 100 | #include "wx/msw/ole/automtn.h" // wxAutomationObject |
| | 101 | |
| | 102 | const IID DIID__DPdf = {0xCA8A9781,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}}; |
| | 103 | const IID DIID__DPdfEvents = {0xCA8A9782,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}}; |
| | 104 | const CLSID CLSID_Pdf = {0xCA8A9780,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}}; |
| | 105 | |
| | 106 | class WXDLLIMPEXP_MEDIA wxPDFMediaBackend : public wxMediaBackendCommonBase |
| | 107 | { |
| | 108 | public: |
| | 109 | wxPDFMediaBackend() : m_pAX(NULL) {} |
| | 110 | virtual ~wxPDFMediaBackend() |
| | 111 | { |
| | 112 | if(m_pAX) |
| | 113 | { |
| | 114 | m_pAX->DissociateHandle(); |
| | 115 | delete m_pAX; |
| | 116 | } |
| | 117 | } |
| | 118 | virtual bool CreateControl(wxControl* ctrl, wxWindow* parent, |
| | 119 | wxWindowID id, |
| | 120 | const wxPoint& pos, |
| | 121 | const wxSize& size, |
| | 122 | long style, |
| | 123 | const wxValidator& validator, |
| | 124 | const wxString& name) |
| | 125 | { |
| | 126 | IDispatch* pDispatch; |
| | 127 | if( ::CoCreateInstance(CLSID_Pdf, NULL, |
| | 128 | CLSCTX_INPROC_SERVER, |
| | 129 | DIID__DPdf, (void**)&pDispatch) != 0 ) |
| | 130 | return false; |
| | 131 | |
| | 132 | m_PDF.SetDispatchPtr(pDispatch); // wxAutomationObject will release itself |
| | 133 | |
| | 134 | if ( !ctrl->wxControl::Create(parent, id, pos, size, |
| | 135 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, |
| | 136 | validator, name) ) |
| | 137 | return false; |
| | 138 | |
| | 139 | m_ctrl = wxStaticCast(ctrl, wxMediaCtrl); |
| | 140 | m_pAX = new wxActiveXContainer(ctrl, |
| | 141 | DIID__DPdf, |
| | 142 | pDispatch); |
| | 143 | |
| | 144 | wxPDFMediaBackend::ShowPlayerControls(wxMEDIACTRLPLAYERCONTROLS_NONE); |
| | 145 | return true; |
| | 146 | } |
| | 147 | |
| | 148 | virtual bool Play() |
| | 149 | { |
| | 150 | return true; |
| | 151 | } |
| | 152 | virtual bool Pause() |
| | 153 | { |
| | 154 | return true; |
| | 155 | } |
| | 156 | virtual bool Stop() |
| | 157 | { |
| | 158 | return true; |
| | 159 | } |
| | 160 | |
| | 161 | virtual bool Load(const wxString& fileName) |
| | 162 | { |
| | 163 | if(m_PDF.CallMethod(wxT("LoadFile"), fileName).GetBool()) |
| | 164 | { |
| | 165 | m_PDF.CallMethod(wxT("setCurrentPage"), wxVariant((long)0)); |
| | 166 | NotifyMovieLoaded(); // initial refresh |
| | 167 | wxSizeEvent event; |
| | 168 | m_pAX->OnSize(event); |
| | 169 | return true; |
| | 170 | } |
| | 171 | |
| | 172 | return false; |
| | 173 | } |
| | 174 | virtual bool Load(const wxURI& location) |
| | 175 | { |
| | 176 | return m_PDF.CallMethod(wxT("LoadFile"), location.BuildUnescapedURI()).GetBool(); |
| | 177 | } |
| | 178 | virtual bool Load(const wxURI& WXUNUSED(location), |
| | 179 | const wxURI& WXUNUSED(proxy)) |
| | 180 | { |
| | 181 | return false; |
| | 182 | } |
| | 183 | |
| | 184 | virtual wxMediaState GetState() |
| | 185 | { |
| | 186 | return wxMEDIASTATE_STOPPED; |
| | 187 | } |
| | 188 | |
| | 189 | virtual bool SetPosition(wxLongLong where) |
| | 190 | { |
| | 191 | m_PDF.CallMethod(wxT("setCurrentPage"), wxVariant((long)where.GetValue())); |
| | 192 | return true; |
| | 193 | } |
| | 194 | virtual wxLongLong GetPosition() |
| | 195 | { |
| | 196 | return 0; |
| | 197 | } |
| | 198 | virtual wxLongLong GetDuration() |
| | 199 | { |
| | 200 | return 0; |
| | 201 | } |
| | 202 | |
| | 203 | virtual void Move(int WXUNUSED(x), int WXUNUSED(y), |
| | 204 | int WXUNUSED(w), int WXUNUSED(h)) |
| | 205 | { |
| | 206 | } |
| | 207 | wxSize GetVideoSize() const |
| | 208 | { |
| | 209 | return wxDefaultSize; |
| | 210 | } |
| | 211 | |
| | 212 | virtual double GetPlaybackRate() |
| | 213 | { |
| | 214 | return 0; |
| | 215 | } |
| | 216 | virtual bool SetPlaybackRate(double) |
| | 217 | { |
| | 218 | return false; |
| | 219 | } |
| | 220 | |
| | 221 | virtual double GetVolume() |
| | 222 | { |
| | 223 | return 0; |
| | 224 | } |
| | 225 | virtual bool SetVolume(double) |
| | 226 | { |
| | 227 | return false; |
| | 228 | } |
| | 229 | |
| | 230 | virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags) |
| | 231 | { |
| | 232 | if(flags) |
| | 233 | { |
| | 234 | m_PDF.CallMethod(wxT("setShowToolbar"), true); |
| | 235 | m_PDF.CallMethod(wxT("setShowScrollbars"), true); |
| | 236 | } |
| | 237 | else |
| | 238 | { |
| | 239 | m_PDF.CallMethod(wxT("setShowToolbar"), false); |
| | 240 | m_PDF.CallMethod(wxT("setShowScrollbars"), false); |
| | 241 | } |
| | 242 | |
| | 243 | return true; |
| | 244 | } |
| | 245 | |
| | 246 | wxActiveXContainer* m_pAX; |
| | 247 | wxAutomationObject m_PDF; |
| | 248 | |
| | 249 | DECLARE_DYNAMIC_CLASS(wxPDFMediaBackend) |
| | 250 | }; |
| | 251 | |
| | 252 | IMPLEMENT_DYNAMIC_CLASS(wxPDFMediaBackend, wxMediaBackend); |
| | 253 | Put this in one of your existant source files and then create a wxMediaCtrl with |
| | 254 | |
| | 255 | //[this] is the parent window, "myfile.pdf" is the PDF file to open |
| | 256 | wxMediaCtrl* mymediactrl = new wxMediaCtrl(this, wxT("myfile.pdf"), wxID_ANY, |
| | 257 | wxDefaultPosition, wxSize(300,300), |
| | 258 | 0, wxT("wxPDFMediaBackend")); |
| | 259 | @endcode |
| | 260 | |