~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/PythonPlugins/PythonInterpreter/ShellCtrlBase.h

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef SHELLCTRL_H
 
2
#define SHELLCTRL_H
 
3
 
 
4
#include <map>
 
5
 
 
6
 
 
7
#include <wx/wxprec.h>
 
8
 
 
9
#ifndef WX_PRECOMP
 
10
    #include <wx/wx.h>
 
11
#endif
 
12
 
 
13
 
 
14
#include <wx/process.h>
 
15
#include <wx/aui/aui.h>
 
16
#include <sdk.h>
 
17
 
 
18
// CLASSES DEFINED IN THIS LIBRARY
 
19
class ShellManager; //Manages the collection of Shell Control Widgets allowing user interaction with external processes within a tabbed notepage - usually the main app (or some plugin) will declare a global instance of this manager. See the full declaration below for more detail
 
20
class ShellCtrlBase; //The manager manages a set of Shell Control widgets that redirect I/O from an external process - ShellCtrlBase is an abstract base class allowing the developer to create custom controls for handling I/O from their process. Note that "process" is not defined here, it could be a new thread, an external program, a server connection etc
 
21
class ShellRegInfo; //Every custom shell control must provide basic info to a global registry
 
22
class ShellRegistry; //The global registry stores the info for all known custom shell controls
 
23
template<class T> class ShellCtrlRegistrant; //The developer makes their custom Shell Control classes available to the manager (and the main application) by creating an instance of this template class
 
24
 
 
25
typedef ShellCtrlBase*(*fnCreate)(wxWindow*, int, const wxString &, ShellManager *); //typedef defining function to create a custom shell control widget
 
26
typedef void(*fnFree)(ShellCtrlBase*); //typedef defining function to free a custom shell control widget
 
27
 
 
28
//Every type of shell control has the following registration info
 
29
struct ShellRegInfo
 
30
{
 
31
//    wxString name; //unique name of the type
 
32
    fnCreate create; //static function call needed to create instance on the heap
 
33
    fnFree free; //static function call needed to free instance
 
34
};
 
35
 
 
36
// Before shells can be used they must be registered in a ShellRegistry, which
 
37
// represents a collection of registered shell controls. One global instance is created
 
38
// within this library
 
39
class ShellRegistry
 
40
{
 
41
public:
 
42
    bool Register(const wxString &name, fnCreate create, fnFree free); //register/deregister are called by the plugin registrant instance
 
43
    bool Deregister(const wxString &name);
 
44
    ShellCtrlBase *CreateControl(const wxString &type,wxWindow* parent, int id, const wxString &windowname, ShellManager *shellmgr=NULL);
 
45
    void FreeControl(ShellCtrlBase *sh); //TODO: Don't think this is necessary?
 
46
private:
 
47
//    std::vector<ShellRegInfo> m_reginfo;
 
48
    std::map<wxString, ShellRegInfo> m_reginfo;
 
49
};
 
50
 
 
51
extern ShellRegistry& GlobalShellRegistry(); //defined in shellctrlbase.cpp, but accessible to all linking libraries
 
52
 
 
53
// every library that creates a new shell control must create an instance of this class with the type of their control as the template paramater T. This will add the new class to the registry of shell controls and the needed functions to create new instances
 
54
template<class T> class ShellCtrlRegistrant
 
55
{
 
56
    public:
 
57
        /// @param name The name of the ShellCtrl.
 
58
        ShellCtrlRegistrant(const wxString& name)
 
59
        {
 
60
            m_name=name;
 
61
            GlobalShellRegistry().Register(name, &Create, &Free);
 
62
        }
 
63
        ~ShellCtrlRegistrant()
 
64
        {
 
65
            GlobalShellRegistry().Deregister(m_name);
 
66
        }
 
67
        static ShellCtrlBase* Create(wxWindow* parent, int id, const wxString &windowname, ShellManager *shellmgr=NULL) //allocates new shell control object on heap
 
68
        {
 
69
            return new T(parent, id, windowname, shellmgr);
 
70
        }
 
71
 
 
72
        static void Free(ShellCtrlBase* sh) // deletes object from heap
 
73
        {
 
74
            delete sh;
 
75
        }
 
76
        wxString m_name;
 
77
 
 
78
//        static void SDKVersion(int* major, int* minor, int* release)
 
79
//        {
 
80
//            if (major) *major = PLUGIN_SDK_VERSION_MAJOR;
 
81
//            if (minor) *minor = PLUGIN_SDK_VERSION_MINOR;
 
82
//            if (release) *release = PLUGIN_SDK_VERSION_RELEASE;
 
83
//        }
 
84
};
 
