]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUITextEditor.h
9c0d0d5264fdd98c0dd3505c7d301d70a1d394bd
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkWxGUITextEditor.h,v $
5   Language:  C++
6   Date:      $Date: 2008/03/25 15:47:54 $
7   Version:   $Revision: 1.4 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*//**
18  * \brief Short description in one line
19  * 
20  * Long description which 
21  * can span multiple lines
22  */
23 /**
24  * \file 
25  * \brief 
26  */
27 /**
28  * \class bbtk::
29  * \brief 
30  */
31
32
33 #ifdef _USE_WXWIDGETS_
34
35         
36 #ifndef __bbtkWxGUITextEditor_h__
37 #define __bbtkWxGUITextEditor_h__
38
39
40 #include "bbtkWx.h"
41
42 #include "bbtkInterpreter.h"
43 #include <wx/splitter.h>
44 #include <wx/aui/aui.h>
45
46 #include "bbtkWxGUICommand.h"
47
48 namespace bbtk
49 {
50
51   class WxTextCtrlGettingKeyEvents;
52   class WxGUITextEditor;
53  
54
55   /// Abstract class which defines the callbacks invoked by WxGUITextEditor
56   class BBTK_EXPORT WxGUITextEditorUser
57   {
58   public:
59     WxGUITextEditorUser() {}
60     ~WxGUITextEditorUser() {}
61     /// Callback invoked when the 'run' button is pressed
62     virtual void WxGUITextEditorRun() {}
63   };
64
65   //================================================================
66   class WxGUITextEditorPage : public wxPanel
67   {
68   public:
69     WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
70     ~WxGUITextEditorPage();
71
72     void SetPageName(const std::string& name) { mName = name; }
73     const std::string& GetPageName() const { return mName; }
74
75     bool AskFilename() const { return mAskFilename; }
76     void SetAskFilename(bool a) { mAskFilename=a; }
77
78     WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
79
80     void Load(const std::string& filename);
81     void Save(const std::string& filter);
82
83     bool IsModified(); //{ return mwxInputText->IsModified(); }
84    
85     std::string GetText();
86
87   private:
88     WxGUITextEditor* mEditor;
89     WxTextCtrlGettingKeyEvents* mwxInputText;
90     wxTextAttr* mwxInputTextAttr;
91     std::string mName;
92     bool mAskFilename;
93
94     /*
95     enum
96     {
97       ID_InputText
98     };
99     */
100     //DECLARE_EVENT_TABLE();
101
102   } ;
103   //================================================================
104
105
106
107   /// A text editor panel
108   class BBTK_EXPORT WxGUITextEditor : public wxPanel
109   {
110   public:
111     WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 );
112     ~WxGUITextEditor();
113
114     void OnKeyDown(wxKeyEvent& event);
115     void OnKeyUp(wxKeyEvent& event);
116
117     void OnButtonNew(wxCommandEvent& event);
118     void OnButtonOpen(wxCommandEvent& event);
119     void OnButtonClose(wxCommandEvent& event);
120     void OnButtonSave(wxCommandEvent& event);
121     void OnButtonSaveAs(wxCommandEvent& event);
122     void OnButtonRun(wxCommandEvent& event);
123     //    void OnButtonQuit(wxCommandEvent& event);
124     void OnPageClose(wxAuiNotebookEvent& evt);
125
126     void New();
127     void Open();
128     void Open(const std::string& filename);
129     void SaveCurrentPage();
130     bool CloseCurrentPage();
131     bool CloseAllPages();
132     //   void Run();
133     //    void Quit();
134
135     void HighlightSyntax();
136     void UpdateInfo();
137
138     void NewPage(const std::string& filename);
139     WxGUITextEditorPage* GetCurrentPage();
140     void FocusOnCurrentPage();
141
142     void SetFileNameFilter(const std::string& filter)
143     { mFileNameFilter = filter; }
144
145   private:
146     WxGUITextEditorUser* mUser;
147
148     wxAuiManager m_mgr;
149     wxAuiNotebook* mwxNotebook;
150  
151     //   Interpreter* mInterpreter;
152     //    wxSplitterWindow* mwxSplit;
153
154     wxButton *  mwxButtonNew; 
155     wxButton *  mwxButtonOpen; 
156     wxButton *  mwxButtonClose; 
157     wxButton *  mwxButtonSave; 
158     wxButton *  mwxButtonSaveAs; 
159     wxButton *  mwxButtonRun; 
160     //    wxButton *  mwxButtonQuit; 
161     wxStaticText* mwxPosition;
162
163     std::string mFileNameFilter;
164
165    public:
166           
167      enum
168     {
169       ID_ButtonNew,
170       ID_ButtonOpen,
171       ID_ButtonClose,
172       ID_ButtonSave,
173       ID_ButtonSaveAs,
174       ID_ButtonRun
175       //      ID_ButtonQuit
176     };
177     
178     DECLARE_EVENT_TABLE()
179         
180   };
181
182   
183   /// Editor in a frame 
184   class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
185                                               //, public WxGUICommandUser
186   {
187   public:
188     WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
189     ~WxGUITextEditorWindow();
190     void Open(const std::string& filename) { mEditor->Open(filename); }
191     //    void WxGUICommandEnter(const std::string& s);
192
193
194   private :
195     
196     WxGUITextEditor* mEditor;
197   };
198   
199
200 } // namespace bbtk
201
202
203 #endif // __bbtkWxGUITextEditor_h__
204
205 #endif //_USE_WXWIDGETS_