]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/textctrl.h
1. DoSetSize() simplified, DoGetBestSize() introduced
[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 #include "wx/setup.h"
20 #include "wx/control.h"
21
22 #if wxUSE_IOSTREAMH
23 #include <iostream.h>
24 #else
25 #include <iostream>
26 #endif
27
28 #if defined(__WIN95__) && !defined(__TWIN32__) && !defined(__WXWINE__)
29 #define wxUSE_RICHEDIT 1
30 #else
31 #define wxUSE_RICHEDIT 0
32 #endif
33
34 WXDLLEXPORT_DATA(extern const wxChar*) wxTextCtrlNameStr;
35 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
36
37 // Single-line text item
38 class WXDLLEXPORT wxTextCtrl : public wxControl
39
40 // 16-bit Borland 4.0 doesn't seem to allow multiple inheritance with wxWindow and streambuf:
41 // it complains about deriving a huge class from the huge class streambuf. !!
42 // Also, can't use streambuf if making or using a DLL :-(
43
44 #if (defined(__BORLANDC__)) || defined(__MWERKS__) || defined(_WINDLL) || defined(WXUSINGDLL) || defined(WXMAKINGDLL)
45 #define NO_TEXT_WINDOW_STREAM
46 #endif
47
48 #ifndef NO_TEXT_WINDOW_STREAM
49 , public streambuf
50 #endif
51
52 {
53 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
54
55 public:
56 // creation
57 // --------
58 wxTextCtrl();
59 wxTextCtrl(wxWindow *parent, wxWindowID id,
60 const wxString& value = wxEmptyString,
61 const wxPoint& pos = wxDefaultPosition,
62 const wxSize& size = wxDefaultSize,
63 long style = 0,
64 const wxValidator& validator = wxDefaultValidator,
65 const wxString& name = wxTextCtrlNameStr)
66 #ifndef NO_TEXT_WINDOW_STREAM
67 :streambuf()
68 #endif
69 {
70 Create(parent, id, value, pos, size, style, validator, name);
71 }
72
73 bool Create(wxWindow *parent, wxWindowID id,
74 const wxString& value = wxEmptyString,
75 const wxPoint& pos = wxDefaultPosition,
76 const wxSize& size = wxDefaultSize,
77 long style = 0,
78 const wxValidator& validator = wxDefaultValidator,
79 const wxString& name = wxTextCtrlNameStr);
80
81 // accessors
82 // ---------
83
84 virtual wxString GetValue() const;
85 virtual void SetValue(const wxString& value);
86
87 virtual int GetLineLength(long lineNo) const;
88 virtual wxString GetLineText(long lineNo) const;
89 virtual int GetNumberOfLines() const;
90
91 // operations
92 // ----------
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 virtual void SetInsertionPoint(long pos);
111 virtual void SetInsertionPointEnd();
112 virtual long GetInsertionPoint() const ;
113 virtual long GetLastPosition() const ;
114 virtual void Replace(long from, long to, const wxString& value);
115 virtual void Remove(long from, long to);
116 virtual void SetSelection(long from, long to);
117 virtual void SetEditable(bool editable);
118
119 // If the return values from and to are the same, there is no
120 // selection.
121 virtual void GetSelection(long* from, long* to) const;
122 virtual bool IsEditable() const ;
123
124 // streambuf implementation
125 #ifndef NO_TEXT_WINDOW_STREAM
126 int overflow(int i);
127 int sync();
128 int underflow();
129 #endif
130
131 wxTextCtrl& operator<<(const wxString& s);
132 wxTextCtrl& operator<<(int i);
133 wxTextCtrl& operator<<(long i);
134 wxTextCtrl& operator<<(float f);
135 wxTextCtrl& operator<<(double d);
136 wxTextCtrl& operator<<(const char c);
137
138 virtual bool LoadFile(const wxString& file);
139 virtual bool SaveFile(const wxString& file);
140 virtual void WriteText(const wxString& text);
141 virtual void AppendText(const wxString& text);
142 virtual void DiscardEdits();
143 virtual bool IsModified() const;
144
145 #if WXWIN_COMPATIBILITY
146 inline bool Modified() const { return IsModified(); }
147 #endif
148
149 virtual long XYToPosition(long x, long y) const ;
150 virtual void PositionToXY(long pos, long *x, long *y) const ;
151 virtual void ShowPosition(long pos);
152 virtual void Clear();
153
154 // Implementation from now on
155 // --------------------------
156
157 virtual void Command(wxCommandEvent& event);
158 virtual bool MSWCommand(WXUINT param, WXWORD id);
159
160 #if wxUSE_RICHEDIT
161 bool IsRich() const { return m_isRich; }
162 void SetRichEdit(bool isRich) { m_isRich = isRich; }
163 #endif
164
165 virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
166 WXUINT message, WXWPARAM wParam,
167 WXLPARAM lParam);
168
169 virtual void AdoptAttributesFromHWND();
170 virtual void SetupColours();
171
172 virtual bool AcceptsFocus() const;
173
174 // callbacks
175 // ---------
176 void OnDropFiles(wxDropFilesEvent& event);
177 void OnChar(wxKeyEvent& event); // Process 'enter' if required
178
179 void OnCut(wxCommandEvent& event);
180 void OnCopy(wxCommandEvent& event);
181 void OnPaste(wxCommandEvent& event);
182 void OnUndo(wxCommandEvent& event);
183 void OnRedo(wxCommandEvent& event);
184
185 void OnUpdateCut(wxUpdateUIEvent& event);
186 void OnUpdateCopy(wxUpdateUIEvent& event);
187 void OnUpdatePaste(wxUpdateUIEvent& event);
188 void OnUpdateUndo(wxUpdateUIEvent& event);
189 void OnUpdateRedo(wxUpdateUIEvent& event);
190
191 protected:
192 #if wxUSE_RICHEDIT
193 bool m_isRich; // Are we using rich text edit to implement this?
194 #endif
195
196 wxString m_fileName;
197
198 // call this to increase the size limit (will do nothing if the current
199 // limit is big enough)
200 void AdjustSpaceLimit();
201
202 virtual wxSize DoGetBestSize();
203
204 private:
205 DECLARE_EVENT_TABLE()
206 };
207
208 #endif
209 // _WX_TEXTCTRL_H_