%module{Wx};

##/////////////////////////////////////////////////////////////////////////////
##// Name:        webview.h
##// Purpose:     interface of wxWebView
##// Author:      wxWidgets team
##// RCS-ID:      $Id$
##// Licence:     wxWindows licence
##/////////////////////////////////////////////////////////////////////////////

#if wxUSE_WEBVIEW

%loadplugin{build::Wx::XSP::Overload};
%loadplugin{build::Wx::XSP::Enum};
%loadplugin{build::Wx::XSP::Event};

%EventExportTag{webview};
%EnumExportTag{webview};

%Event{%EVT_WEBVIEW_NAVIGATING(id, func)%}
      {wxEVT_COMMAND_WEBVIEW_NAVIGATING};
%Event{%EVT_WEBVIEW_NAVIGATED(id, func)%}
      {wxEVT_COMMAND_WEBVIEW_NAVIGATED};
%Event{%EVT_WEBVIEW_LOADED(id, func)%}
      {wxEVT_COMMAND_WEBVIEW_LOADED};
%Event{%EVT_WEBVIEW_ERROR(id, func)%}
      {wxEVT_COMMAND_WEBVIEW_ERROR};
%Event{%EVT_WEBVIEW_NEWWINDOW(id, func)%}
      {wxEVT_COMMAND_WEBVIEW_NEWWINDOW};
%Event{%EVT_WEBVIEW_TITLE_CHANGED(id, func)%}
      {wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED};      


enum wxWebViewZoom
{
    wxWEBVIEW_ZOOM_TINY,
    wxWEBVIEW_ZOOM_SMALL,
    wxWEBVIEW_ZOOM_MEDIUM,
    wxWEBVIEW_ZOOM_LARGE,
    wxWEBVIEW_ZOOM_LARGEST
};

enum wxWebViewZoomType
{
    wxWEBVIEW_ZOOM_TYPE_LAYOUT,
    wxWEBVIEW_ZOOM_TYPE_TEXT
};

enum wxWebViewNavigationError
{
    wxWEBVIEW_NAV_ERR_CONNECTION,
    wxWEBVIEW_NAV_ERR_CERTIFICATE,
    wxWEBVIEW_NAV_ERR_AUTH,
    wxWEBVIEW_NAV_ERR_SECURITY,
    wxWEBVIEW_NAV_ERR_NOT_FOUND,
    wxWEBVIEW_NAV_ERR_REQUEST,
    wxWEBVIEW_NAV_ERR_USER_CANCELLED,
    wxWEBVIEW_NAV_ERR_OTHER
};

enum wxWebViewReloadFlags
{
    wxWEBVIEW_RELOAD_DEFAULT,
    wxWEBVIEW_RELOAD_NO_CACHE
};

enum wxWebViewFindFlags
{
    wxWEBVIEW_FIND_WRAP,
    wxWEBVIEW_FIND_ENTIRE_WORD,
    wxWEBVIEW_FIND_MATCH_CASE,
    wxWEBVIEW_FIND_HIGHLIGHT_RESULT,
    wxWEBVIEW_FIND_BACKWARDS,
    wxWEBVIEW_FIND_DEFAULT
};

%name{Wx::WebViewHistoryItem} class wxWebViewHistoryItem
{
    
%{
static void
wxWebViewHistoryItem::CLONE()
  CODE:
    wxPli_thread_sv_clone( aTHX_ CLASS, (wxPliCloneSV)wxPli_detach_object );
%}

public:

    wxWebViewHistoryItem(const wxString& url, const wxString& title);
    
    ~wxWebViewHistoryItem()
        %code%{  wxPli_thread_sv_unregister( aTHX_ "Wx::WebViewHistoryItem", THIS, ST(0) );
                 delete THIS;
               %};    
    
    wxString GetUrl();
    
    wxString GetTitle();
};

%name{Wx::WebViewHandler} class wxWebViewHandler
{
public:

    virtual wxFSFile* GetFile(const wxString &uri);

    virtual wxString GetName() const;
};

