~registry/codeblocks/trunk

« back to all changes in this revision

Viewing changes to src/include/cbeditor.h

  • Committer: mandrav
  • Date: 2007-02-12 14:55:28 UTC
  • Revision ID: svn-v4:98b59c6a-2706-0410-b7d6-d2fa1a1880c9:trunk:3594
* First part of directories layout re-organization: moved all sdk header files to a new dir named "include".

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef CBEDITOR_H
 
2
#define CBEDITOR_H
 
3
 
 
4
#include <wx/hashmap.h>
 
5
#include <wx/datetime.h>
 
6
#include <wx/fontmap.h>
 
7
 
 
8
#include "wx/wxscintilla.h"
 
9
#include "settings.h"
 
10
#include "editorbase.h"
 
11
#include "printing_types.h"
 
12
 
 
13
extern const wxString g_EditorModified;
 
14
 
 
15
// forward decls
 
16
struct cbEditorInternalData; // this is the private data struct used by the editor.
 
17
class cbEditor;
 
18
class ProjectFile;
 
19
class EditorColourSet;
 
20
class wxSplitterWindow;
 
21
 
 
22
class cbStyledTextCtrl : public wxScintilla
 
23
{
 
24
        public:
 
25
                cbStyledTextCtrl(wxWindow* pParent, int id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
 
26
                virtual ~cbStyledTextCtrl();
 
27
        protected:
 
28
                void OnContextMenu(wxContextMenuEvent& event);
 
29
                void OnKillFocus(wxFocusEvent& event);
 
30
                void OnGPM(wxMouseEvent& event);
 
31
        private:
 
32
                wxWindow* m_pParent;
 
33
                DECLARE_EVENT_TABLE()
 
34
};
 
35
 
 
36
/** @brief A file editor
 
37
  *
 
38
  * This class represents one builtin editor in Code::Blocks. It holds all the necessary
 
39
  * information about an editor. When you want to access a Code::Blocks editor,
 
40
  * this is the class you want to get at ;)\n
 
41
  *
 
42
  * To do this, use Manager::Get()->GetEditorManager() functions.
 
43
  *
 
44
  * The actual editor component used is Scintilla and it can be accessed through
 
45
  * the member function GetControl().
 
46
  */
 
47
class DLLIMPORT cbEditor : public EditorBase
 
48
{
 
49
        DECLARE_EVENT_TABLE()
 
50
        friend class EditorManager;
 
51
 
 
52
    protected:
 
53
                /** cbEditor constructor.
 
54
                  * @param parent the parent notebook - you should use EditorManager::Get()
 
55
                  * @param filename the filename to open. If filename is empty, it creates a
 
56
                  * new, empty, editor.
 
57
                  * @param theme the initial colour set to use\n
 
58
                  * <em>Note: you cannot create a cbEditor object directly. Instead
 
59
                  * use EditorManager's methods to do it...</em>
 
60
                  */
 
61
                cbEditor(wxWindow* parent, const wxString& filename, EditorColourSet* theme = 0L);
 
62
        /** Don't use this. It throws an exception if you do. */
 
63
        cbEditor(const cbEditor& rhs) : EditorBase(rhs) { cbThrow(_T("Can't call cbEditor's copy ctor!!!")); }
 
64
                /** cbEditor destructor. */
 
65
                ~cbEditor();
 
66
        public:
 
67
        enum SplitType
 
68
        {
 
69
            stNoSplit = 0,
 
70
            stHorizontal,
 
71
            stVertical
 
72
        };
 
73
 
 
74
        /** Don't use this. It throws an exception if you do. */
 
75
        virtual void operator=(const cbEditor& rhs){ cbThrow(_T("Can't assign an cbEditor* !!!")); }
 
76
 
 
77
                // properties
 
78
 
 
79
                /** Returns a pointer to the underlying cbStyledTextCtrl object (which
 
80
                  * itself is the wxWindows implementation of Scintilla). If you want
 
81
                  * to mess with the actual contents of an editor, this is the object
 
82
                  * you want to get.
 
83
                  * @remarks If the editor is split, this function returns the control
 
84
                  * which currently has the keyboard focus. Don't save this pointer
 
85
                  * because it might be invalid at any later time...
 
86
                  */
 
87
        cbStyledTextCtrl* GetControl() const;
 
88
 
 
89
                /** Returns a pointer to the left (or top) split-view cbStyledTextCtrl.
 
90
                  * This function always returns a valid pointer.
 
91
                  */
 
92
        cbStyledTextCtrl* GetLeftSplitViewControl() const { return m_pControl; }
 
93
 
 
94
                /** Returns a pointer to the right (or bottom) split-view cbStyledTextCtrl.
 
95
                  * This function may return NULL if the editor is not split.
 
96
                  */
 
97
        cbStyledTextCtrl* GetRightSplitViewControl() const { return m_pControl2; }
 
98
 
 
99
        /** Returns the state of split-view for this editor. */
 
100
        SplitType GetSplitType() const { return m_SplitType; }
 
101
 
 
102
                /** Returns true if editor is OK, i.e. constructor was called with a filename
 
103
                  * parameter and file was opened succesfully. If it returns false, you
 
104
                  * should delete the editor...
 
105
                  */
 
106
                bool IsOK() const { return m_IsOK; }
 
107
 
 
108
                /** Sets the editor title. For tabbed interface, it sets the corresponding
 
109
                  * tab text, while for MDI interface it sets the MDI window title...
 
110
                  */
 
111
                void SetEditorTitle(const wxString& title);
 
112
 
 
113
                /** Returns true if editor is modified, false otherwise */
 
114
                bool GetModified() const;
 
115
 
 
116
                /** Set the editor's modification state to \c modified. */
 
117
                void SetModified(bool modified = true);
 
118
 
 
119
                /** Set the ProjectFile pointer associated with this editor. All editors
 
120
                  * which belong to a project file, should have this set. All others should return NULL.
 
121
                  * Optionally you can preserve the "modified" flag of the file.
 
122
                  */
 
123
                void SetProjectFile(ProjectFile* project_file,bool preserve_modified = false);
 
124
 
 
125
                /** Read the ProjectFile pointer associated with this editor. All editors
 
126
                  * which belong to a project file, have this set. All others return NULL.
 
127
                  */
 
128
                ProjectFile* GetProjectFile() const { return m_pProjectFile; }
 
129
 
 
130
                /** Updates the associated ProjectFile object with the editor's caret
 
131
                  * position, top visible line and its open state. Used in devProject
 
132
                  * layout information, so that each time the user opens a project
 
133
                  * file in the IDE, it opens exactly in the same state it was when last
 
134
                  * closed.
 
135
                  */
 
136
                void UpdateProjectFile();
 
137
 
 
138
                /** Save editor contents. Returns true on success, false otherwise. */
 
139
                bool Save();
 
140
 
 
141
                /** Save editor contents under a different filename. Returns true on success, false otherwise. */
 
142
                bool SaveAs();
 
143
 
 
144
                /** Unimplemented */
 
145
                bool RenameTo(const wxString& filename, bool deleteOldFromDisk = false);
 
146
 
 
147
                /** Save fold states within a new cbStyledTextCtrl. This saves the whole document, thus saving the fold states before the Fold Options Change*/
 
148
                bool SaveFoldState();
 
149
 
 
150
                /** Fix fold states by comparing foldBackup with m_pControl. This is a temp fix for the Scintilla bug*/
 
151
                bool FixFoldState();
 
152
 
 
153
                /** Fold all editor folds (hides blocks of code). */
 
154
                void FoldAll();
 
155
 
 
156
                /** Unfold all editor folds (shows blocks of code). */
 
157
                void UnfoldAll();
 
158
 
 
159
                /** Toggle all editor folds (inverts the show/hide state of blocks of code). */
 
160
                void ToggleAllFolds();
 
161
 
 
162
                /** Folds the block containing \c line. If \c line is -1, folds the block containing the caret. */
 
163
                void FoldBlockFromLine(int line = -1);
 
164
 
 
165
                /** Unfolds the block containing \c line. If \c line is -1, unfolds the block containing the caret. */
 
166
                void UnfoldBlockFromLine(int line = -1);
 
167
 
 
168
                /** Toggles folding of the block containing \c line. If \c line is -1, toggles folding of the block containing the caret. */
 
169
                void ToggleFoldBlockFromLine(int line = -1);
 
170
 
 
171
                /** Set the colour set to use. */
 
172
                void SetColourSet(EditorColourSet* theme);
 
173
 
 
174
                /** Get the colour set in use. */
 
175
                EditorColourSet* GetColourSet() const { return m_pTheme; }
 
176
 
 
177
                /** Jumps to the matching brace (if there is one). */
 
178
                void GotoMatchingBrace();
 
179
 
 
180
                /** Highlights the brace pair (one of the braces must be under the cursor) */
 
181
                void HighlightBraces();
 
182
 
 
183
        /** Returns the specified line's (0-based) indentation (whitespace) in spaces. If line is -1, it uses the current line */
 
184
        int GetLineIndentInSpaces(int line = -1) const;
 
185
 
 
186
        /** Returns the specified line's (0-based) indentation (whitespace) string. If line is -1, it uses the current line */
 
187
        wxString GetLineIndentString(int line = -1) const;
 
188
 
 
189
        /** Returns the last modification time for the file. Used to detect modifications outside the editor. */
 
190
        wxDateTime GetLastModificationTime() const { return m_LastModified; }
 
191
 
 
192
        /** Sets the last modification time for the file to 'now'. Used to detect modifications outside the editor. */
 
193
        void Touch();
 
194
 
 
195
        /** Reloads the file from disk. @return True on success, False on failure. */
 
196
        bool Reload(bool detectEncoding = true);
 
197
 
 
198
        /** Print the file.
 
199
          * @param selectionOnly Should the selected text be printed only?
 
200
          * @param pcm The colour mode to use when printing
 
201
          * @param line_numbers Print the line numbers of file, too.
 
202
          */
 
203
        void Print(bool selectionOnly, PrintColourMode pcm, bool line_numbers);
 
204
 
 
205
        /** Try to auto-complete the current word.
 
206
          *
 
207
          * This has nothing to do with code-completion plugins. Editor auto-completion
 
208
          * is a feature that saves typing common blocks of code, e.g.
 
209
          *
 
210
          * If you have typed "forb" (no quotes) and select auto-complete, then
 
211
          * it will convert "forb" to "for ( ; ; ){ }".
 
212
          * If the word up to the caret position is an unknown keyword, nothing happens.
 
213
          *
 
214
          * These keywords/code pairs can be edited in the editor configuration
 
215
          * dialog.
 
216
          */
 
217
                void AutoComplete();
 
218
 
 
219
        /** Move the caret at the specified line.
 
220
          * @param line Line to move caret to.
 
221
          * @param centerOnScreen If true (default), tries to bring the specified line to the centre of the editor.*/
 
222
        void GotoLine(int line, bool centerOnScreen = true);
 
223
 
 
224
        /** Add debugger breakpoint at specified line. If @c line is -1, use current line. */
 
225
        bool AddBreakpoint(int line = -1, bool notifyDebugger = true);
 
226
 
 
227
        /** Remove debugger breakpoint at specified line. If @c line is -1, use current line. */
 
228
        bool RemoveBreakpoint(int line = -1, bool notifyDebugger = true);
 
229
 
 
230
        /** Toggle debugger breakpoint at specified line. If @c line is -1, use current line. */
 
231
        void ToggleBreakpoint(int line = -1, bool notifyDebugger = true);
 
232
 
 
233
        /** Does @c line has debugger breakpoint? If @c line is -1, use current line. */
 
234
        bool HasBreakpoint(int line) const;
 
235
 
 
236
        /** Go to next debugger breakpoint. */
 
237
        void GotoNextBreakpoint();
 
238
 
 
239
        /** Go to previous debugger breakpoint. */
 
240
        void GotoPreviousBreakpoint();
 
241
 
 
242
        /** Toggle bookmark at specified line. If @c line is -1, use current line. */
 
243
        void ToggleBookmark(int line = -1);
 
244
 
 
245
        /** Does @c line has bookmark? */
 
246
        bool HasBookmark(int line) const;
 
247
 
 
248
        /** Go to next bookmark. */
 
249
        void GotoNextBookmark();
 
250
 
 
251
        /** Go to previous bookmark. */
 
252
        void GotoPreviousBookmark();
 
253
 
 
254
        /** Highlight the line the debugger will execute next. */
 
255
        void SetDebugLine(int line);
 
256
 
 
257
        /** Highlight the specified line as error. */
 
258
        void SetErrorLine(int line);
 
259
 
 
260
        /** Split the editor window.
 
261
          * @param split The type of split: horizontal or vertical. */
 
262
        void Split(SplitType split);
 
263
 
 
264
        /** Unsplit the editor window. */
 
265
        void Unsplit();
 
266
 
 
267
        // the following functions, although self-explanatory, are documented
 
268
        // in EditorBase.
 
269
        void Undo();
 
270
        void Redo();
 
271
        void Cut();
 
272
        void Copy();
 
273
        void Paste();
 
274
        bool CanUndo() const;
 
275
        bool CanRedo() const;
 
276
        bool HasSelection() const;
 
277
        bool CanPaste() const;
 
278
 
 
279
                // Workaround for shift-tab bug in wx2.4.2
 
280
                void DoIndent(); /// Indents current line/block
 
281
                void DoUnIndent(); /// UnIndents current line/block
 
282
 
 
283
        // misc. functions
 
284
        virtual wxMenu* CreateContextSubMenu(long id);
 
285
        virtual void AddToContextMenu(wxMenu* popup,ModuleType type,bool pluginsdone);  //pecan 2006/03/22
 
286
 
 
287
        HighlightLanguage GetLanguage( ) const { return m_lang; }
 
288
        void SetLanguage( HighlightLanguage lang = HL_AUTO );
 
289
 
 
290
        wxFontEncoding GetEncoding( ) const;
 
291
        wxString GetEncodingName( ) const;
 
292
        void SetEncoding( wxFontEncoding encoding );
 
293
 
 
294
        bool GetUseBom() const;
 
295
        void SetUseBom( bool bom );
 
296
 
 
297
        /// Apply the editor defaults to any (possibly foreign) cbStyledTextCtrl.
 
298
        static void ApplyStyles(cbStyledTextCtrl* control);
 
299
    private:
 
300
        // functions
 
301
        bool LineHasMarker(int marker, int line = -1) const;
 
302
        void MarkerToggle(int marker, int line = -1);
 
303
        void MarkerNext(int marker);
 
304
        void MarkerPrevious(int marker);
 
305
        void MarkLine(int marker, int line);
 
306
 
 
307
                void DoFoldAll(int fold); // 0=unfold, 1=fold, 2=toggle
 
308
                void DoFoldBlockFromLine(int line, int fold); // 0=unfold, 1=fold, 2=toggle
 
309
                bool DoFoldLine(int line, int fold); // 0=unfold, 1=fold, 2=toggle
 
310
        cbStyledTextCtrl* CreateEditor();
 
311
        void SetEditorStyle();
 
312
        void SetEditorStyleBeforeFileOpen();
 
313
        void SetEditorStyleAfterFileOpen();
 
314
        static void InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control);
 
315
        static void InternalSetEditorStyleAfterFileOpen(cbStyledTextCtrl* control);
 
316
        void DetectEncoding();
 
317
        bool Open(bool detectEncoding = true);
 
318
        void DoAskForCodeCompletion(); // relevant to code-completion plugins
 
319
                static wxColour GetOptionColour(const wxString& option, const wxColour _default);
 
320
                void NotifyPlugins(wxEventType type, int intArg = 0, const wxString& strArg = wxEmptyString, int xArg = 0, int yArg = 0);
 
321
 
 
322
        // events
 
323
        void OnMarginClick(wxScintillaEvent& event);
 
324
        void OnEditorUpdateUI(wxScintillaEvent& event);
 
325
        void OnEditorChange(wxScintillaEvent& event);
 
326
        void OnEditorCharAdded(wxScintillaEvent& event);
 
327
                void OnEditorDwellStart(wxScintillaEvent& event);
 
328
                void OnEditorDwellEnd(wxScintillaEvent& event);
 
329
                void OnEditorModified(wxScintillaEvent& event);
 
330
                void OnUserListSelection(wxScintillaEvent& event);
 
331
                void OnZoom(wxScintillaEvent& event);
 
332
                void OnScintillaEvent(wxScintillaEvent& event);
 
333
                void OnClose(wxCloseEvent& event);
 
334
 
 
335
                // one event handler for all popup menu entries
 
336
                void OnContextMenuEntry(wxCommandEvent& event);
 
337
        bool OnBeforeBuildContextMenu(const wxPoint& position, ModuleType type);    //pecan 2006/03/22
 
338
        void OnAfterBuildContextMenu(ModuleType type);                              //pecan 2006/03/22
 
339
 
 
340
        void DestroySplitView();
 
341
 
 
342
        // variables
 
343
        bool m_IsOK;
 
344
        wxSplitterWindow* m_pSplitter;
 
345
        wxBoxSizer* m_pSizer;
 
346
        cbStyledTextCtrl* m_pControl;
 
347
        cbStyledTextCtrl* m_pControl2;
 
348
        cbStyledTextCtrl* m_foldBackup;
 
349
        SplitType m_SplitType;
 
350
        int m_ID;
 
351
                bool m_Modified;
 
352
                int m_Index;
 
353
        wxTimer m_timerWait;
 
354
                ProjectFile* m_pProjectFile;
 
355
                EditorColourSet* m_pTheme;
 
356
                HighlightLanguage m_lang;
 
357
        wxDateTime m_LastModified; // to check if the file was modified outside the editor
 
358
 
 
359
        // DO NOT ADD ANY MORE VARIABLES HERE!
 
360
        // ADD THEM IN cbEditorInternalData INSTEAD!
 
361
 
 
362
        friend struct cbEditorInternalData; // allow cbEditorInternalData to access cbEditor
 
363
        cbEditorInternalData* m_pData;
 
364
};
 
365
 
 
366
#endif // CBEDITOR_H