//////////////////////////////////////////////////////////////////////////////
// File:        sourceedit.h
// Purpose:     wxPackageSourceEditCtrl
// Author:      Francesco Montorsi
// Modified by:
// Created:     2006-06-08
// RCS-ID:      $Id: sourceeditctrl.h,v 1.1.1.1 2006/12/12 09:41:04 frm Exp $
// Copyright:  (c) Francesco Montorsi
// Licence:     wxWidgets licence
//////////////////////////////////////////////////////////////////////////////

#ifndef _PMSOURCEEDIT_H_
#define _PMSOURCEEDIT_H_

// includes
#include "wx/stc/stc.h"

// currently this control is used for read only
#define ENABLE_EDIT_MODE            0

// constants
enum wxPackageSourceEditCtrlId
{
    // edit menu
    ID_SEC_INDENTINC,
    ID_SEC_INDENTRED,
    ID_SEC_FINDNEXT,
    ID_SEC_REPLACE,
    ID_SEC_REPLACENEXT,

    // view menu
    ID_SEC_DISPLAYEOL,
    ID_SEC_INDENTGUIDE,
    ID_SEC_LINENUMBER,
    ID_SEC_LONGLINEON,
    ID_SEC_WHITESPACE,
    ID_SEC_WRAPMODEON
};


// ----------------------------------------------------------------------------
// wxPackageSourceEditCtrl
// ----------------------------------------------------------------------------

class wxPackageSourceEditCtrl : public wxStyledTextCtrl
{
public:
    wxPackageSourceEditCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
                            const wxPoint &pos = wxDefaultPosition,
                            const wxSize &size = wxDefaultSize,
                            long style = wxSUNKEN_BORDER|wxVSCROLL)
    {
        Create(parent, id, pos, size, style);
    }

    bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
                const wxPoint &pos = wxDefaultPosition,
                const wxSize &size = wxDefaultSize,
                long style = wxSUNKEN_BORDER|wxVSCROLL);

    virtual ~wxPackageSourceEditCtrl() {}


public:     // public API

    void UpdateSource(const wxString &source)
    {
        SetReadOnly(false);
        SetText(source);
#if !ENABLE_EDIT_MODE
        SetReadOnly(true);
#endif
        UpdateScrollWidth();
    }

    void SetDefaultStyle();
    void UpdateScrollWidth();
    void EnableWrapMode(bool enable = true);

public:    // event handlers

    // edit
    void OnEditRedo(wxCommandEvent &event);
    void OnEditUndo(wxCommandEvent &event);
    void OnEditClear(wxCommandEvent &event);
    void OnEditCut(wxCommandEvent &event);
    void OnEditCopy(wxCommandEvent &event);
    void OnEditPaste(wxCommandEvent &event);

    // find
    void OnFind(wxCommandEvent &event);
    void OnFindNext(wxCommandEvent &event);
    void OnReplace(wxCommandEvent &event);
    void OnReplaceNext(wxCommandEvent &event);
    void OnBraceMatch(wxCommandEvent &event);
    void OnGoto(wxCommandEvent &event);
    void OnEditIndentInc(wxCommandEvent &event);
    void OnEditIndentRed(wxCommandEvent &event);
    void OnEditSelectAll(wxCommandEvent &event);
    void OnEditSelectLine(wxCommandEvent &event);

    // view
    void OnHilightLang(wxCommandEvent &event);
    void OnDisplayEOL(wxCommandEvent &event);
    void OnIndentGuide(wxCommandEvent &event);
    void OnLineNumber(wxCommandEvent &event);
    void OnLongLineOn(wxCommandEvent &event);
    void OnWhiteSpace(wxCommandEvent &event);
    void OnFoldToggle(wxCommandEvent &event);
    void OnSetOverType(wxCommandEvent &event);
    void OnSetReadOnly(wxCommandEvent &event);
    void OnWrapmodeOn(wxCommandEvent &event);
    void OnUseCharset(wxCommandEvent &event);

    // stc
    void OnMarginClick(wxStyledTextEvent &event);
    void OnCharAdded (wxStyledTextEvent &event);

protected:
    // the font in use
    wxFont m_font;

private:
    DECLARE_EVENT_TABLE()
};

#endif // _PMSOURCEEDIT_H_