%name{Wx::WebView} class wxWebView : public %name{Wx::Control} wxControl
{
public:

    static wxWebView* NewDefault(const wxString& backend = wxWebViewBackendDefault)
        %code{% RETVAL = wxWebView::New( backend ); %}
        %postcall{% wxPli_create_evthandler( aTHX_ RETVAL, "Wx::WebView" ); %};
    
    static wxWebView* New(wxWindow* parent,
            wxWindowID id,
            const wxString& url = wxWebViewDefaultURLStr,
            const wxPoint& pos = wxDefaultPosition,
            const wxSize& size = wxDefaultSize,
            const wxString& backend = wxWebViewBackendDefault,
            long style = 0,
            const wxString& name = wxWebViewNameStr)
            %postcall{% wxPli_create_evthandler( aTHX_ RETVAL, "Wx::WebView" ); %};
   
    virtual bool Create(wxWindow* parent,
                        wxWindowID id,
                        const wxString& url = wxWebViewDefaultURLStr,
                        const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxDefaultSize,
                        long style = 0,
                        const wxString& name = wxWebViewNameStr);
    
    virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT);
    
    virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT);
    
    virtual void* GetNativeBackend() const;

    virtual wxString GetCurrentTitle() const;
    
    virtual wxString GetCurrentURL() const;
    
    virtual wxString GetPageSource() const;
  
    virtual wxString GetPageText() const;
    
    virtual bool IsBusy() const;

    virtual bool IsEditable() const;

    virtual void LoadURL(const wxString& url);

    virtual void Print();
 
    /* TODO : IMP  virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0; */
    
    virtual void RunScript(const wxString& javascript);
    
    virtual void SetEditable(bool enable = true);

    virtual void SetPage(const wxString& html, const wxString& baseUrl);

    %name{SetPageFH} virtual void SetPage(SV* fh, wxString baseUrl)
        %code{% wxInputStream* stream = wxPliInputStream_ctor( fh );
                THIS->SetPage( *stream, baseUrl );
                delete stream;
                %};

    virtual void Stop();

    virtual bool CanCopy() const;

    virtual bool CanCut() const;

    virtual bool CanPaste() const;

    virtual void Copy();

    virtual void Cut();

    virtual void Paste();

    virtual bool CanGoBack();

    virtual bool CanGoForward() const;

    virtual void ClearHistory();
    
    virtual void EnableHistory(bool enable = true);

    
%{

void
wxWebView::GetBackwardHistory()
  PPCODE:
    wxVector<wxSharedPtr<wxWebViewHistoryItem> > back = THIS->GetBackwardHistory();
    size_t num = back.size();
    EXTEND( SP, (IV)num );
    for( size_t i = 0; i < num; ++i )
    {
        PUSHs( wxPli_non_object_2_sv( aTHX_ sv_newmortal(),
                                      new wxWebViewHistoryItem(
                                          back[i]->GetUrl(), back[i]->GetTitle()
                                          ),
                                      "Wx::WebViewHistoryItem" ) );
    }


void
wxWebView::GetForwardHistory()
  PPCODE:
    wxVector<wxSharedPtr<wxWebViewHistoryItem> > forward = THIS->GetForwardHistory();
    size_t num = forward.size();
    EXTEND( SP, (IV)num );
    for( size_t i = 0; i < num; ++i )
    {
        PUSHs( wxPli_non_object_2_sv( aTHX_ sv_newmortal(),
                                      new wxWebViewHistoryItem(
                                          forward[i]->GetUrl(), forward[i]->GetTitle()
                                          ),
                                      "Wx::WebViewHistoryItem" ) );
    }

%}    

    virtual void GoBack();

    virtual void GoForward();

    /* not quite the standard implementation but it makes
      wxWebViewHistoryItem simpler */
      
    virtual void LoadHistoryItem( wxWebViewHistoryItem* item )
        %code{% THIS->LoadURL( item->GetUrl() ); %};
    
    virtual void ClearSelection();
   
    virtual void DeleteSelection();
 
    virtual wxString GetSelectedSource() const;
  
    virtual wxString GetSelectedText() const;

    virtual bool HasSelection() const;

    virtual void SelectAll();

    virtual bool CanRedo() const;

    virtual bool CanUndo() const;

    virtual void Redo();

    virtual void Undo();

    virtual bool CanSetZoomType(wxWebViewZoomType type) const;

    virtual wxWebViewZoom GetZoom() const;

    virtual wxWebViewZoomType GetZoomType() const;

    virtual void SetZoom(wxWebViewZoom zoom);

    virtual void SetZoomType(wxWebViewZoomType zoomType);
};


%name{Wx::WebViewEvent} class wxWebViewEvent : public %name{Wx::NotifyEvent} wxNotifyEvent
{
public:
    
    %name{newDefault} wxWebViewEvent() %Overload;
    
    %name{newFull} wxWebViewEvent(wxEventType type, int id, const wxString& href,
                   const wxString& target) %Overload;

    const wxString& GetTarget() const;
    
    const wxString& GetURL() const;
};


%name{Wx::WebViewArchiveHandler} class wxWebViewArchiveHandler : public %name{Wx::WebViewHandler} wxWebViewHandler
{
public:
    
    wxWebViewArchiveHandler(const wxString& scheme);
    
    virtual wxFSFile* GetFile(const wxString &uri);
};

#endif

