⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 activex.i

📁 Wxpython Implemented on Windows CE, Source code
💻 I
📖 第 1 页 / 共 3 页
字号:

    switch(vt) {
    case VT_VARIANT:
        return _T("VT_VARIANT");
        
    // 1 byte chars
    case VT_I1:
    case VT_UI1:
    // 2 byte shorts
    case VT_I2:
    case VT_UI2:
    // 4 bytes longs
    case VT_I4:
    case VT_UI4:
    case VT_INT:
    case VT_UINT:
    case VT_ERROR:
        return _T("int");

    // 4 byte floats
    case VT_R4:
    // 8 byte doubles
    case VT_R8:
    // decimals are converted from doubles too
    case VT_DECIMAL:
        return _T("double");
        
    case VT_BOOL:
        return _T("bool");
        
    case VT_DATE:
        return _T("wx.DateTime");
        
    case VT_BSTR:
        return _T("string");

    case VT_UNKNOWN:
        return _T("VT_UNKNOWN");
        
    case VT_DISPATCH: 
        return _T("VT_DISPATCH");

    case VT_EMPTY:
        return _T("VT_EMPTY");
        
    case VT_NULL:
        return _T("VT_NULL");
        
    case VT_VOID:
        return _T("VT_VOID");
        
    default:
        wxString msg;
        msg << _T("unsupported type ") << vt;
        return msg;
    }
}

%}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
%newgroup


