]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUITextEditor.h
*** empty log message ***
[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/21 14:59:39 $
7   Version:   $Revision: 1.2 $
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
77     WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
78
79     void Load(const std::string& filename);
80     void Save(const std::string& filter);
81
82     bool IsModified(); //{ return mwxInputText->IsModified(); }
83    
84     std::string GetText();
85
86   private:
87     WxGUITextEditor* mEditor;
88     WxTextCtrlGettingKeyEvents* mwxInputText;
89     wxTextAttr* mwxInputTextAttr;
90     std::string mName;
91     bool mAskFilename;
92
93     /*
94     enum
95     {
96       ID_InputText
97     };
98     */
99     //DECLARE_EVENT_TABLE();
100
101   } ;
102   //================================================================
103
104
105
106   /// A text editor panel
107   class BBTK_EXPORT WxGUITextEditor : public wxPanel
108   {
109   public:
110     WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 );
111     ~WxGUITextEditor();
112
113     void OnKeyDown(wxKeyEvent& event);
114     void OnKeyUp(wxKeyEvent& event);
115
116     void OnButtonNew(wxCommandEvent& event);
117     void OnButtonOpen(wxCommandEvent& event);
118     void OnButtonSave(wxCommandEvent& event);
119     void OnButtonRun(wxCommandEvent& event);
120     //    void OnButtonQuit(wxCommandEvent& event);
121     void OnPageClose(wxAuiNotebookEvent& evt);
122
123     void New();
124     void Open();
125     void Open(const std::string& filename);
126     void Save();
127     //   void Run();
128     //    void Quit();
129
130     void HighlightSyntax();
131     void UpdateInfo();
132
133     void NewPage(const std::string& filename);
134     WxGUITextEditorPage* GetCurrentPage();
135     void FocusOnCurrentPage();
136
137     void SetFileNameFilter(const std::string& filter)
138     { mFileNameFilter = filter; }
139
140   private:
141     WxGUITextEditorUser* mUser;
142
143     wxAuiManager m_mgr;
144     wxAuiNotebook* mwxNotebook;
145  
146     //   Interpreter* mInterpreter;
147     //    wxSplitterWindow* mwxSplit;
148
149     wxButton *  mwxButtonNew; 
150     wxButton *  mwxButtonOpen; 
151     wxButton *  mwxButtonSave; 
152     wxButton *  mwxButtonRun; 
153     //    wxButton *  mwxButtonQuit; 
154     wxStaticText* mwxPosition;
155
156     std::string mFileNameFilter;
157
158    public:
159           
160      enum
161     {
162       ID_ButtonNew,
163       ID_ButtonOpen,
164       ID_ButtonSave,
165       ID_ButtonRun
166       //      ID_ButtonQuit
167     };
168     
169     DECLARE_EVENT_TABLE()
170         
171   };
172
173   
174   /// Editor in a frame 
175   class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
176                                               //, public WxGUICommandUser
177   {
178   public:
179     WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
180     ~WxGUITextEditorWindow();
181     void Open(const std::string& filename) { mEditor->Open(filename); }
182     //    void WxGUICommandEnter(const std::string& s);
183
184
185   private :
186     
187     WxGUITextEditor* mEditor;
188   };
189   
190
191 } // namespace bbtk
192
193
194 #endif // __bbtkWxGUITextEditor_h__
195
196 #endif //_USE_WXWIDGETS_