]> git.saurik.com Git - wxWidgets.git/blob - include/wx/stc/stc.h
Reworked Frame class
[wxWidgets.git] / include / wx / stc / stc.h
1 ////////////////////////////////////////////////////////////////////////////
2 // Name: stc.h
3 // Purpose: A wxWindows implementation of Scintilla. This class is the
4 // one meant to be used directly by wx applications. It does not
5 // derive directly from the Scintilla classes, and in fact there
6 // is no mention of Scintilla classes at all in this header.
7 // This class delegates all method calls and events to the
8 // Scintilla objects and so forth. This allows the use of
9 // Scintilla without polluting the namespace with all the
10 // classes and itentifiers from Scintilla.
11 //
12 // Author: Robin Dunn
13 //
14 // Created: 13-Jan-2000
15 // RCS-ID: $Id$
16 // Copyright: (c) 2000 by Total Control Software
17 // Licence: wxWindows license
18 /////////////////////////////////////////////////////////////////////////////
19
20 #ifndef __stc_h__
21 #define __stc_h__
22
23
24 #include <wx/wx.h>
25
26
27 //----------------------------------------------------------------------
28 // constants and stuff
29
30 enum wxSTC_UndoType {
31 wxSTC_UndoCollectNone,
32 wxSTC_UndoCollectAutoStart
33 };
34
35
36 enum wxSTC_EOL {
37 wxSTC_EOL_CRLF,
38 wxSTC_EOL_CR,
39 wxSTC_EOL_LF
40 };
41
42 enum wxSTC_EDGE {
43 wxSTC_EDGE_NONE,
44 wxSTC_EDGE_LINE,
45 wxSTC_EDGE_BACKGROUND
46 };
47
48
49
50 const int wxSTC_LEX_STYLE_MAX = 31;
51 const int wxSTC_STYLE_DEFAULT = 32;
52 const int wxSTC_STYLE_LINENUMBER = 33;
53 const int wxSTC_STYLE_BRACELIGHT = 34;
54 const int wxSTC_STYLE_BRACEBAD = 35;
55 const int wxSTC_STYLE_CONTROLCHAR = 36;
56 const int wxSTC_STYLE_MAX = 63;
57 const int wxSTC_STYLE_MASK = 31;
58
59 const int wxSTC_MARKER_MAX = 31;
60 const int wxSTC_MARK_CIRCLE = 0;
61 const int wxSTC_MARK_ROUNDRECT = 1;
62 const int wxSTC_MARK_ARROW = 2;
63 const int wxSTC_MARK_SMALLRECT = 3;
64 const int wxSTC_MARK_SHORTARROW = 4;
65 const int wxSTC_MARK_EMPTY = 5;
66
67 const int wxSTC_INDIC_PLAIN = 0;
68 const int wxSTC_INDIC_SQUIGGLE = 1;
69 const int wxSTC_INDIC_TT = 2;
70 const int wxSTC_INDIC0_MASK = 32;
71 const int wxSTC_INDIC1_MASK = 64;
72 const int wxSTC_INDIC2_MASK = 128;
73 const int wxSTC_INDICS_MASK = (wxSTC_INDIC0_MASK | wxSTC_INDIC1_MASK | wxSTC_INDIC2_MASK);
74
75
76 // key commands
77 enum {
78 wxSTC_CMD_LINEDOWN = 2300,
79 wxSTC_CMD_LINEDOWNEXTEND,
80 wxSTC_CMD_LINEUP,
81 wxSTC_CMD_LINEUPEXTEND,
82 wxSTC_CMD_CHARLEFT,
83 wxSTC_CMD_CHARLEFTEXTEND,
84 wxSTC_CMD_CHARRIGHT,
85 wxSTC_CMD_CHARRIGHTEXTEND,
86 wxSTC_CMD_WORDLEFT,
87 wxSTC_CMD_WORDLEFTEXTEND,
88 wxSTC_CMD_WORDRIGHT,
89 wxSTC_CMD_WORDRIGHTEXTEND,
90 wxSTC_CMD_HOME,
91 wxSTC_CMD_HOMEEXTEND,
92 wxSTC_CMD_LINEEND,
93 wxSTC_CMD_LINEENDEXTEND,
94 wxSTC_CMD_DOCUMENTSTART,
95 wxSTC_CMD_DOCUMENTSTARTEXTEND,
96 wxSTC_CMD_DOCUMENTEND,
97 wxSTC_CMD_DOCUMENTENDEXTEND,
98 wxSTC_CMD_PAGEUP,
99 wxSTC_CMD_PAGEUPEXTEND,
100 wxSTC_CMD_PAGEDOWN,
101 wxSTC_CMD_PAGEDOWNEXTEND,
102 wxSTC_CMD_EDITTOGGLEOVERTYPE,
103 wxSTC_CMD_CANCEL,
104 wxSTC_CMD_DELETEBACK,
105 wxSTC_CMD_TAB,
106 wxSTC_CMD_BACKTAB,
107 wxSTC_CMD_NEWLINE,
108 wxSTC_CMD_FORMFEED,
109 wxSTC_CMD_VCHOME,
110 wxSTC_CMD_VCHOMEEXTEND,
111 wxSTC_CMD_ZOOMIN,
112 wxSTC_CMD_ZOOMOUT,
113 wxSTC_CMD_DELWORDLEFT,
114 wxSTC_CMD_DELWORDRIGHT
115 };
116
117
118 enum wxSTC_LEX {
119 wxSTC_LEX_CONTAINER=0,
120 wxSTC_LEX_NULL,
121 wxSTC_LEX_PYTHON,
122 wxSTC_LEX_CPP,
123 wxSTC_LEX_HTML,
124 wxSTC_LEX_XML,
125 wxSTC_LEX_PERL,
126 wxSTC_LEX_SQL,
127 wxSTC_LEX_VB,
128 wxSTC_LEX_PROPERTIES,
129 wxSTC_LEX_ERRORLIST,
130 wxSTC_LEX_MAKEFILE,
131 wxSTC_LEX_BATCH,
132 };
133
134
135
136 const int wxSTC_CARET_SLOP = 0x01;
137 const int WXSTC_CARET_CENTER = 0x02;
138 const int wxSTC_CARET_STRICT = 0x04;
139
140 const int wxSTC_MARGIN_SYMBOL = 0;
141 const int wxSTC_MARGIN_NUMBER = 1;
142
143
144 class ScintillaWX; // forward declare
145 class WordList;
146 struct SCNotification;
147
148
149 extern const wxChar* wxSTCNameStr;
150
151 //----------------------------------------------------------------------
152
153 class wxStyledTextCtrl : public wxControl {
154 public:
155
156 wxStyledTextCtrl(wxWindow *parent, wxWindowID id,
157 const wxPoint& pos = wxDefaultPosition,
158 const wxSize& size = wxDefaultSize, long style = 0,
159 const wxString& name = wxSTCNameStr);
160 ~wxStyledTextCtrl();
161
162
163
164 // Text retrieval and modification
165 wxString GetText();
166 bool SetText(const wxString& text);
167 wxString GetLine(int line);
168 void ReplaceSelection(const wxString& text);
169 void SetReadOnly(bool readOnly);
170 bool GetReadOnly();
171 wxString GetTextRange(int startPos, int endPos);
172 wxString GetStyledTextRange(int startPos, int endPos);
173 void GetTextRange(int startPos, int endPos, char* buff);
174 void GetStyledTextRange(int startPos, int endPos, char* buff);
175 void AddText(const wxString& text);
176 void AddStyledText(const wxString& text);
177 void InsertText(int pos, const wxString& text);
178 void ClearAll();
179 char GetCharAt(int pos);
180 char GetStyleAt(int pos);
181 void SetStyleBits(int bits);
182 int GetStyleBits();
183
184
185 // Clipboard
186 void Cut();
187 void Copy();
188 void Paste();
189 bool CanPaste();
190 void ClearClipbrd(); // avoiding name conflict with virtual in wxWindow
191
192
193 // Undo and Redo
194 void Undo();
195 bool CanUndo();
196 void EmptyUndoBuffer();
197 void Redo();
198 bool CanRedo();
199 void SetUndoCollection(wxSTC_UndoType type);
200 wxSTC_UndoType GetUndoCollection();
201 void BeginUndoAction();
202 void EndUndoAction();
203
204
205 // Selection and information
206 void GetSelection(int* startPos, int* endPos);
207 void SetSelection(int startPos, int endPos);
208 wxString GetSelectedText();
209 void HideSelection(bool hide);
210 bool GetHideSelection();
211
212 int GetTextLength();
213 int GetFirstVisibleLine();
214 bool GetModified();
215 int GetLineCount();
216 wxRect GetRect();
217 int GetLineFromPos(int pos);
218 int GetLineStartPos(int line);
219 int GetLineLengthAtPos(int pos);
220 int GetLineLength(int line);
221 wxString GetCurrentLineText(int* linePos=NULL);
222 int GetCurrentLine();
223 int PositionFromPoint(wxPoint pt);
224 int LineFromPoint(wxPoint pt);
225 wxPoint PointFromPosition(int pos);
226 int GetCurrentPos();
227 int GetAnchor();
228 void SelectAll();
229 void SetCurrentPosition(int pos);
230 void SetAnchor(int pos);
231 void GotoPos(int pos);
232 void GotoLine(int line);
233 void ChangePosition(int delta, bool extendSelection);
234 void PageMove(int cmdKey, bool extendSelection);
235
236 void ScrollBy(int columnDelta, int lineDelta);
237 void ScrollToLine(int line);
238 void ScrollToColumn(int column);
239 void EnsureCaretVisible();
240 void SetCaretPolicy(int policy, int slop=0);
241 int GetSelectionType();
242
243
244
245 // Searching
246 int FindText(int minPos, int maxPos, const wxString& text,
247 bool caseSensitive, bool wholeWord);
248 void SearchAnchor();
249 int SearchNext(const wxString& text, bool caseSensitive, bool wholeWord);
250 int SearchPrev(const wxString& text, bool caseSensitive, bool wholeWord);
251
252
253 // Visible whitespace
254 bool GetViewWhitespace();
255 void SetViewWhitespace(bool visible);
256
257
258 // Line endings
259 wxSTC_EOL GetEOLMode();
260 void SetEOLMode(wxSTC_EOL mode);
261 bool GetViewEOL();
262 void SetViewEOL(bool visible);
263 void ConvertEOL(wxSTC_EOL mode);
264
265
266 // Styling
267 int GetEndStyled();
268 void StartStyling(int pos, int mask);
269 void SetStyleFor(int length, int style);
270 void SetStyleBytes(int length, char* styleBytes);
271
272
273 // Style Definition
274 void StyleClearAll();
275 void StyleResetDefault();
276 void StyleSetSpec(int styleNum, const wxString& spec);
277 void StyleSetForeground(int styleNum, const wxColour& colour);
278 void StyleSetBackground(int styleNum, const wxColour& colour);
279 void StyleSetFont(int styleNum, wxFont& font);
280 void StyleSetFontAttr(int styleNum, int size, const wxString& faceName, bool bold, bool italic);
281 void StyleSetBold(int styleNum, bool bold);
282 void StyleSetItalic(int styleNum, bool italic);
283 void StyleSetFaceName(int styleNum, const wxString& faceName);
284 void StyleSetSize(int styleNum, int pointSize);
285 void StyleSetEOLFilled(int styleNum, bool fillEOL);
286
287
288 // Margins in the edit area
289 int GetLeftMargin();
290 int GetRightMargin();
291 void SetMargins(int left, int right);
292
293
294 // Margins for selection, markers, etc.
295 void SetMarginType(int margin, int type);
296 int GetMarginType(int margin);
297 void SetMarginWidth(int margin, int pixelWidth);
298 int GetMarginWidth(int margin);
299 void SetMarginMask(int margin, int mask);
300 int GetMarginMask(int margin);
301 void SetMarginSensitive(int margin, bool sensitive);
302 bool GetMarginSensitive(int margin);
303
304
305 // Selection and Caret styles
306 void SetSelectionForeground(const wxColour& colour);
307 void SetSelectionBackground(const wxColour& colour);
308 void SetCaretForeground(const wxColour& colour);
309 int GetCaretPeriod();
310 void SetCaretPeriod(int milliseconds);
311
312
313 // Other settings
314 void SetBufferedDraw(bool isBuffered);
315 void SetTabWidth(int numChars);
316 void SetWordChars(const wxString& wordChars);
317
318
319 // Brace highlighting
320 void BraceHighlight(int pos1, int pos2);
321 void BraceBadlight(int pos);
322 int BraceMatch(int pos, int maxReStyle=0);
323
324
325 // Markers
326 void MarkerDefine(int markerNumber, int markerSymbol,
327 const wxColour& foreground,
328 const wxColour& background);
329 void MarkerSetType(int markerNumber, int markerSymbol);
330 void MarkerSetForeground(int markerNumber, const wxColour& colour);
331 void MarkerSetBackground(int markerNumber, const wxColour& colour);
332 int MarkerAdd(int line, int markerNumber);
333 void MarkerDelete(int line, int markerNumber);
334 void MarkerDeleteAll(int markerNumber);
335 int MarkerGet(int line);
336 int MarkerGetNextLine(int lineStart, int markerMask);
337 int MarkerGetPrevLine(int lineStart, int markerMask);
338 int MarkerLineFromHandle(int handle);
339 void MarkerDeleteHandle(int handle);
340
341
342 // Indicators
343 void IndicatorSetStyle(int indicNum, int indicStyle);
344 int IndicatorGetStyle(int indicNum);
345 void IndicatorSetColour(int indicNum, const wxColour& colour);
346
347
348 // Auto completion
349 void AutoCompShow(const wxString& listOfWords);
350 void AutoCompCancel();
351 bool AutoCompActive();
352 int AutoCompPosAtStart();
353 void AutoCompComplete();
354 void AutoCompStopChars(const wxString& stopChars);
355
356
357 // Call tips
358 void CallTipShow(int pos, const wxString& text);
359 void CallTipCancel();
360 bool CallTipActive();
361 int CallTipPosAtStart();
362 void CallTipSetHighlight(int start, int end);
363 void CallTipSetBackground(const wxColour& colour);
364
365
366 // Key bindings
367 void CmdKeyAssign(int key, int modifiers, int cmd);
368 void CmdKeyClear(int key, int modifiers);
369 void CmdKeyClearAll();
370 void CmdKeyExecute(int cmd);
371
372
373 // Print formatting
374 int FormatRange(bool doDraw,
375 int startPos,
376 int endPos,
377 wxDC* draw,
378 wxDC* target, // Why does it use two? Can they be the same?
379 wxRect renderRect,
380 wxRect pageRect);
381
382
383 // Document Sharing (multiple views)
384 void* GetDocument();
385 void SetDocument(void* document);
386 // TODO: create a wx wrapper for Scintilla's document class
387
388
389 // Folding
390 int VisibleFromDocLine(int docLine);
391 int DocLineFromVisible(int displayLine);
392 int SetFoldLevel(int line, int level);
393 int GetFoldLevel(int line);
394 int GetLastChild(int line);
395 int GetFoldParent(int line);
396 void ShowLines(int lineStart, int lineEnd);
397 void HideLines(int lineStart, int lineEnd);
398 bool GetLineVisible(int line);
399 void SetFoldExpanded(int line);
400 bool GetFoldExpanded(int line);
401 void ToggleFold(int line);
402 void EnsureVisible(int line);
403
404
405 // Long Lines
406 int GetEdgeColumn();
407 void SetEdgeColumn(int column);
408 wxSTC_EDGE GetEdgeMode();
409 void SetEdgeMode(wxSTC_EDGE mode);
410 wxColour GetEdgeColour();
411 void SetEdgeColour(const wxColour& colour);
412
413
414 // Lexer
415 void SetLexer(wxSTC_LEX lexer);
416 wxSTC_LEX GetLexer();
417 void Colourise(int start, int end);
418 void SetProperty(const wxString& key, const wxString& value);
419 void SetKeywords(int keywordSet, const wxString& keywordList);
420
421
422
423 private:
424 // Event handlers
425 void OnPaint(wxPaintEvent& evt);
426 void OnScrollWin(wxScrollWinEvent& evt);
427 void OnSize(wxSizeEvent& evt);
428 void OnMouseLeftDown(wxMouseEvent& evt);
429 void OnMouseMove(wxMouseEvent& evt);
430 void OnMouseLeftUp(wxMouseEvent& evt);
431 void OnMouseRightUp(wxMouseEvent& evt);
432 void OnChar(wxKeyEvent& evt);
433 void OnLoseFocus(wxFocusEvent& evt);
434 void OnGainFocus(wxFocusEvent& evt);
435 void OnSysColourChanged(wxSysColourChangedEvent& evt);
436 void OnEraseBackground(wxEraseEvent& evt);
437 void OnMenu(wxCommandEvent& evt);
438
439
440 // Turn notifications from Scintilla into events
441 void NotifyChange();
442 void NotifyParent(SCNotification* scn);
443
444 long SendMsg(int msg, long wp=0, long lp=0);
445
446 private:
447 DECLARE_EVENT_TABLE()
448
449 ScintillaWX* m_swx;
450 wxStopWatch m_stopWatch;
451 bool m_readOnly;
452 wxSTC_UndoType m_undoType;
453
454
455 friend class ScintillaWX;
456 friend class Platform;
457 };
458
459 //----------------------------------------------------------------------
460
461 class wxStyledTextEvent : public wxCommandEvent {
462 public:
463 wxStyledTextEvent(wxEventType commandType, int id);
464 ~wxStyledTextEvent() {}
465
466 void SetPosition(int pos) { m_position = pos; }
467 void SetKey(int k) { m_key = k; }
468 void SetModifiers(int m) { m_modifiers = m; }
469 void SetModificationType(int t) { m_modificationType = t; }
470 void SetText(const char* t) { m_text = t; }
471 void SetLength(int len) { m_length = len; }
472 void SetLinesAdded(int num) { m_linesAdded = num; }
473 void SetLine(int val) { m_line = val; }
474 void SetFoldLevelNow(int val) { m_foldLevelNow = val; }
475 void SetFoldLevelPrev(int val) { m_foldLevelPrev = val; }
476 void SetMargin(int val) { m_margin = val; }
477 void SetMessage(int val) { m_message = val; }
478 void SetWParam(int val) { m_wParam = val; }
479 void SetLParam(int val) { m_lParam = val; }
480
481 int GetPosition() const { return m_position; }
482 int GetKey() const { return m_key; }
483 int GetModifiers() const { return m_modifiers; }
484 int GetModificationType() const { return m_modificationType; }
485 wxString GetText() const { return m_text; }
486 int GetLength() const { return m_length; }
487 int GetLinesAdded() const { return m_linesAdded; }
488 int GetLine() const { return m_line; }
489 int GetFoldLevelNow() const { return m_foldLevelNow; }
490 int GetFoldLevelPrev() const { return m_foldLevelPrev; }
491 int GetMargin() const { return m_margin; }
492 int GetMessage() const { return m_message; }
493 int GetWParam() const { return m_wParam; }
494 int GetLParam() const { return m_lParam; }
495
496 bool GetShift() const;
497 bool GetControl() const;
498 bool GetAlt() const;
499
500 void CopyObject(wxObject& obj) const;
501
502 private:
503 int m_position;
504 int m_key;
505 int m_modifiers;
506
507 int m_modificationType; // wxEVT_STC_MODIFIED
508 wxString m_text;
509 int m_length;
510 int m_linesAdded;
511 int m_line;
512 int m_foldLevelNow;
513 int m_foldLevelPrev;
514
515 int m_margin; // wxEVT_STC_MARGINCLICK
516
517 int m_message; // wxEVT_STC_MACRORECORD
518 int m_wParam;
519 int m_lParam;
520
521 };
522
523
524
525 enum {
526 wxEVT_STC_CHANGE = 1650,
527 wxEVT_STC_STYLENEEDED,
528 wxEVT_STC_CHARADDED,
529 wxEVT_STC_UPDATEUI,
530 wxEVT_STC_SAVEPOINTREACHED,
531 wxEVT_STC_SAVEPOINTLEFT,
532 wxEVT_STC_ROMODIFYATTEMPT,
533 wxEVT_STC_DOUBLECLICK,
534 wxEVT_STC_MODIFIED,
535 wxEVT_STC_KEY,
536 wxEVT_STC_MACRORECORD,
537 wxEVT_STC_MARGINCLICK,
538 wxEVT_STC_NEEDSHOWN
539 };
540
541 typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&);
542
543 #define EVT_STC_CHANGE(id, fn) { wxEVT_STC_CHANGE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
544 #define EVT_STC_STYLENEEDED(id, fn) { wxEVT_STC_STYLENEEDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
545 #define EVT_STC_CHARADDED(id, fn) { wxEVT_STC_CHARADDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
546 #define EVT_STC_UPDATEUI(id, fn) { wxEVT_STC_UPDATEUI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
547 #define EVT_STC_SAVEPOINTREACHED(id, fn) { wxEVT_STC_SAVEPOINTREACHED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
548 #define EVT_STC_SAVEPOINTLEFT(id, fn) { wxEVT_STC_SAVEPOINTLEFT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
549 #define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
550 #define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
551 #define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
552 #define EVT_STC_CMDKEY(id, fn) { wxEVT_STC_CMDKEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
553 #define EVT_STC_UNKNOWNCMDKEY(id, fn) { wxEVT_STC_UNKNOWNCMDKEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL },
554
555
556 //----------------------------------------------------------------------
557 //----------------------------------------------------------------------
558 #endif
559
560