14
#include <wx/process.h>
15
#include <wx/aui/aui.h>
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
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
28
//Every type of shell control has the following registration info
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
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
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?
47
// std::vector<ShellRegInfo> m_reginfo;
48
std::map<wxString, ShellRegInfo> m_reginfo;
51
extern ShellRegistry& GlobalShellRegistry(); //defined in shellctrlbase.cpp, but accessible to all linking libraries
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
57
/// @param name The name of the ShellCtrl.
58
ShellCtrlRegistrant(const wxString& name)
61
GlobalShellRegistry().Register(name, &Create, &Free);
63
~ShellCtrlRegistrant()
65
GlobalShellRegistry().Deregister(m_name);
67
static ShellCtrlBase* Create(wxWindow* parent, int id, const wxString &windowname, ShellManager *shellmgr=NULL) //allocates new shell control object on heap
69
return new T(parent, id, windowname, shellmgr);
72
static void Free(ShellCtrlBase* sh) // deletes object from heap
78
// static void SDKVersion(int* major, int* minor, int* release)
80
// if (major) *major = PLUGIN_SDK_VERSION_MAJOR;
81
// if (minor) *minor = PLUGIN_SDK_VERSION_MINOR;
82
// if (release) *release = PLUGIN_SDK_VERSION_RELEASE;
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??
95
ShellCtrlBase():wxPanel() {m_id=-1;}
96
ShellCtrlBase(wxWindow* parent, int id, const wxString &name, ShellManager *shellmgr=NULL);
97
virtual ~ShellCtrlBase() {}
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
105
virtual bool IsDead()=0;
106
wxString GetName() {return m_name;}
107
void SetName(const wxString &name) {m_name=name;}
110
ShellManager *m_shellmgr;
112
// DECLARE_DYNAMIC_CLASS(ShellCtrlBase)
113
// DECLARE_EVENT_TABLE()
117
BEGIN_DECLARE_EVENT_TYPES()
118
DECLARE_LOCAL_EVENT_TYPE(wxEVT_SHELL_ADD_CLICKED, -1)
119
END_DECLARE_EVENT_TYPES()
122
class ShellManager : public wxPanel
124
friend class ShellCtrlBase;
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);
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);
148
DECLARE_EVENT_TABLE()
153
#endif // SHELLCTRL_H