]> 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/07/23 11:46:11 $
7   Version:   $Revision: 1.6 $
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     virtual ~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 OnToolLeftClick(wxCommandEvent& event);
118     void OnToolRightClick(wxCommandEvent& event);
119
120     void OnPageClose(wxAuiNotebookEvent& evt);
121
122     void New();
123     void Open();
124     void Open(const std::string& filename);
125     void SaveCurrentPage();
126     bool CloseCurrentPage();
127     bool CloseAllPages();
128     //   void Run();
129     //    void Quit();
130
131     void HighlightSyntax();
132     void UpdateInfo();
133
134     void NewPage(const std::string& filename);
135     WxGUITextEditorPage* GetCurrentPage();
136     void FocusOnCurrentPage();
137
138     void SetFileNameFilter(const std::string& filter)
139     { mFileNameFilter = filter; }
140
141   private:
142     WxGUITextEditorUser* mUser;
143
144     wxAuiManager m_mgr;
145     wxAuiNotebook* mwxNotebook;
146  
147     wxToolBar* mwxToolBar;
148
149     wxStaticText* mwxPosition;
150
151     std::string mFileNameFilter;
152
153    public:
154           
155      enum
156     {
157       ID_ButtonNew,
158       ID_ButtonOpen,
159       ID_ButtonClose,
160       ID_ButtonSave,
161       ID_ButtonSaveAs,
162       ID_ButtonRun
163       //      ID_ButtonQuit
164     };
165     
166     DECLARE_EVENT_TABLE()
167         
168   };
169
170   
171   /// Editor in a frame 
172   class BBTK_EXPORT WxGUITextEditorWindow : public wxFrame
173                                               //, public WxGUICommandUser
174   {
175   public:
176     WxGUITextEditorWindow( wxWindow *parent, wxString title, wxSize size);
177     ~WxGUITextEditorWindow();
178     void Open(const std::string& filename) { mEditor->Open(filename); }
179     //    void WxGUICommandEnter(const std::string& s);
180
181
182   private :
183     
184     WxGUITextEditor* mEditor;
185   };
186   
187
188 } // namespace bbtk
189
190
191 #endif // __bbtkWxGUITextEditor_h__
192
193 #endif //_USE_WXWIDGETS_