File: textctrl.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (385 lines) | stat: -rw-r--r-- 12,050 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/x11/textctrl.h
// Purpose:
// Author:      Robert Roebling
// Created:     01/02/97
// Copyright:   (c) 1998 Robert Roebling
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef __X11TEXTCTRLH__
#define __X11TEXTCTRLH__

// Set to 1 to use wxUniv's implementation, 0
// to use wxX11's.
#define wxUSE_UNIV_TEXTCTRL 1

#if wxUSE_UNIV_TEXTCTRL
#include "wx/univ/textctrl.h"
#else

#include "wx/scrolwin.h"
#include "wx/arrstr.h"

//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------

class WXDLLIMPEXP_FWD_CORE wxTextCtrl;

//-----------------------------------------------------------------------------
// helpers
//-----------------------------------------------------------------------------

enum wxSourceUndo
{
    wxSOURCE_UNDO_LINE,
    wxSOURCE_UNDO_ENTER,
    wxSOURCE_UNDO_BACK,
    wxSOURCE_UNDO_INSERT_LINE,
    wxSOURCE_UNDO_DELETE,
    wxSOURCE_UNDO_PASTE
};

class wxSourceUndoStep: public wxObject
{
public:
    wxSourceUndoStep( wxSourceUndo type, int y1, int y2, wxTextCtrl *owner );

    void Undo();

    wxSourceUndo    m_type;
    int             m_y1;
    int             m_y2;
    int             m_cursorX;
    int             m_cursorY;
    wxTextCtrl     *m_owner;
    wxString        m_text;
    wxArrayString   m_lines;
};

class wxSourceLine
{
public:
    wxSourceLine( const wxString &text = wxEmptyString )
    {
        m_text = text;
    }

    wxString       m_text;
};

WX_DECLARE_OBJARRAY(wxSourceLine, wxSourceLineArray);

enum wxSourceLanguage
{
    wxSOURCE_LANG_NONE,
    wxSOURCE_LANG_CPP,
    wxSOURCE_LANG_PERL,
    wxSOURCE_LANG_PYTHON
};

