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