%{
// A class derived from our wxActiveXWindow for the IE WebBrowser
// control that will serve as a base class for a Python
// implementation.  This is done so we can "eat our own dog food"
// and use a class at least mostly generated by genaxmodule, but
// also get some of the extra stuff like loading a document from
// a string or a stream, getting text contents, etc. that
// Lindsay's version gives us.
//

#include <wx/mstream.h>
#include <oleidl.h>
#include <winerror.h>
#include <exdispid.h>
#include <exdisp.h>
#include <olectl.h>
#include <Mshtml.h>
#include <sstream>

#include "IEHtmlStream.h"

class wxIEHtmlWindowBase : public wxActiveXWindow {
private:
    wxAutoOleInterface<IWebBrowser2>  m_webBrowser;

    DECLARE_ABSTRACT_CLASS(wxIEHtmlWindowBase);

public:

    wxIEHtmlWindowBase ( wxWindow* parent, const CLSID& clsId, wxWindowID id = -1,
                         const wxPoint& pos = wxDefaultPosition,
                         const wxSize& size = wxDefaultSize,
                         long style = 0,
                         const wxString& name = wxPyPanelNameStr)
        : wxActiveXWindow(parent, clsId, id, pos, size, style, name)
    {
        HRESULT hret;

        // Get IWebBrowser2 Interface
        hret = m_webBrowser.QueryInterface(IID_IWebBrowser2, m_ActiveX);
        wxASSERT(SUCCEEDED(hret));

        // web browser setup
        m_webBrowser->put_MenuBar(VARIANT_FALSE);
        m_webBrowser->put_AddressBar(VARIANT_FALSE);
        m_webBrowser->put_StatusBar(VARIANT_FALSE);
        m_webBrowser->put_ToolBar(VARIANT_FALSE);

        m_webBrowser->put_RegisterAsBrowser(VARIANT_TRUE);
        m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE);

        m_webBrowser->Navigate( L"about:blank", NULL, NULL, NULL, NULL );
    }


    void SetCharset(const wxString& charset)
    {
        HRESULT hret;
        
        // HTML Document ?
        IDispatch *pDisp = NULL;
        hret = m_webBrowser->get_Document(&pDisp);
        wxAutoOleInterface<IDispatch> disp(pDisp);

        if (disp.Ok())
        {
            wxAutoOleInterface<IHTMLDocument2> doc(IID_IHTMLDocument2, disp);
            if (doc.Ok())
                doc->put_charset((BSTR) (const wchar_t *) charset.wc_str(wxConvUTF8));
            //doc->put_charset((BSTR) wxConvUTF8.cMB2WC(charset).data());
        }
    }


    bool LoadString(const wxString& html)
    {
        char *data = NULL;
        size_t len = html.length();
        len *= sizeof(wxChar);
        data = (char *) malloc(len);
        memcpy(data, html.c_str(), len);
        return LoadStream(new wxOwnedMemInputStream(data, len));
    }

    
    bool LoadStream(IStreamAdaptorBase *pstrm)
    {
        // need to prepend this as poxy MSHTML will not recognise a HTML comment
        // as starting a html document and treats it as plain text
        // Does nayone know how to force it to html mode ?
#if wxUSE_UNICODE
        // TODO: What to do in this case???
#else
        pstrm->prepend = _T("<html>");
#endif

        // strip leading whitespace as it can confuse MSHTML
        wxAutoOleInterface<IStream> strm(pstrm);

        // Document Interface
        IDispatch *pDisp = NULL;
        HRESULT hret = m_webBrowser->get_Document(&pDisp);
        if (! pDisp)
            return false;
        wxAutoOleInterface<IDispatch> disp(pDisp);


        // get IPersistStreamInit
        wxAutoOleInterface<IPersistStreamInit>
            pPersistStreamInit(IID_IPersistStreamInit, disp);

        if (pPersistStreamInit.Ok())
        {
            HRESULT hr = pPersistStreamInit->InitNew();
            if (SUCCEEDED(hr))
                hr = pPersistStreamInit->Load(strm);

            return SUCCEEDED(hr);
        }
        else
            return false;
    }

    bool LoadStream(wxInputStream *is)
    {
        // wrap reference around stream
        IwxStreamAdaptor *pstrm = new IwxStreamAdaptor(is);
        pstrm->AddRef();

        return LoadStream(pstrm);
    }

    
    wxString GetStringSelection(bool asHTML)
    {
        wxAutoOleInterface<IHTMLTxtRange> tr(wxieGetSelRange(m_oleObject));
        if (! tr)
            return wxEmptyString;

        BSTR text = NULL;
        HRESULT hr = E_FAIL;
    
        if (asHTML)
            hr = tr->get_htmlText(&text);
        else
            hr = tr->get_text(&text);
        if (hr != S_OK)
            return wxEmptyString;

        wxString s = text;
        SysFreeString(text);

        return s;
    };

    wxString GetText(bool asHTML)
    {
        if (! m_webBrowser.Ok())
            return wxEmptyString;

        // get document dispatch interface
        IDispatch *iDisp = NULL;
        HRESULT hr = m_webBrowser->get_Document(&iDisp);
        if (hr != S_OK)
            return wxEmptyString;

        // Query for Document Interface
        wxAutoOleInterface<IHTMLDocument2> hd(IID_IHTMLDocument2, iDisp);
        iDisp->Release();

        if (! hd.Ok())
            return wxEmptyString;

        // get body element
        IHTMLElement *_body = NULL;
        hd->get_body(&_body);
        if (! _body)
            return wxEmptyString;
        wxAutoOleInterface<IHTMLElement> body(_body);

        // get inner text
        BSTR text = NULL;
        hr = E_FAIL;
    
        if (asHTML)
            hr = body->get_innerHTML(&text);
        else
            hr = body->get_innerText(&text);
        if (hr != S_OK)
            return wxEmptyString;

        wxString s = text;
        SysFreeString(text);

        return s;   
    }


//     void wxIEHtmlWin::SetEditMode(bool seton)
//     {
//         m_bAmbientUserMode = ! seton;
//         AmbientPropertyChanged(DISPID_AMBIENT_USERMODE);
//     };

//     bool wxIEHtmlWin::GetEditMode()
//     {
//         return ! m_bAmbientUserMode;
//     };
};

IMPLEMENT_ABSTRACT_CLASS( wxIEHtmlWindowBase, wxActiveXWindow );

%}


// we'll document it in the derived Python class
%feature("noautodoc") wxIEHtmlWindowBase;
%feature("noautodoc") wxIEHtmlWindowBase::SetCharset;
%feature("noautodoc") wxIEHtmlWindowBase::LoadString;
%feature("noautodoc") wxIEHtmlWindowBase::LoadStream;
%feature("noautodoc") wxIEHtmlWindowBase::GetStringSelection;
%feature("noautodoc") wxIEHtmlWindowBase::GetText;


