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