]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUITextEditor.h
Feature #1774
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkWxGUITextEditor.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.11 $
34 =========================================================================*/
35
36
37
38
39 /**
40  * \brief Short description in one line
41  * 
42  * Long description which 
43  * can span multiple lines
44  */
45 /**
46  * \file 
47  * \brief 
48  */
49 /**
50  * \class bbtk::
51  * \brief 
52  */
53
54
55 #ifdef _USE_WXWIDGETS_
56
57         
58 #ifndef __bbtkWxGUITextEditor_h__
59 #define __bbtkWxGUITextEditor_h__
60
61
62 #include "bbtkWx.h"
63
64 #include "bbtkInterpreter.h"
65 #include <wx/splitter.h>
66 #include <wx/aui/aui.h>
67
68 #include "bbtkWxGUICommand.h"
69
70 namespace bbtk
71 {
72
73   class WxTextCtrlGettingKeyEvents;
74 //   typedef wxTextCtrl WxTextCtrlGettingKeyEvents;
75         class WxGUITextEditor;
76  
77
78   /// Abstract class which defines the callbacks invoked by WxGUITextEditor
79   class BBTK_EXPORT WxGUITextEditorUser
80   {
81   public:
82     WxGUITextEditorUser() {}
83     virtual ~WxGUITextEditorUser() {}
84     /// Callback invoked when the 'run' button is pressed
85     virtual void WxGUITextEditorRun() {}
86     virtual void WxGUITextEditorRunBBI() {} 
87         virtual void WxGUITextEditorGraphSimple() {}
88         virtual void WxGUITextEditorGraphDetail() {}
89           
90   };
91
92   //================================================================
93   class WxGUITextEditorPage : public wxPanel
94   {
95   public:
96     WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
97     ~WxGUITextEditorPage();
98
99     void SetPageName(const std::string& name) { mName = name; }
100     const std::string& GetPageName() const { return mName; }
101
102     bool AskFilename() const { return mAskFilename; }
103     void SetAskFilename(bool a) { mAskFilename=a; }
104
105     WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
106
107     void Load(const std::string& filename);
108     void Save(const std::string& filter);
109         void SaveFile(const std::string& filename);
110
111           
112     bool IsModified(); //{ return mwxInputText->IsModified(); }
113    
114     std::string GetText();
115
116   private:
117     WxGUITextEditor* mEditor;
118     WxTextCtrlGettingKeyEvents* mwxInputText;
119     wxTextAttr* mwxInputTextAttr;
120         wxFont* mFixedFont;
121     std::string mName;
122     bool mAskFilename;
123
124     /*
125     enum
126     {
127       ID_InputText
128     };
129     */
130     //DECLARE_EVENT_TABLE();
131
132   } ;
133   //================================================================
134
135
136
137   /// A text editor panel
138   class BBTK_EXPORT WxGUITextEditor : public wxPanel
139   {
140   public:
141     WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 );
142     ~WxGUITextEditor();
143
144     void OnKeyDown(wxKeyEvent& event);
145     void OnKeyUp(wxKeyEvent& event);
146
147     void OnToolLeftClick(wxCommandEvent& event);
148     void OnToolRightClick(wxCommandEvent& event);
149
150     void OnPageClose(wxAuiNotebookEvent& evt);
151
152     void New();
153     void Open();
154     void Open(const std::string& filename);
155     void SaveCurrentPage();
156     bool CloseCurrentPage();
157     bool CloseAllPages();
158     //   void Run();
159     //    void Quit();
160
161     void HighlightSyntax();
162     void UpdateInfo();
163
164     void NewPage(const std::string& filename);
165     WxGUITextEditorPage* GetCurrentPage();
166     void FocusOnCurrentPage();
167
168     void SetFileNameFilter(const std::string& filter)
169     { mFileNameFilter = filter; }
170
171   private:
172     WxGUITextEditorUser* mUser;
173
174 //    wxAuiManager m_mgr;
175 //    wxAuiNotebook*
176         wxNotebook* mwxNotebook;
177  
178     wxToolBar* mwxToolBar;
179
180     wxStaticText* mwxPosition;
181
182     std::string mFileNameFilter;
183
184    public:
185           
186      enum
187     {
188       ID_ButtonNew,
189       ID_ButtonOpen,
190       ID_ButtonClose,
191       ID_ButtonSave,
192       ID_ButtonSaveAs,
193       ID_ButtonRun,
194           ID_ButtonRunBBI,
195           ID_ButtonGraphSimple,
196           ID_ButtonGraphDetail
197       //      ID_ButtonQuit
198     };
199     
200     DECLARE_EVENT_TABLE()
201         
202   };
203
204   
205   /// Editor in a frame 
206   class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
207                                               //, public WxGUICommandUser
208   {
209   public:
210     WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
211     ~WxGUITextEditorWindow();
212     void Open(const std::string& filename) { mEditor->Open(filename); }
213     //    void WxGUICommandEnter(const std::string& s);
214
215
216   private :
217     
218     WxGUITextEditor* mEditor;
219   };
220   
221
222 } // namespace bbtk
223
224
225 #endif // __bbtkWxGUITextEditor_h__
226
227 #endif //_USE_WXWIDGETS_