//-----------------------------------------------------------------------------
// wxTextCtrl
//-----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase, public wxScrollHelper
{
public:
    wxTextCtrl() { Init(); }
    wxTextCtrl(wxWindow *parent,
               wxWindowID id,
               const wxString &value = wxEmptyString,
               const wxPoint &pos = wxDefaultPosition,
               const wxSize &size = wxDefaultSize,
               long style = 0,
               const wxValidator& validator = wxDefaultValidator,
               const wxString &name = wxTextCtrlNameStr);
    virtual ~wxTextCtrl();

    bool Create(wxWindow *parent,
                wxWindowID id,
                const wxString &value = wxEmptyString,
                const wxPoint &pos = wxDefaultPosition,
                const wxSize &size = wxDefaultSize,
                long style = 0,
                const wxValidator& validator = wxDefaultValidator,
                const wxString &name = wxTextCtrlNameStr);

    // required for scrolling with wxScrollHelper
    // ------------------------------------------

    virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }

    // implement base class pure virtuals
    // ----------------------------------

    virtual void ChangeValue(const wxString &value);

    virtual int GetLineLength(long lineNo) const;
    virtual wxString GetLineText(long lineNo) const;
    virtual int GetNumberOfLines() const;

    virtual bool IsModified() const;
    virtual bool IsEditable() const;

    // more readable flag testing methods
    // ----------------------------------

    bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; }
    bool WrapLines() const { return false; }

    // If the return values from and to are the same, there is no selection.
    virtual void GetSelection(long* from, long* to) const;

    // operations
    // ----------

    // editing
    virtual void Clear();
    virtual void Replace(long from, long to, const wxString& value);
    virtual void Remove(long from, long to);

    // clears the dirty flag
    virtual void DiscardEdits();

    virtual void SetMaxLength(unsigned long len);

    // writing text inserts it at the current position, appending always
    // inserts it at the end
    virtual void WriteText(const wxString& text);
    virtual void AppendText(const wxString& text);

    // apply text attribute to the range of text (only works with richedit
    // controls)
    virtual bool SetStyle(long start, long end, const wxTextAttr& style);

    // translate between the position (which is just an index in the text ctrl
    // considering all its contents as a single strings) and (x, y) coordinates
    // which represent column and line.
    virtual long XYToPosition(long x, long y) const;
    virtual bool PositionToXY(long pos, long *x, long *y) const;

    virtual void ShowPosition(long pos);

    // Clipboard operations
    virtual void Copy();
    virtual void Cut();
    virtual void Paste();

    // Undo/redo
    virtual void Undo();
    virtual void Redo() {}

    virtual bool CanUndo() const    { return (m_undos.GetCount() > 0); }
    virtual bool CanRedo() const    { return false; }

    // Insertion point
    virtual void SetInsertionPoint(long pos);
    virtual void SetInsertionPointEnd();
    virtual long GetInsertionPoint() const;
    virtual wxTextPos GetLastPosition() const;

    virtual void SetSelection(long from, long to);
    virtual void SetEditable(bool editable);

    virtual bool Enable( bool enable = true );

    void OnCut(wxCommandEvent& event);
    void OnCopy(wxCommandEvent& event);
    void OnPaste(wxCommandEvent& event);
    void OnUndo(wxCommandEvent& event);
    void OnRedo(wxCommandEvent& event);

    void OnUpdateCut(wxUpdateUIEvent& event);
    void OnUpdateCopy(wxUpdateUIEvent& event);
    void OnUpdatePaste(wxUpdateUIEvent& event);
    void OnUpdateUndo(wxUpdateUIEvent& event);
    void OnUpdateRedo(wxUpdateUIEvent& event);

    bool SetFont(const wxFont& font);
    bool SetForegroundColour(const wxColour& colour);
    bool SetBackgroundColour(const wxColour& colour);

    void SetModified() { m_modified = true; }

    // textctrl specific scrolling
    virtual bool ScrollLines(int lines);
    virtual bool ScrollPages(int pages);

    // not part of the wxTextCtrl API from now on..

    void SetLanguage( wxSourceLanguage lang = wxSOURCE_LANG_NONE );

    void Delete();
    void DeleteLine();

    void Indent();
    void Unindent();

    bool HasSelection();
    void ClearSelection();

    int GetCursorX()                        { return m_cursorX; }
    int GetCursorY()                        { return m_cursorY; }
    bool IsModified()                       { return m_modified; }
    bool OverwriteMode()                    { return m_overwrite; }

    // implementation from now on...

    int PosToPixel( int line, int pos );
    int PixelToPos( int line, int pixel );

    void SearchForBrackets();

    void DoChar( char c );
    void DoBack();
    void DoDelete();
    void DoReturn();
    void DoDClick();

    wxString GetNextToken( wxString &line, size_t &pos );

    void DrawLinePart( wxDC &dc, int x, int y, const wxString &toDraw, const wxString &origin, const wxColour &colour);
    void DrawLine( wxDC &dc, int x, int y, const wxString &line, int lineNum );
    void OnPaint( wxPaintEvent &event );
    void OnEraseBackground( wxEraseEvent &event );
    void OnMouse( wxMouseEvent &event );
    void OnChar( wxKeyEvent &event );
    void OnSetFocus( wxFocusEvent& event );
    void OnKillFocus( wxFocusEvent& event );

    void OnInternalIdle();
    void RefreshLine( int n );
    void RefreshDown( int n );
    void MoveCursor( int new_x, int new_y, bool shift = false, bool centre = false );
    void MyAdjustScrollbars();

