]> 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/10/03 14:27:52 $
7   Version:   $Revision: 1.7 $
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 //   typedef wxTextCtrl WxTextCtrlGettingKeyEvents;
53         class WxGUITextEditor;
54  
55
56   /// Abstract class which defines the callbacks invoked by WxGUITextEditor
57   class BBTK_EXPORT WxGUITextEditorUser
58   {
59   public:
60     WxGUITextEditorUser() {}
61     virtual ~WxGUITextEditorUser() {}
62     /// Callback invoked when the 'run' button is pressed
63     virtual void WxGUITextEditorRun() {}
64   };
65
66   //================================================================
67   class WxGUITextEditorPage : public wxPanel
68   {
69   public:
70     WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
71     ~WxGUITextEditorPage();
72
73     void SetPageName(const std::string& name) { mName = name; }
74     const std::string& GetPageName() const { return mName; }
75
76     bool AskFilename() const { return mAskFilename; }
77     void SetAskFilename(bool a) { mAskFilename=a; }
78
79     WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
80
81     void Load(const std::string& filename);
82     void Save(const std::string& filter);
83
84     bool IsModified(); //{ return mwxInputText->IsModified(); }
85    
86     std::string GetText();
87
88   private:
89     WxGUITextEditor* mEditor;
90     WxTextCtrlGettingKeyEvents* mwxInputText;
91     wxTextAttr* mwxInputTextAttr;
92     std::string mName;
93     bool mAskFilename;
94
95     /*
96     enum
97     {
98       ID_InputText
99     };
100     */
101     //DECLARE_EVENT_TABLE();
102
103   } ;
104   //================================================================
105
106
107
108   /// A text editor panel
109   class BBTK_EXPORT WxGUITextEditor : public wxPanel
110   {
111   public:
112     WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 );
113     ~WxGUITextEditor();
114
115     void OnKeyDown(wxKeyEvent& event);
116     void OnKeyUp(wxKeyEvent& event);
117
118     void OnToolLeftClick(wxCommandEvent& event);
119     void OnToolRightClick(wxCommandEvent& event);
120
121     void OnPageClose(wxAuiNotebookEvent& evt);
122
123     void New();
124     void Open();
125     void Open(const std::string& filename);
126     void SaveCurrentPage();
127     bool CloseCurrentPage();
128     bool CloseAllPages();
129     //   void Run();
130     //    void Quit();
131
132     void HighlightSyntax();
133     void UpdateInfo();
134
135     void NewPage(const std::string& filename);
136     WxGUITextEditorPage* GetCurrentPage();
137     void FocusOnCurrentPage();
138
139     void SetFileNameFilter(const std::string& filter)
140     { mFileNameFilter = filter; }
141
142   private:
143     WxGUITextEditorUser* mUser;
144
145 //    wxAuiManager m_mgr;
146 //    wxAuiNotebook*
147         wxNotebook* mwxNotebook;
148  
149     wxToolBar* mwxToolBar;
150
151     wxStaticText* mwxPosition;
152
153     std::string mFileNameFilter;
154
155    public:
156           
157      enum
158     {
159       ID_ButtonNew,
160       ID_ButtonOpen,
161       ID_ButtonClose,
162       ID_ButtonSave,
163       ID_ButtonSaveAs,
164       ID_ButtonRun
165       //      ID_ButtonQuit
166     };
167     
168     DECLARE_EVENT_TABLE()
169         
170   };
171
172   
173   /// Editor in a frame 
174   class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
175                                               //, public WxGUICommandUser
176   {
177   public:
178     WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
179     ~WxGUITextEditorWindow();
180     void Open(const std::string& filename) { mEditor->Open(filename); }
181     //    void WxGUICommandEnter(const std::string& s);
182
183
184   private :
185     
186     WxGUITextEditor* mEditor;
187   };
188   
189
190 } // namespace bbtk
191
192
193 #endif // __bbtkWxGUITextEditor_h__
194
195 #endif //_USE_WXWIDGETS_