85
 
 
86
 
 
87
 
 
88
// This is the shell control base class
 
89
// All controls derives from a basic wxPanel
 
90
// The control must offer services to create and destroy underlying processes
 
91
// terminal controls sit inside a tabbed panel managed by the Shell Manager
 
92
class ShellCtrlBase : public wxPanel //TODO: make wxPanel a member, not a base??
 
93
{
 
94
    public:
 
95
        ShellCtrlBase():wxPanel() {m_id=-1;}
 
96
        ShellCtrlBase(wxWindow* parent, int id, const wxString &name, ShellManager *shellmgr=NULL);
 
97
        virtual ~ShellCtrlBase() {}
 
98
 
 
99
        // Every shell control widget must override the following
 
100
        virtual long LaunchProcess(const wxString &processcmd, const wxArrayString &options)=0;
 
101
//        virtual void KillWindow()=0; // manager may destroy the window, but will call this before doing so
 
102
        virtual void KillProcess()=0; //use this to respond to ShellManager request to kill the process
 
103
        virtual void SyncOutput(int maxchars=1000)=0; //use this to respond to ShellManager request to gather output from the running process for display in the panel
 
104
 
 
105
        virtual bool IsDead()=0;
 
106
        wxString GetName() {return m_name;}
 
107
        void SetName(const wxString &name) {m_name=name;}
 
108
    protected:
 
109
        wxString m_name;
 
110
        ShellManager *m_shellmgr;
 
111
        int m_id;
 
112
//    DECLARE_DYNAMIC_CLASS(ShellCtrlBase)
 
113
//    DECLARE_EVENT_TABLE()
 
114
};
 
115
 
 
116
 
 
117
BEGIN_DECLARE_EVENT_TYPES()
 
118
DECLARE_LOCAL_EVENT_TYPE(wxEVT_SHELL_ADD_CLICKED, -1)
 
119
END_DECLARE_EVENT_TYPES()
 
120
 
 
121
 
 
122
class ShellManager : public wxPanel
 
123
{
 
124
    friend class ShellCtrlBase;
 
125
    public:
 
126
        ShellManager(wxWindow* parent);
 
127
        ~ShellManager(); //virtual??
 
128
        long LaunchProcess(const wxString &processcmd, const wxString &name, const wxString &type, const wxArrayString &options);
 
129
        void KillProcess(int id);
 
130
        void KillWindow(int id);
 
131
        void RemoveDeadPages();
 
132
        ShellCtrlBase *GetPage(size_t i);
 
133
        ShellCtrlBase *GetPage(const wxString &name);
 
134
        void OnShellTerminate(ShellCtrlBase *term);
 
135
        int NumAlive();
 
136
    private:
 
137
        //Responders to standard wxWidgets Messages
 
138
        void OnUserInput(wxKeyEvent& ke);
 
139
        void OnPollandSyncOutput(wxTimerEvent& te);
 
140
        void OnPageClosing(wxAuiNotebookEvent& event);
 
141
        void OnPageChanging(wxAuiNotebookEvent& event);
 
142
        bool QueryClose(ShellCtrlBase* sh);
 
143
        //Responders to friend class ShellCtrlBase
 
144
        size_t GetTermNum(ShellCtrlBase *term);
 
145
    protected:
 
146
        wxTimer m_synctimer;
 
147
        wxAuiNotebook *m_nb;
 
148
    DECLARE_EVENT_TABLE()
 
149
};
 
150
 
 
151
 
 
152
 
 
153
#endif // SHELLCTRL_H