]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUITextEditor.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUITextEditor.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:15 $
6   Version:   $Revision: 1.8 $
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   };
80
81   //================================================================
82   class WxGUITextEditorPage : public wxPanel
83   {
84   public:
85     WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
86     ~WxGUITextEditorPage();
87
88     void SetPageName(const std::string& name) { mName = name; }
89     const std::string& GetPageName() const { return mName; }
90
91     bool AskFilename() const { return mAskFilename; }
92     void SetAskFilename(bool a) { mAskFilename=a; }
93
94     WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
95
96     void Load(const std::string& filename);
97     void Save(const std::string& filter);
98
99     bool IsModified(); //{ return mwxInputText->IsModified(); }
100    
101     std::string GetText();
102
103   private:
104     WxGUITextEditor* mEditor;
105     WxTextCtrlGettingKeyEvents* mwxInputText;
106     wxTextAttr* mwxInputTextAttr;
107     std::string mName;
108     bool mAskFilename;
109
110     /*
111     enum
112     {
113       ID_InputText
114     };
115     */
116     //DECLARE_EVENT_TABLE();
117
118   } ;
119   //================================================================
120
121
122
123   /// A text editor panel
124   class BBTK_EXPORT WxGUITextEditor : public wxPanel
125   {
126   public:
127     WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 );
128     ~WxGUITextEditor();
129
130     void OnKeyDown(wxKeyEvent& event);
131     void OnKeyUp(wxKeyEvent& event);
132
133     void OnToolLeftClick(wxCommandEvent& event);
134     void OnToolRightClick(wxCommandEvent& event);
135
136     void OnPageClose(wxAuiNotebookEvent& evt);
137
138     void New();
139     void Open();
140     void Open(const std::string& filename);
141     void SaveCurrentPage();
142     bool CloseCurrentPage();
143     bool CloseAllPages();
144     //   void Run();
145     //    void Quit();
146
147     void HighlightSyntax();
148     void UpdateInfo();
149
150     void NewPage(const std::string& filename);
151     WxGUITextEditorPage* GetCurrentPage();
152     void FocusOnCurrentPage();
153
154     void SetFileNameFilter(const std::string& filter)
155     { mFileNameFilter = filter; }
156
157   private:
158     WxGUITextEditorUser* mUser;
159
160 //    wxAuiManager m_mgr;
161 //    wxAuiNotebook*
162         wxNotebook* mwxNotebook;
163  
164     wxToolBar* mwxToolBar;
165
166     wxStaticText* mwxPosition;
167
168     std::string mFileNameFilter;
169
170    public:
171           
172      enum
173     {
174       ID_ButtonNew,
175       ID_ButtonOpen,
176       ID_ButtonClose,
177       ID_ButtonSave,
178       ID_ButtonSaveAs,
179       ID_ButtonRun
180       //      ID_ButtonQuit
181     };
182     
183     DECLARE_EVENT_TABLE()
184         
185   };
186
187   
188   /// Editor in a frame 
189   class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
190                                               //, public WxGUICommandUser
191   {
192   public:
193     WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
194     ~WxGUITextEditorWindow();
195     void Open(const std::string& filename) { mEditor->Open(filename); }
196     //    void WxGUICommandEnter(const std::string& s);
197
198
199   private :
200     
201     WxGUITextEditor* mEditor;
202   };
203   
204
205 } // namespace bbtk
206
207
208 #endif // __bbtkWxGUITextEditor_h__
209
210 #endif //_USE_WXWIDGETS_