]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUITextEditor.h
icons bbStudio
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUITextEditor.h,v $
4   Language:  C++
5   Date:      $Date: 2009/04/15 15:45:50 $
6   Version:   $Revision: 1.9 $
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     std::string mName;
114     bool mAskFilename;
115
116     /*
117     enum
118     {
119       ID_InputText
120     };
121     */
122     //DECLARE_EVENT_TABLE();
123
124   } ;
125   //================================================================
126
127
128
129   /// A text editor panel
130   class BBTK_EXPORT WxGUITextEditor : public wxPanel
131   {
132   public:
133     WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 );
134     ~WxGUITextEditor();
135
136     void OnKeyDown(wxKeyEvent& event);
137     void OnKeyUp(wxKeyEvent& event);
138
139     void OnToolLeftClick(wxCommandEvent& event);
140     void OnToolRightClick(wxCommandEvent& event);
141
142     void OnPageClose(wxAuiNotebookEvent& evt);
143
144     void New();
145     void Open();
146     void Open(const std::string& filename);
147     void SaveCurrentPage();
148     bool CloseCurrentPage();
149     bool CloseAllPages();
150     //   void Run();
151     //    void Quit();
152
153     void HighlightSyntax();
154     void UpdateInfo();
155
156     void NewPage(const std::string& filename);
157     WxGUITextEditorPage* GetCurrentPage();
158     void FocusOnCurrentPage();
159
160     void SetFileNameFilter(const std::string& filter)
161     { mFileNameFilter = filter; }
162
163   private:
164     WxGUITextEditorUser* mUser;
165
166 //    wxAuiManager m_mgr;
167 //    wxAuiNotebook*
168         wxNotebook* mwxNotebook;
169  
170     wxToolBar* mwxToolBar;
171
172     wxStaticText* mwxPosition;
173
174     std::string mFileNameFilter;
175
176    public:
177           
178      enum
179     {
180       ID_ButtonNew,
181       ID_ButtonOpen,
182       ID_ButtonClose,
183       ID_ButtonSave,
184       ID_ButtonSaveAs,
185       ID_ButtonRun,
186           ID_ButtonRunBBI,
187           ID_ButtonGraphSimple,
188           ID_ButtonGraphDetail
189       //      ID_ButtonQuit
190     };
191     
192     DECLARE_EVENT_TABLE()
193         
194   };
195
196   
197   /// Editor in a frame 
198   class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
199                                               //, public WxGUICommandUser
200   {
201   public:
202     WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
203     ~WxGUITextEditorWindow();
204     void Open(const std::string& filename) { mEditor->Open(filename); }
205     //    void WxGUICommandEnter(const std::string& s);
206
207
208   private :
209     
210     WxGUITextEditor* mEditor;
211   };
212   
213
214 } // namespace bbtk
215
216
217 #endif // __bbtkWxGUITextEditor_h__
218
219 #endif //_USE_WXWIDGETS_