protected:
    // common part of all ctors
    void Init();

    virtual wxSize DoGetBestSize() const;

    virtual void DoSetValue(const wxString& value, int flags = 0);

    friend class wxSourceUndoStep;

    wxSourceLineArray  m_lines;

    wxFont             m_sourceFont;
    wxColour           m_sourceColour;
    wxColour           m_commentColour;
    wxColour           m_stringColour;

    int                m_cursorX;
    int                m_cursorY;

    int                m_selStartX,m_selStartY;
    int                m_selEndX,m_selEndY;

    int                m_lineHeight;
    int                m_charWidth;

    int                m_longestLine;

    bool               m_overwrite;
    bool               m_modified;
    bool               m_editable;
    bool               m_ignoreInput;

    wxArrayString      m_keywords;
    wxColour           m_keywordColour;

    wxArrayString      m_defines;
    wxColour           m_defineColour;

    wxArrayString      m_variables;
    wxColour           m_variableColour;

    wxSourceLanguage   m_lang;

    wxList             m_undos;

    bool               m_capturing;

    int                m_bracketX;
    int                m_bracketY;

private:
    DECLARE_EVENT_TABLE()
    DECLARE_DYNAMIC_CLASS(wxTextCtrl);
};

//-----------------------------------------------------------------------------
// this is superfluous here but helps to compile
//-----------------------------------------------------------------------------

// cursor movement and also selection and delete operations
#define wxACTION_TEXT_GOTO          wxT("goto")  // to pos in numArg
#define wxACTION_TEXT_FIRST         wxT("first") // go to pos 0
#define wxACTION_TEXT_LAST          wxT("last")  // go to last pos
#define wxACTION_TEXT_HOME          wxT("home")
#define wxACTION_TEXT_END           wxT("end")
#define wxACTION_TEXT_LEFT          wxT("left")
#define wxACTION_TEXT_RIGHT         wxT("right")
#define wxACTION_TEXT_UP            wxT("up")
#define wxACTION_TEXT_DOWN          wxT("down")
#define wxACTION_TEXT_WORD_LEFT     wxT("wordleft")
#define wxACTION_TEXT_WORD_RIGHT    wxT("wordright")
#define wxACTION_TEXT_PAGE_UP       wxT("pageup")
#define wxACTION_TEXT_PAGE_DOWN     wxT("pagedown")

// clipboard operations
#define wxACTION_TEXT_COPY          wxT("copy")
#define wxACTION_TEXT_CUT           wxT("cut")
#define wxACTION_TEXT_PASTE         wxT("paste")

// insert text at the cursor position: the text is in strArg of PerformAction
#define wxACTION_TEXT_INSERT        wxT("insert")

// if the action starts with either of these prefixes and the rest of the
// string is one of the movement commands, it means to select/delete text from
// the current cursor position to the new one
#define wxACTION_TEXT_PREFIX_SEL    wxT("sel")
#define wxACTION_TEXT_PREFIX_DEL    wxT("del")

// mouse selection
#define wxACTION_TEXT_ANCHOR_SEL    wxT("anchorsel")
#define wxACTION_TEXT_EXTEND_SEL    wxT("extendsel")
#define wxACTION_TEXT_SEL_WORD      wxT("wordsel")
#define wxACTION_TEXT_SEL_LINE      wxT("linesel")

// undo or redo
#define wxACTION_TEXT_UNDO          wxT("undo")
#define wxACTION_TEXT_REDO          wxT("redo")

// ----------------------------------------------------------------------------
// wxTextCtrl types
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxStdTextCtrlInputHandler : public wxStdInputHandler
{
public:
    wxStdTextCtrlInputHandler(wxInputHandler *inphand) : wxStdInputHandler(inphand) {}

    virtual bool HandleKey(wxInputConsumer *consumer,
                           const wxKeyEvent& event,
                           bool pressed) { return false; }
    virtual bool HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { return false; }
    virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event) { return false; }
    virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event) { return false; }

protected:
    // get the position of the mouse click
    static wxTextPos HitTest(const wxTextCtrl *text, const wxPoint& pos) { return 0; }

    // capture data
    wxTextCtrl *m_winCapture;
};

#endif
// wxUSE_UNIV_TEXTCTRL

#endif // __X11TEXTCTRLH__