MustHaveApp(wxIEHtmlWindowBase);

class wxIEHtmlWindowBase : public wxActiveXWindow {
public:
    %pythonAppend wxIEHtmlWindowBase    "self._setOORInfo(self)"

    wxIEHtmlWindowBase ( wxWindow* parent, const CLSID& clsId, wxWindowID id = -1,
                         const wxPoint& pos = wxDefaultPosition,
                         const wxSize& size = wxDefaultSize,
                         long style = 0,
                         const wxString& name = wxPyPanelNameStr);

    void SetCharset(const wxString& charset);
    bool LoadString(const wxString& html);
    bool LoadStream(wxInputStream *is);
    wxString GetStringSelection(bool asHTML);
    wxString GetText(bool asHTML);
};











#if 0
enum wxIEHtmlRefreshLevel
{
    wxIEHTML_REFRESH_NORMAL = 0,
    wxIEHTML_REFRESH_IFEXPIRED = 1,
    wxIEHTML_REFRESH_CONTINUE = 2,
    wxIEHTML_REFRESH_COMPLETELY = 3
};

DocStr(wxIEHtmlWin,
"");
class wxIEHtmlWin : public wxWindow 
{
public:
    %pythonAppend wxIEHtmlWin      "self._setOORInfo(self)"

    wxIEHtmlWin(wxWindow * parent, wxWindowID id = -1,
                const wxPoint& pos = wxDefaultPosition,
                const wxSize& size = wxDefaultSize,
                long style = 0,
                const wxString& name = wxPyPanelNameStr);

    void LoadUrl(const wxString& url);
    bool LoadString(wxString html);
    bool LoadStream(wxInputStream *is);

    %pythoncode { Navigate = LoadUrl }

    void SetCharset(wxString charset);
    void SetEditMode(bool seton);
    bool GetEditMode();
    wxString GetStringSelection(bool asHTML = false);
    wxString GetText(bool asHTML = false);

    bool GoBack();
    bool GoForward();
    bool GoHome();
    bool GoSearch();
    %name(RefreshPage)bool Refresh(wxIEHtmlRefreshLevel level);
    bool Stop();
};



%pythoncode {
wxEVT_COMMAND_MSHTML_BEFORENAVIGATE2  = RegisterActiveXEvent('BeforeNavigate2')
wxEVT_COMMAND_MSHTML_NEWWINDOW2       = RegisterActiveXEvent('NewWindow2')
wxEVT_COMMAND_MSHTML_DOCUMENTCOMPLETE = RegisterActiveXEvent('DocumentComplete')
wxEVT_COMMAND_MSHTML_PROGRESSCHANGE   = RegisterActiveXEvent('ProgressChange')
wxEVT_COMMAND_MSHTML_STATUSTEXTCHANGE = RegisterActiveXEvent('StatusTextChange')
wxEVT_COMMAND_MSHTML_TITLECHANGE      = RegisterActiveXEvent('TitleChange')

EVT_MSHTML_BEFORENAVIGATE2      = wx.PyEventBinder(wxEVT_COMMAND_MSHTML_BEFORENAVIGATE2, 1)
EVT_MSHTML_NEWWINDOW2           = wx.PyEventBinder(wxEVT_COMMAND_MSHTML_NEWWINDOW2, 1)
EVT_MSHTML_DOCUMENTCOMPLETE     = wx.PyEventBinder(wxEVT_COMMAND_MSHTML_DOCUMENTCOMPLETE, 1)
EVT_MSHTML_PROGRESSCHANGE       = wx.PyEventBinder(wxEVT_COMMAND_MSHTML_PROGRESSCHANGE, 1)
EVT_MSHTML_STATUSTEXTCHANGE     = wx.PyEventBinder(wxEVT_COMMAND_MSHTML_STATUSTEXTCHANGE, 1)
EVT_MSHTML_TITLECHANGE          = wx.PyEventBinder(wxEVT_COMMAND_MSHTML_TITLECHANGE, 1)
}

#endif

//---------------------------------------------------------------------------
// Include some extra Python code into the proxy module

%pythoncode "_activex_ex.py"

//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -