/////////////////////////////////////////////////////////////////////////////
// Name:        webbrowser.h
// Purpose:     A browser window class
// Author:      Julian Smart
// Modified by: Francesco Montorsi
// Created:     2003-12-03
// RCS-ID:      $Id: webbrowser.h,v 1.1.1.1 2006/12/12 09:40:42 frm Exp $
// Copyright:   (c) Julian Smart
// Licence:     wxWidgets license
/////////////////////////////////////////////////////////////////////////////

#ifndef _wx_WEBBROWSER_H_
#define _wx_WEBBROWSER_H_

#include "wx/window.h"
#include "wx/textctrl.h"

class wxURLTextCtrl;
class wxToolBarBase;

#ifdef __WXMAC__
    class wxWebKitCtrl;
    class wxWebKitStateChangedEvent;
#elif defined(__WXMSW__)
    class wxIEHtmlWin;
    class wxActiveXEvent;
#endif

/*!
 * wxWebBrowserWindow paints a background and holds an embedded
 * HTML window.
 */

class wxWebBrowserWindow: public wxWindow
{
    DECLARE_CLASS(wxWebBrowserWindow)

public:
    wxWebBrowserWindow(wxWindow* parent, wxWindowID id,
       const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, 
       long style = wxCLIP_CHILDREN);

    void OnSize(wxSizeEvent& event);
    void OnIdle(wxIdleEvent& event);
    void OnEraseBackground(wxEraseEvent& event);

#ifdef __WXMAC__
    wxWebKitCtrl* GetBrowser() const { return m_browserWindow; }
    void OnStateChanged(wxWebKitStateChangedEvent& myEvent);
#elif defined(__WXMSW__)
    void OnMSHTMLBeforeNavigate(wxActiveXEvent& event);
    wxIEHtmlWin* GetBrowser() const { return m_browserWindow; }
#endif

    // Prepend http:// if necessary
    void MakeRealURL(wxString& url);

    /// Get the URL text control
    wxURLTextCtrl* GetURLTextCtrl() const { return m_urlTextCtrl; }

    /// Get the toolbar
    wxToolBarBase* GetToolBar() const { return m_toolBar; }

    /// Get/set custom search engine
    void SetSearchEngine(const wxString& searchEngine) { m_searchEngine = searchEngine; }
    const wxString& GetSearchEngine() const { return m_searchEngine; }

    /// Get/set initial page
    void SetInitialPage(const wxString& initialPage) { m_initialPage = initialPage; }
    const wxString& GetInitialPage() const { return m_initialPage; }

    /// Create windows. Must be called outside of ctor for virtual functions
    /// to work.
    virtual bool CreateWindows();

    /// Add toolbar tools
    virtual void AddToolBarTools(wxToolBarBase* toolBar);

    /// Add the URL control (usually the last one)
    virtual void AddURLControl(wxToolBarBase* toolBar);

    /// Create an object of the appropriate class
    virtual wxToolBarBase* CreateToolBarObject();

    /// Load a page
    virtual bool LoadPage(const wxString& url);

    /// Create the toolbar
    virtual bool CreateToolbar();

    /// Load the initial page
    virtual void LoadInitialPage();

    /// View in a separate web browser
    virtual void ViewInBrowser(const wxString& WXUNUSED(url)) {}

// Command handlers

    void OnBack(wxCommandEvent& event);
    void OnForward(wxCommandEvent& event);
    void OnHome(wxCommandEvent& event);
    void OnReload(wxCommandEvent& event);
    void OnOpenURL(wxCommandEvent& event);
    void OnStop(wxCommandEvent& event);
    void OnSearch(wxCommandEvent& event);
    void OnURLEnter(wxCommandEvent& event);
    void OnNewURLScrap(wxCommandEvent& event);
    void OnNewWindow(wxCommandEvent& event);

    void OnToolEnter(wxCommandEvent& event);

protected:
#ifdef __WXMAC__
    wxWebKitCtrl*   m_browserWindow;
#elif defined(__WXMSW__)
    wxIEHtmlWin*    m_browserWindow;
#else
    wxWindow*       m_browserWindow;
#endif

    wxToolBarBase*  m_toolBar;
    wxURLTextCtrl*  m_urlTextCtrl;
    wxString        m_lastUrl;
    wxString        m_searchEngine;
    wxString        m_initialPage;

DECLARE_EVENT_TABLE()
};

#define wxID_BROWSER_GO_HOME    6000
#define wxID_BROWSER_GO_BACK    6001
#define wxID_BROWSER_GO_FORWARD 6002
#define wxID_BROWSER_STOP       6003
#define wxID_BROWSER_OPEN_URL   6004
#define wxID_BROWSER_REFRESH    6005
#define wxID_BROWSER_URL_TEXT   6006
#define wxID_BROWSER_SEARCH     6007
#define wxID_BROWSER_URL_CTRL   6008
#define wxID_BROWSER_CTRL       6009
#define wxID_BROWSER_NEW_WINDOW 6010

/*
 * wxURLTextCtrl: a kind of wxTextCtrl (or wxRichEditCtrl under Windows)
 */

class wxURLTextCtrl: public wxTextCtrl
{
    DECLARE_CLASS(wxURLTextCtrl)

public:
    wxURLTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString,
       const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, 
       long style = wxTE_PROCESS_ENTER);

    void OnChar(wxKeyEvent& event);
    void OnSetFocus(wxFocusEvent& event);
    void OnTextUpdated(wxCommandEvent& event);

protected:
    DECLARE_EVENT_TABLE()
};

#endif
    // _wx_WEBBROWSER_H_

