]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/textctrl.h
fixed the last of the off-by-one errors (some are refixed, again...)
[wxWidgets.git] / include / wx / msw / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: textctrl.h
3 // Purpose: wxTextCtrl class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_TEXTCTRL_H_
13 #define _WX_TEXTCTRL_H_
14
15 #ifdef __GNUG__
16 #pragma interface "textctrl.h"
17 #endif
18
19 class WXDLLEXPORT wxTextCtrl : public wxTextCtrlBase
20 {
21 public:
22 // creation
23 // --------
24
25 wxTextCtrl();
26 wxTextCtrl(wxWindow *parent, wxWindowID id,
27 const wxString& value = wxEmptyString,
28 const wxPoint& pos = wxDefaultPosition,
29 const wxSize& size = wxDefaultSize,
30 long style = 0,
31 const wxValidator& validator = wxDefaultValidator,
32 const wxString& name = wxTextCtrlNameStr)
33 {
34 Create(parent, id, value, pos, size, style, validator, name);
35 }
36
37 bool Create(wxWindow *parent, wxWindowID id,
38 const wxString& value = wxEmptyString,
39 const wxPoint& pos = wxDefaultPosition,
40 const wxSize& size = wxDefaultSize,
41 long style = 0,
42 const wxValidator& validator = wxDefaultValidator,
43 const wxString& name = wxTextCtrlNameStr);
44
45 // implement base class pure virtuals
46 // ----------------------------------
47
48 virtual wxString GetValue() const;
49 virtual void SetValue(const wxString& value);
50
51 virtual int GetLineLength(long lineNo) const;
52 virtual wxString GetLineText(long lineNo) const;
53 virtual int GetNumberOfLines() const;
54
55 virtual bool IsModified() const;
56 virtual bool IsEditable() const;
57
58 // If the return values from and to are the same, there is no selection.
59 virtual void GetSelection(long* from, long* to) const;
60
61 // operations
62 // ----------
63
64 // editing
65 virtual void Clear();
66 virtual void Replace(long from, long to, const wxString& value);
67 virtual void Remove(long from, long to);
68
69 // load the controls contents from the file
70 virtual bool LoadFile(const wxString& file);
71
72 // clears the dirty flag
73 virtual void DiscardEdits();
74
75 // writing text inserts it at the current position, appending always
76 // inserts it at the end
77 virtual void WriteText(const wxString& text);
78 virtual void AppendText(const wxString& text);
79
80 #if wxUSE_RICHEDIT
81 // apply text attribute to the range of text (only works with richedit
82 // controls)
83 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
84 #endif // wxUSE_RICHEDIT
85
86 // translate between the position (which is just an index in the text ctrl
87 // considering all its contents as a single strings) and (x, y) coordinates
88 // which represent column and line.
89 virtual long XYToPosition(long x, long y) const;
90 virtual bool PositionToXY(long pos, long *x, long *y) const;
91
92 virtual void ShowPosition(long pos);
93
94 // Clipboard operations
95 virtual void Copy();
96 virtual void Cut();
97 virtual void Paste();
98
99 virtual bool CanCopy() const;
100 virtual bool CanCut() const;
101 virtual bool CanPaste() const;
102
103 // Undo/redo
104 virtual void Undo();
105 virtual void Redo();
106
107 virtual bool CanUndo() const;
108 virtual bool CanRedo() const;
109
110 // Insertion point
111 virtual void SetInsertionPoint(long pos);
112 virtual void SetInsertionPointEnd();
113 virtual long GetInsertionPoint() const;
114 virtual long GetLastPosition() const;
115
116 virtual void SetSelection(long from, long to);
117 virtual void SetEditable(bool editable);
118
119 // Implementation from now on
120 // --------------------------
121
122 virtual void Command(wxCommandEvent& event);
123 virtual bool MSWCommand(WXUINT param, WXWORD id);
124 virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
125 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
126
127 // In WIN16, need to override normal erasing because
128 // Ctl3D doesn't use the wxWindows background colour.
129 #ifdef __WIN16__
130 void OnEraseBackground(wxEraseEvent& event);
131 #endif
132
133 #if wxUSE_RICHEDIT
134 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
135
136 bool IsRich() const { return m_isRich; }
137 void SetRichEdit(bool isRich) { m_isRich = isRich; }
138
139 // rich edit controls are not compatible with normal ones and wem ust set
140 // the colours for them otherwise
141 virtual bool SetBackgroundColour(const wxColour& colour);
142 virtual bool SetForegroundColour(const wxColour& colour);
143 #endif // wxUSE_RICHEDIT
144
145 virtual void AdoptAttributesFromHWND();
146 virtual void SetupColours();
147
148 virtual bool AcceptsFocus() const;
149
150 // callbacks
151 void OnDropFiles(wxDropFilesEvent& event);
152 void OnChar(wxKeyEvent& event); // Process 'enter' if required
153
154 void OnCut(wxCommandEvent& event);
155 void OnCopy(wxCommandEvent& event);
156 void OnPaste(wxCommandEvent& event);
157 void OnUndo(wxCommandEvent& event);
158 void OnRedo(wxCommandEvent& event);
159
160 void OnUpdateCut(wxUpdateUIEvent& event);
161 void OnUpdateCopy(wxUpdateUIEvent& event);
162 void OnUpdatePaste(wxUpdateUIEvent& event);
163 void OnUpdateUndo(wxUpdateUIEvent& event);
164 void OnUpdateRedo(wxUpdateUIEvent& event);
165
166 protected:
167 #if wxUSE_RICHEDIT
168 bool m_isRich; // Are we using rich text edit to implement this?
169 #endif
170
171 // call this to increase the size limit (will do nothing if the current
172 // limit is big enough)
173 void AdjustSpaceLimit();
174
175 // override some base class virtuals
176 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
177 virtual wxSize DoGetBestSize() const;
178
179 private:
180 DECLARE_EVENT_TABLE()
181 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
182 };
183
184 #endif
185 // _WX_TEXTCTRL_H_