///////////////////////////////////////////////////////////////////////////////
// Name:        opteditctrl.h
// Purpose:     wxOptionEditorCtrl definition
// Author:      Francesco Montorsi
// Modified by:
// Created:     10/7/2006
// RCS-ID:      $Id: opteditctrl.h,v 1.2 2007/02/01 20:11:26 frm Exp $
// Copyright:   (c) Francesco Montorsi
// Licence:     wxWindows licence
///////////////////////////////////////////////////////////////////////////////

#ifndef _WX_OPTIONEDITOR_H_
#define _WX_OPTIONEDITOR_H_

// includes needed by wxPropertyGrid header
#include "wx/window.h"
#include "wx/bitmap.h"
#include "wx/dcclient.h"
#include <wx/scrolwin.h>

#include "wx/propgrid/propgrid.h"
#include "wxp/package.h"
class wxConfigBase;


// ----------------------------------------------------------------------------
// wxOptionEditorCtrl - a control which allows the user to edit package options
// ----------------------------------------------------------------------------

class wxOptionEditorCtrl : public wxPropertyGrid
{
    DECLARE_DYNAMIC_CLASS( wxOptionEditorCtrl )
    DECLARE_EVENT_TABLE()

public:
    wxOptionEditorCtrl() {}

    wxOptionEditorCtrl(wxWindow* parent, wxWindowID id,
                       const wxPoint& pos = wxDefaultPosition,
                       const wxSize& size = wxDefaultSize,
                       long style = 0,
                       const wxString& name = wxT("wxOptionEditorCtrl"))
        { Create(parent, id, pos, size, style, name); }

    bool Create(wxWindow* parent, wxWindowID id,
                         const wxPoint& pos = wxDefaultPosition,
                         const wxSize& size = wxDefaultSize,
                         long style = 0,
                         const wxString& name = wxT("wxOptionEditorCtrl"));


public:     // wxOptionEditorCtrl-specific API

    //! Loads from given path the strings previously saved by a #Save call.
    //! All previous contents are cleared.
    bool Load(wxConfigBase *, const wxString &path);

    //! Saves in given path all the currently contained strings.
    //! Order will be preserved by #Load.
    void Save(wxConfigBase *, const wxString &path) const;

    //! Sets the options associated to this control and the stage it controls.
    //! Only the options which can be used with the given format & given stage
    //! are shown. The value wxPCF_INVALID means that the check on the compiler
    //! is skipped.
    //! Remember to call TransferDataToWindow() after calling all Set*() functions!
    bool SetOptions(const wxPackageCommandOptionArray &opt)
        { m_arr = opt; m_arr.SetDirty(false); return true; }

    // Remember to call TransferDataToWindow() after calling all Set*() functions!

    void SetBuildSystemType(wxPackageBuildSystemType type)
        { m_buildsys = type; }
    void SetStages(long stages)
        { m_stages = stages; }
    void SetCompilerFormats(long formats)
        { m_formats = formats; }

    //! Returns all options with the values currently set in this control.
    //! Note that if you modify the returned array, in order to make the
    //! changes appear in the control you have to call #TransferDataToWindow().
    wxPackageCommandOptionArray &GetOptions()
        { return m_arr; }

    //! Returns true if the options have been changed by the user since last
    //! call to SetOptions().
    bool IsDirty() const
        { return m_arr.IsDirty(); }

    bool TransferDataFromWindow();
    bool TransferDataToWindow();

public:     // event handlers

    void OnOptionChanged(wxPropertyGridEvent &ev);

protected:
    wxPackageCommandOptionArray m_arr;

    // filters of the m_arr options
    wxPackageBuildSystemType m_buildsys;
    long m_stages;
    long m_formats;
};


// ----------------------------------------------------------------------------
// wxEVT_COMMAND_OPTIONS_CHANGED
// ----------------------------------------------------------------------------

BEGIN_DECLARE_EVENT_TYPES()
    //DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP, wxEVT_COMMAND_FILTER_PACKAGES, 1000000)
    DECLARE_EVENT_TYPE(wxEVT_COMMAND_OPTIONS_CHANGED, 3000000)
END_DECLARE_EVENT_TYPES()

#define EVT_OPTIONS_CHANGED(id, fn) \
    wx__DECLARE_EVT1(wxEVT_COMMAND_OPTIONS_CHANGED, id, wxCommandEventHandler(fn))


#endif
    // _WX_OPTIONEDITOR_H_

