]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
40ff126a | 2 | // Name: src/msw/textctrl.cpp |
2bda0e17 KB |
3 | // Purpose: wxTextCtrl |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a1b82138 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
a1b82138 VZ |
16 | // ---------------------------------------------------------------------------- |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
a1b82138 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
3180bc0e | 27 | #if wxUSE_TEXTCTRL && !(defined(__SMARTPHONE__) && defined(__WXWINCE__)) |
1e6feb95 | 28 | |
2bda0e17 | 29 | #ifndef WX_PRECOMP |
a1b82138 VZ |
30 | #include "wx/textctrl.h" |
31 | #include "wx/settings.h" | |
32 | #include "wx/brush.h" | |
33 | #include "wx/utils.h" | |
381dd4bf | 34 | #include "wx/intl.h" |
a1b82138 | 35 | #include "wx/log.h" |
381dd4bf | 36 | #include "wx/app.h" |
2b5f62a0 | 37 | #include "wx/menu.h" |
e2bcbdfb | 38 | #include "wx/math.h" |
02761f6c | 39 | #include "wx/module.h" |
2bda0e17 KB |
40 | #endif |
41 | ||
8ef51d67 | 42 | #include "wx/sysopt.h" |
f6bcfd97 | 43 | |
47d67540 | 44 | #if wxUSE_CLIPBOARD |
a1b82138 | 45 | #include "wx/clipbrd.h" |
2bda0e17 KB |
46 | #endif |
47 | ||
a1b82138 VZ |
48 | #include "wx/textfile.h" |
49 | ||
50 | #include <windowsx.h> | |
51 | ||
2bda0e17 | 52 | #include "wx/msw/private.h" |
9a88fc58 | 53 | #include "wx/msw/winundef.h" |
8f825d89 | 54 | #include "wx/msw/mslu.h" |
2bda0e17 | 55 | |
a1b82138 | 56 | #include <string.h> |
2bda0e17 | 57 | #include <stdlib.h> |
4676948b JS |
58 | |
59 | #ifndef __WXWINCE__ | |
a1b82138 | 60 | #include <sys/types.h> |
4676948b | 61 | #endif |
fbc535ff | 62 | |
a40c9444 VZ |
63 | #if wxUSE_RICHEDIT |
64 | ||
8ef51d67 JS |
65 | #if wxUSE_INKEDIT |
66 | #include "wx/dynlib.h" | |
67 | #endif | |
68 | ||
a40c9444 VZ |
69 | // old mingw32 has richedit stuff directly in windows.h and doesn't have |
70 | // richedit.h at all | |
71 | #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) | |
cd471848 | 72 | #include <richedit.h> |
2bda0e17 KB |
73 | #endif |
74 | ||
a40c9444 VZ |
75 | #endif // wxUSE_RICHEDIT |
76 | ||
7212d155 PC |
77 | #include "wx/msw/missing.h" |
78 | ||
b12915c1 VZ |
79 | // ---------------------------------------------------------------------------- |
80 | // private classes | |
81 | // ---------------------------------------------------------------------------- | |
82 | ||
83 | #if wxUSE_RICHEDIT | |
84 | ||
a5aa8086 | 85 | // this module initializes RichEdit DLL(s) if needed |
b12915c1 VZ |
86 | class wxRichEditModule : public wxModule |
87 | { | |
88 | public: | |
628c219e VZ |
89 | enum Version |
90 | { | |
91 | Version_1, // riched32.dll | |
92 | Version_2or3, // both use riched20.dll | |
93 | Version_41, // msftedit.dll (XP SP1 and Windows 2003) | |
94 | Version_Max | |
95 | }; | |
96 | ||
b12915c1 VZ |
97 | virtual bool OnInit(); |
98 | virtual void OnExit(); | |
99 | ||
628c219e VZ |
100 | // load the richedit DLL for the specified version of rich edit |
101 | static bool Load(Version version); | |
b12915c1 | 102 | |
8ef51d67 JS |
103 | #if wxUSE_INKEDIT |
104 | // load the InkEdit library | |
105 | static bool LoadInkEdit(); | |
106 | #endif | |
107 | ||
b12915c1 | 108 | private: |
a5aa8086 | 109 | // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs |
628c219e | 110 | static HINSTANCE ms_hRichEdit[Version_Max]; |
b12915c1 | 111 | |
8ef51d67 JS |
112 | #if wxUSE_INKEDIT |
113 | static wxDynamicLibrary ms_inkEditLib; | |
114 | static bool ms_inkEditLibLoadAttemped; | |
115 | #endif | |
116 | ||
b12915c1 VZ |
117 | DECLARE_DYNAMIC_CLASS(wxRichEditModule) |
118 | }; | |
119 | ||
628c219e | 120 | HINSTANCE wxRichEditModule::ms_hRichEdit[Version_Max] = { NULL, NULL, NULL }; |
b12915c1 | 121 | |
8ef51d67 JS |
122 | #if wxUSE_INKEDIT |
123 | wxDynamicLibrary wxRichEditModule::ms_inkEditLib; | |
124 | bool wxRichEditModule::ms_inkEditLibLoadAttemped = false; | |
125 | #endif | |
126 | ||
b12915c1 VZ |
127 | IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule, wxModule) |
128 | ||
129 | #endif // wxUSE_RICHEDIT | |
e702ff0f | 130 | |
2c62dd25 VZ |
131 | // a small class used to set m_updatesCount to 0 (to filter duplicate events if |
132 | // necessary) and to reset it back to -1 afterwards | |
133 | class UpdatesCountFilter | |
134 | { | |
135 | public: | |
136 | UpdatesCountFilter(int& count) | |
137 | : m_count(count) | |
138 | { | |
f6519b40 VZ |
139 | wxASSERT_MSG( m_count == -1 || m_count == -2, |
140 | _T("wrong initial m_updatesCount value") ); | |
2c62dd25 | 141 | |
f6519b40 VZ |
142 | if (m_count != -2) |
143 | m_count = 0; | |
144 | //else: we don't want to count how many update events we get as we're going | |
145 | // to ignore all of them | |
2c62dd25 VZ |
146 | } |
147 | ||
148 | ~UpdatesCountFilter() | |
149 | { | |
150 | m_count = -1; | |
151 | } | |
152 | ||
153 | // return true if an event has been received | |
154 | bool GotUpdate() const | |
155 | { | |
156 | return m_count == 1; | |
157 | } | |
158 | ||
159 | private: | |
160 | int& m_count; | |
161 | ||
162 | DECLARE_NO_COPY_CLASS(UpdatesCountFilter) | |
163 | }; | |
164 | ||
a1b82138 VZ |
165 | // ---------------------------------------------------------------------------- |
166 | // event tables and other macros | |
167 | // ---------------------------------------------------------------------------- | |
168 | ||
51741307 | 169 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
170 | WX_DEFINE_FLAGS( wxTextCtrlStyle ) |
171 | ||
321239b6 | 172 | wxBEGIN_FLAGS( wxTextCtrlStyle ) |
bc9fb572 JS |
173 | // new style border flags, we put them first to |
174 | // use them for streaming out | |
321239b6 SC |
175 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
176 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
177 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
178 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
179 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
180 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
bfbb0b4c | 181 | |
bc9fb572 | 182 | // old style border flags |
321239b6 SC |
183 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
184 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
185 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
186 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
187 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 188 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
189 | |
190 | // standard window styles | |
321239b6 SC |
191 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
192 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
193 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
194 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 195 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
321239b6 SC |
196 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
197 | wxFLAGS_MEMBER(wxVSCROLL) | |
198 | wxFLAGS_MEMBER(wxHSCROLL) | |
199 | ||
200 | wxFLAGS_MEMBER(wxTE_PROCESS_ENTER) | |
201 | wxFLAGS_MEMBER(wxTE_PROCESS_TAB) | |
202 | wxFLAGS_MEMBER(wxTE_MULTILINE) | |
203 | wxFLAGS_MEMBER(wxTE_PASSWORD) | |
204 | wxFLAGS_MEMBER(wxTE_READONLY) | |
205 | wxFLAGS_MEMBER(wxHSCROLL) | |
206 | wxFLAGS_MEMBER(wxTE_RICH) | |
207 | wxFLAGS_MEMBER(wxTE_RICH2) | |
208 | wxFLAGS_MEMBER(wxTE_AUTO_URL) | |
209 | wxFLAGS_MEMBER(wxTE_NOHIDESEL) | |
210 | wxFLAGS_MEMBER(wxTE_LEFT) | |
211 | wxFLAGS_MEMBER(wxTE_CENTRE) | |
212 | wxFLAGS_MEMBER(wxTE_RIGHT) | |
213 | wxFLAGS_MEMBER(wxTE_DONTWRAP) | |
40ff126a | 214 | wxFLAGS_MEMBER(wxTE_CHARWRAP) |
321239b6 SC |
215 | wxFLAGS_MEMBER(wxTE_WORDWRAP) |
216 | ||
217 | wxEND_FLAGS( wxTextCtrlStyle ) | |
bc9fb572 | 218 | |
51741307 SC |
219 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl, wxControl,"wx/textctrl.h") |
220 | ||
321239b6 | 221 | wxBEGIN_PROPERTIES_TABLE(wxTextCtrl) |
bfbb0b4c | 222 | wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) |
321239b6 | 223 | wxEVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent ) |
c5ca409b | 224 | |
af498247 | 225 | wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) |
bfbb0b4c | 226 | wxPROPERTY( Value , wxString , SetValue, GetValue, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
af498247 | 227 | wxPROPERTY_FLAGS( WindowStyle , wxTextCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
321239b6 | 228 | wxEND_PROPERTIES_TABLE() |
51741307 | 229 | |
321239b6 SC |
230 | wxBEGIN_HANDLERS_TABLE(wxTextCtrl) |
231 | wxEND_HANDLERS_TABLE() | |
51741307 | 232 | |
321239b6 | 233 | wxCONSTRUCTOR_6( wxTextCtrl , wxWindow* , Parent , wxWindowID , Id , wxString , Value , wxPoint , Position , wxSize , Size , long , WindowStyle) |
51741307 | 234 | #else |
9d112688 | 235 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) |
51741307 SC |
236 | #endif |
237 | ||
2bda0e17 | 238 | |
9d112688 | 239 | BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) |
a1b82138 VZ |
240 | EVT_CHAR(wxTextCtrl::OnChar) |
241 | EVT_DROP_FILES(wxTextCtrl::OnDropFiles) | |
242 | ||
2b5f62a0 | 243 | #if wxUSE_RICHEDIT |
26f60eb6 | 244 | EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu) |
2b5f62a0 VZ |
245 | #endif |
246 | ||
a1b82138 VZ |
247 | EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) |
248 | EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) | |
249 | EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) | |
250 | EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) | |
251 | EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) | |
2b5f62a0 VZ |
252 | EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete) |
253 | EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll) | |
a1b82138 VZ |
254 | |
255 | EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) | |
256 | EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) | |
257 | EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) | |
258 | EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) | |
259 | EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) | |
2b5f62a0 VZ |
260 | EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete) |
261 | EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll) | |
e3a6a6b2 VZ |
262 | |
263 | EVT_SET_FOCUS(wxTextCtrl::OnSetFocus) | |
2bda0e17 | 264 | END_EVENT_TABLE() |
e702ff0f | 265 | |
a1b82138 VZ |
266 | // ============================================================================ |
267 | // implementation | |
268 | // ============================================================================ | |
269 | ||
270 | // ---------------------------------------------------------------------------- | |
271 | // creation | |
272 | // ---------------------------------------------------------------------------- | |
273 | ||
aac7e7fe | 274 | void wxTextCtrl::Init() |
2bda0e17 | 275 | { |
cd471848 | 276 | #if wxUSE_RICHEDIT |
aac7e7fe | 277 | m_verRichEdit = 0; |
2b5f62a0 | 278 | #endif // wxUSE_RICHEDIT |
5036ea90 | 279 | |
8ef51d67 JS |
280 | #if wxUSE_INKEDIT && wxUSE_RICHEDIT |
281 | m_isInkEdit = 0; | |
282 | #endif | |
283 | ||
2b5f62a0 | 284 | m_privateContextMenu = NULL; |
2c62dd25 | 285 | m_updatesCount = -1; |
e3a6a6b2 | 286 | m_isNativeCaretShown = true; |
2b5f62a0 VZ |
287 | } |
288 | ||
289 | wxTextCtrl::~wxTextCtrl() | |
290 | { | |
caea50ac | 291 | delete m_privateContextMenu; |
2bda0e17 KB |
292 | } |
293 | ||
9b99c1e3 VZ |
294 | bool wxTextCtrl::Create(wxWindow *parent, |
295 | wxWindowID id, | |
c085e333 VZ |
296 | const wxString& value, |
297 | const wxPoint& pos, | |
a1b82138 VZ |
298 | const wxSize& size, |
299 | long style, | |
c085e333 VZ |
300 | const wxValidator& validator, |
301 | const wxString& name) | |
2bda0e17 | 302 | { |
3d4ea84b RR |
303 | #ifdef __WXWINCE__ |
304 | if ((style & wxBORDER_MASK) == 0) | |
305 | style |= wxBORDER_SIMPLE; | |
306 | #endif | |
307 | ||
a1b82138 | 308 | // base initialization |
f4d233c7 | 309 | if ( !CreateControl(parent, id, pos, size, style, validator, name) ) |
bfbb0b4c | 310 | return false; |
2bda0e17 | 311 | |
9b99c1e3 VZ |
312 | if ( !MSWCreateText(value, pos, size) ) |
313 | return false; | |
314 | ||
315 | return true; | |
316 | } | |
317 | ||
318 | bool wxTextCtrl::MSWCreateText(const wxString& value, | |
319 | const wxPoint& pos, | |
320 | const wxSize& size) | |
321 | { | |
b2d5a7ee VZ |
322 | // translate wxWin style flags to MSW ones |
323 | WXDWORD msStyle = MSWGetCreateWindowFlags(); | |
cfdd3a98 | 324 | |
a1b82138 | 325 | // do create the control - either an EDIT or RICHEDIT |
b12915c1 | 326 | wxString windowClass = wxT("EDIT"); |
628c219e | 327 | |
afafd942 JS |
328 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) |
329 | // A control that capitalizes the first letter | |
9b99c1e3 | 330 | if ( HasFlag(wxTE_CAPITALIZE) ) |
afafd942 | 331 | windowClass = wxT("CAPEDIT"); |
628c219e | 332 | #endif |
cd471848 | 333 | |
57c208c5 | 334 | #if wxUSE_RICHEDIT |
a5aa8086 VZ |
335 | if ( m_windowStyle & wxTE_AUTO_URL ) |
336 | { | |
337 | // automatic URL detection only works in RichEdit 2.0+ | |
338 | m_windowStyle |= wxTE_RICH2; | |
339 | } | |
340 | ||
341 | if ( m_windowStyle & wxTE_RICH2 ) | |
342 | { | |
343 | // using richedit 2.0 implies using wxTE_RICH | |
344 | m_windowStyle |= wxTE_RICH; | |
345 | } | |
346 | ||
347 | // we need to load the richedit DLL before creating the rich edit control | |
c49245f8 | 348 | if ( m_windowStyle & wxTE_RICH ) |
a1b82138 | 349 | { |
628c219e VZ |
350 | // versions 2.0, 3.0 and 4.1 of rich edit are mostly compatible with |
351 | // each other but not with version 1.0, so we have separate flags for | |
352 | // the version 1.0 and the others (and so m_verRichEdit may be 0 (plain | |
353 | // EDIT control), 1 for version 1.0 or 2 for any higher version) | |
a5aa8086 | 354 | // |
628c219e VZ |
355 | // notice that 1.0 has no Unicode support at all so in Unicode build we |
356 | // must use another version | |
357 | ||
a5aa8086 | 358 | #if wxUSE_UNICODE |
628c219e | 359 | m_verRichEdit = 2; |
a5aa8086 | 360 | #else // !wxUSE_UNICODE |
628c219e | 361 | m_verRichEdit = m_windowStyle & wxTE_RICH2 ? 2 : 1; |
a5aa8086 | 362 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE |
0d0512bd | 363 | |
8ef51d67 JS |
364 | #if wxUSE_INKEDIT |
365 | // First test if we can load an ink edit control. Normally, all edit | |
366 | // controls will be made ink edit controls if a tablet environment is | |
367 | // found (or if msw.inkedit != 0 and the InkEd.dll is present). | |
368 | // However, an application can veto ink edit controls by either specifying | |
369 | // msw.inkedit = 0 or by removing wxTE_RICH[2] from the style. | |
57a67daf | 370 | // |
8ef51d67 JS |
371 | if ((wxSystemSettings::HasFeature(wxSYS_TABLET_PRESENT) || wxSystemOptions::GetOptionInt(wxT("msw.inkedit")) != 0) && |
372 | !(wxSystemOptions::HasOption(wxT("msw.inkedit")) && wxSystemOptions::GetOptionInt(wxT("msw.inkedit")) == 0)) | |
0d0512bd | 373 | { |
8ef51d67 | 374 | if (wxRichEditModule::LoadInkEdit()) |
57a67daf DS |
375 | { |
376 | windowClass = INKEDIT_CLASS; | |
377 | ||
378 | #if wxUSE_INKEDIT && wxUSE_RICHEDIT | |
8ef51d67 | 379 | m_isInkEdit = 1; |
57a67daf DS |
380 | #endif |
381 | ||
8ef51d67 JS |
382 | // Fake rich text version for other calls |
383 | m_verRichEdit = 2; | |
628c219e | 384 | } |
8ef51d67 JS |
385 | } |
386 | #endif | |
57a67daf | 387 | |
122d1d56 | 388 | if (!IsInkEdit()) |
8ef51d67 JS |
389 | { |
390 | if ( m_verRichEdit == 2 ) | |
40ff126a | 391 | { |
8ef51d67 JS |
392 | if ( wxRichEditModule::Load(wxRichEditModule::Version_41) ) |
393 | { | |
394 | // yes, class name for version 4.1 really is 5.0 | |
395 | windowClass = _T("RICHEDIT50W"); | |
396 | } | |
397 | else if ( wxRichEditModule::Load(wxRichEditModule::Version_2or3) ) | |
398 | { | |
399 | windowClass = _T("RichEdit20") | |
628c219e | 400 | #if wxUSE_UNICODE |
8ef51d67 | 401 | _T("W"); |
628c219e | 402 | #else // ANSI |
8ef51d67 | 403 | _T("A"); |
628c219e | 404 | #endif // Unicode/ANSI |
8ef51d67 JS |
405 | } |
406 | else // failed to load msftedit.dll and riched20.dll | |
407 | { | |
408 | m_verRichEdit = 1; | |
409 | } | |
628c219e | 410 | } |
0d0512bd | 411 | |
8ef51d67 | 412 | if ( m_verRichEdit == 1 ) |
b12915c1 | 413 | { |
8ef51d67 | 414 | if ( wxRichEditModule::Load(wxRichEditModule::Version_1) ) |
f8387e15 | 415 | { |
8ef51d67 | 416 | windowClass = _T("RICHEDIT"); |
f8387e15 | 417 | } |
8ef51d67 JS |
418 | else // failed to load any richedit control DLL |
419 | { | |
420 | // only give the error msg once if the DLL can't be loaded | |
421 | static bool s_errorGiven = false; // MT ok as only used by GUI | |
422 | ||
423 | if ( !s_errorGiven ) | |
424 | { | |
425 | wxLogError(_("Impossible to create a rich edit control, using simple text control instead. Please reinstall riched32.dll")); | |
628c219e | 426 | |
8ef51d67 JS |
427 | s_errorGiven = true; |
428 | } | |
429 | ||
430 | m_verRichEdit = 0; | |
431 | } | |
b12915c1 | 432 | } |
40ff126a | 433 | } // !useInkEdit |
a1b82138 | 434 | } |
b12915c1 | 435 | #endif // wxUSE_RICHEDIT |
2bda0e17 | 436 | |
c8b204e6 VZ |
437 | // we need to turn '\n's into "\r\n"s for the multiline controls |
438 | wxString valueWin; | |
439 | if ( m_windowStyle & wxTE_MULTILINE ) | |
440 | { | |
441 | valueWin = wxTextFile::Translate(value, wxTextFileType_Dos); | |
442 | } | |
443 | else // single line | |
444 | { | |
445 | valueWin = value; | |
446 | } | |
447 | ||
448 | if ( !MSWCreateControl(windowClass, msStyle, pos, size, valueWin) ) | |
bfbb0b4c | 449 | return false; |
2bda0e17 | 450 | |
57c208c5 | 451 | #if wxUSE_RICHEDIT |
8ef51d67 | 452 | if (IsRich()) |
a1b82138 | 453 | { |
8ef51d67 JS |
454 | #if wxUSE_INKEDIT |
455 | if (IsInkEdit()) | |
456 | { | |
457 | // Pass IEM_InsertText (0) as wParam, in order to have the ink always | |
458 | // converted to text. | |
459 | ::SendMessage(GetHwnd(), EM_SETINKINSERTMODE, 0, 0); | |
40ff126a | 460 | |
8ef51d67 JS |
461 | // Make sure the mouse can be used for input |
462 | ::SendMessage(GetHwnd(), EM_SETUSEMOUSEFORINPUT, 1, 0); | |
463 | } | |
464 | #endif | |
40ff126a | 465 | |
5036ea90 VZ |
466 | // enable the events we're interested in: we want to get EN_CHANGE as |
467 | // for the normal controls | |
468 | LPARAM mask = ENM_CHANGE; | |
c57e3339 | 469 | |
8ef51d67 | 470 | if (GetRichVersion() == 1 && !IsInkEdit()) |
1dae1d00 VZ |
471 | { |
472 | // we also need EN_MSGFILTER for richedit 1.0 for the reasons | |
473 | // explained in its handler | |
474 | mask |= ENM_MOUSEEVENTS; | |
9cf4b439 VZ |
475 | |
476 | // we also need to force the appearance of the vertical scrollbar | |
477 | // initially as otherwise the control doesn't refresh correctly | |
478 | // after resize: but once the vertical scrollbar had been shown | |
479 | // (even if it's subsequently hidden) it does | |
480 | // | |
481 | // this is clearly a bug and for now it has been only noticed under | |
482 | // Windows XP, so if we're sure it works correctly under other | |
483 | // systems we could do this only for XP | |
484 | SetSize(-1, 1); // 1 is small enough to force vert scrollbar | |
b370e758 | 485 | SetInitialSize(size); |
1dae1d00 VZ |
486 | } |
487 | else if ( m_windowStyle & wxTE_AUTO_URL ) | |
c57e3339 VZ |
488 | { |
489 | mask |= ENM_LINK; | |
490 | ||
491 | ::SendMessage(GetHwnd(), EM_AUTOURLDETECT, TRUE, 0); | |
492 | } | |
493 | ||
494 | ::SendMessage(GetHwnd(), EM_SETEVENTMASK, 0, mask); | |
a1b82138 | 495 | } |
c57e3339 | 496 | #endif // wxUSE_RICHEDIT |
2bda0e17 | 497 | |
bfbb0b4c | 498 | return true; |
2bda0e17 KB |
499 | } |
500 | ||
501 | // Make sure the window style (etc.) reflects the HWND style (roughly) | |
cd471848 | 502 | void wxTextCtrl::AdoptAttributesFromHWND() |
2bda0e17 | 503 | { |
aac7e7fe | 504 | wxWindow::AdoptAttributesFromHWND(); |
2bda0e17 | 505 | |
aac7e7fe VZ |
506 | HWND hWnd = GetHwnd(); |
507 | long style = ::GetWindowLong(hWnd, GWL_STYLE); | |
2bda0e17 | 508 | |
aac7e7fe | 509 | // retrieve the style to see whether this is an edit or richedit ctrl |
cd471848 | 510 | #if wxUSE_RICHEDIT |
aac7e7fe | 511 | wxString classname = wxGetWindowClass(GetHWND()); |
2bda0e17 | 512 | |
bfbb0b4c | 513 | if ( classname.IsSameAs(_T("EDIT"), false /* no case */) ) |
aac7e7fe VZ |
514 | { |
515 | m_verRichEdit = 0; | |
516 | } | |
517 | else // rich edit? | |
518 | { | |
519 | wxChar c; | |
520 | if ( wxSscanf(classname, _T("RichEdit%d0%c"), &m_verRichEdit, &c) != 2 ) | |
521 | { | |
522 | wxLogDebug(_T("Unknown edit control '%s'."), classname.c_str()); | |
2bda0e17 | 523 | |
aac7e7fe VZ |
524 | m_verRichEdit = 0; |
525 | } | |
526 | } | |
a1b82138 | 527 | #endif // wxUSE_RICHEDIT |
c085e333 | 528 | |
aac7e7fe VZ |
529 | if (style & ES_MULTILINE) |
530 | m_windowStyle |= wxTE_MULTILINE; | |
531 | if (style & ES_PASSWORD) | |
532 | m_windowStyle |= wxTE_PASSWORD; | |
533 | if (style & ES_READONLY) | |
534 | m_windowStyle |= wxTE_READONLY; | |
535 | if (style & ES_WANTRETURN) | |
536 | m_windowStyle |= wxTE_PROCESS_ENTER; | |
e015d1f7 JS |
537 | if (style & ES_CENTER) |
538 | m_windowStyle |= wxTE_CENTRE; | |
539 | if (style & ES_RIGHT) | |
540 | m_windowStyle |= wxTE_RIGHT; | |
2bda0e17 KB |
541 | } |
542 | ||
b2d5a7ee VZ |
543 | WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const |
544 | { | |
545 | long msStyle = wxControl::MSWGetStyle(style, exstyle); | |
546 | ||
db50ec5a | 547 | // styles which we alaways add by default |
b2d5a7ee VZ |
548 | if ( style & wxTE_MULTILINE ) |
549 | { | |
b2d5a7ee VZ |
550 | msStyle |= ES_MULTILINE | ES_WANTRETURN; |
551 | if ( !(style & wxTE_NO_VSCROLL) ) | |
db50ec5a VZ |
552 | { |
553 | // always adjust the vertical scrollbar automatically if we have it | |
554 | msStyle |= WS_VSCROLL | ES_AUTOVSCROLL; | |
555 | ||
34433938 | 556 | #if wxUSE_RICHEDIT |
db50ec5a VZ |
557 | // we have to use this style for the rich edit controls because |
558 | // without it the vertical scrollbar never appears at all in | |
559 | // richedit 3.0 because of our ECO_NOHIDESEL hack (search for it) | |
560 | if ( style & wxTE_RICH2 ) | |
561 | { | |
562 | msStyle |= ES_DISABLENOSCROLL; | |
563 | } | |
34433938 | 564 | #endif // wxUSE_RICHEDIT |
db50ec5a | 565 | } |
b2d5a7ee VZ |
566 | |
567 | style |= wxTE_PROCESS_ENTER; | |
568 | } | |
569 | else // !multiline | |
570 | { | |
571 | // there is really no reason to not have this style for single line | |
572 | // text controls | |
573 | msStyle |= ES_AUTOHSCROLL; | |
574 | } | |
575 | ||
0376ed54 VZ |
576 | // note that wxTE_DONTWRAP is the same as wxHSCROLL so if we have a horz |
577 | // scrollbar, there is no wrapping -- which makes sense | |
578 | if ( style & wxTE_DONTWRAP ) | |
db50ec5a VZ |
579 | { |
580 | // automatically scroll the control horizontally as necessary | |
ce192630 VZ |
581 | // |
582 | // NB: ES_AUTOHSCROLL is needed for richedit controls or they don't | |
583 | // show horz scrollbar at all, even in spite of WS_HSCROLL, and as | |
584 | // it doesn't seem to do any harm for plain edit controls, add it | |
585 | // always | |
586 | msStyle |= WS_HSCROLL | ES_AUTOHSCROLL; | |
db50ec5a | 587 | } |
b2d5a7ee VZ |
588 | |
589 | if ( style & wxTE_READONLY ) | |
590 | msStyle |= ES_READONLY; | |
591 | ||
592 | if ( style & wxTE_PASSWORD ) | |
593 | msStyle |= ES_PASSWORD; | |
594 | ||
b2d5a7ee VZ |
595 | if ( style & wxTE_NOHIDESEL ) |
596 | msStyle |= ES_NOHIDESEL; | |
597 | ||
db50ec5a | 598 | // note that we can't do do "& wxTE_LEFT" as wxTE_LEFT == 0 |
e015d1f7 JS |
599 | if ( style & wxTE_CENTRE ) |
600 | msStyle |= ES_CENTER; | |
db50ec5a | 601 | else if ( style & wxTE_RIGHT ) |
e015d1f7 | 602 | msStyle |= ES_RIGHT; |
db50ec5a | 603 | else |
0376ed54 | 604 | msStyle |= ES_LEFT; // ES_LEFT is 0 as well but for consistency... |
e015d1f7 | 605 | |
b2d5a7ee VZ |
606 | return msStyle; |
607 | } | |
608 | ||
609 | void wxTextCtrl::SetWindowStyleFlag(long style) | |
610 | { | |
66c72081 VZ |
611 | // changing the alignment of the control dynamically works under Win2003 |
612 | // (but not older Windows version: it seems to work under some versions of | |
613 | // XP but not other ones, and we have no way to determine it so be | |
614 | // conservative here) and only for plain EDIT controls (not RICH ones) and | |
615 | // we have to recreate the control to make it always work | |
616 | if ( IsRich() || wxGetWinVersion() < wxWinVersion_2003 ) | |
9b99c1e3 VZ |
617 | { |
618 | const long alignMask = wxTE_LEFT | wxTE_CENTRE | wxTE_RIGHT; | |
619 | if ( (style & alignMask) != (GetWindowStyle() & alignMask) ) | |
620 | { | |
621 | const wxString value = GetValue(); | |
622 | const wxPoint pos = GetPosition(); | |
623 | const wxSize size = GetSize(); | |
624 | ||
625 | // delete the old window | |
626 | HWND hwnd = GetHwnd(); | |
627 | DissociateHandle(); | |
628 | ::DestroyWindow(hwnd); | |
629 | ||
630 | // create the new one with the updated flags | |
631 | m_windowStyle = style; | |
632 | MSWCreateText(value, pos, size); | |
633 | ||
634 | // and make sure it has the same attributes as before | |
635 | if ( m_hasFont ) | |
636 | { | |
637 | // calling SetFont(m_font) would do nothing as the code would | |
638 | // notice that the font didn't change, so force it to believe | |
639 | // that it did | |
640 | wxFont font = m_font; | |
641 | m_font = wxNullFont; | |
642 | SetFont(font); | |
643 | } | |
644 | ||
645 | if ( m_hasFgCol ) | |
646 | { | |
647 | wxColour colFg = m_foregroundColour; | |
648 | m_foregroundColour = wxNullColour; | |
649 | SetForegroundColour(colFg); | |
650 | } | |
651 | ||
652 | if ( m_hasBgCol ) | |
653 | { | |
654 | wxColour colBg = m_backgroundColour; | |
655 | m_backgroundColour = wxNullColour; | |
656 | SetBackgroundColour(colBg); | |
657 | } | |
658 | ||
659 | // note that text styles are lost but this is probably not a big | |
660 | // problem: if you use styles, you probably don't use nor change | |
661 | // alignment flags anyhow | |
662 | ||
663 | return; | |
664 | } | |
665 | } | |
666 | ||
b2d5a7ee VZ |
667 | #if wxUSE_RICHEDIT |
668 | // we have to deal with some styles separately because they can't be | |
669 | // changed by simply calling SetWindowLong(GWL_STYLE) but can be changed | |
670 | // using richedit-specific EM_SETOPTIONS | |
671 | if ( IsRich() && | |
672 | ((style & wxTE_NOHIDESEL) != (GetWindowStyle() & wxTE_NOHIDESEL)) ) | |
673 | { | |
674 | bool set = (style & wxTE_NOHIDESEL) != 0; | |
675 | ||
676 | ::SendMessage(GetHwnd(), EM_SETOPTIONS, set ? ECOOP_OR : ECOOP_AND, | |
677 | set ? ECO_NOHIDESEL : ~ECO_NOHIDESEL); | |
678 | } | |
679 | #endif // wxUSE_RICHEDIT | |
680 | ||
681 | wxControl::SetWindowStyleFlag(style); | |
682 | } | |
683 | ||
a1b82138 VZ |
684 | // ---------------------------------------------------------------------------- |
685 | // set/get the controls text | |
686 | // ---------------------------------------------------------------------------- | |
687 | ||
28fdd8db VZ |
688 | bool wxTextCtrl::IsEmpty() const |
689 | { | |
690 | // this is an optimization for multiline controls containing a lot of text | |
691 | if ( IsMultiLine() && GetNumberOfLines() != 1 ) | |
692 | return false; | |
693 | ||
694 | return wxTextCtrlBase::IsEmpty(); | |
695 | } | |
696 | ||
cd471848 | 697 | wxString wxTextCtrl::GetValue() const |
2bda0e17 | 698 | { |
a5aa8086 VZ |
699 | // range 0..-1 is special for GetRange() and means to retrieve all text |
700 | return GetRange(0, -1); | |
701 | } | |
702 | ||
703 | wxString wxTextCtrl::GetRange(long from, long to) const | |
704 | { | |
705 | wxString str; | |
706 | ||
707 | if ( from >= to && to != -1 ) | |
708 | { | |
709 | // nothing to retrieve | |
710 | return str; | |
711 | } | |
712 | ||
b12915c1 | 713 | #if wxUSE_RICHEDIT |
aac7e7fe | 714 | if ( IsRich() ) |
b12915c1 | 715 | { |
3988b155 | 716 | int len = GetWindowTextLength(GetHwnd()); |
a5aa8086 | 717 | if ( len > from ) |
3988b155 | 718 | { |
7411f983 VZ |
719 | if ( to == -1 ) |
720 | to = len; | |
721 | ||
11db7d81 | 722 | #if !wxUSE_UNICODE |
7411f983 VZ |
723 | // we must use EM_STREAMOUT if we don't want to lose all characters |
724 | // not representable in the current character set (EM_GETTEXTRANGE | |
725 | // simply replaces them with question marks...) | |
e669d184 | 726 | if ( GetRichVersion() > 1 ) |
7411f983 | 727 | { |
e669d184 VZ |
728 | // we must have some encoding, otherwise any 8bit chars in the |
729 | // control are simply *lost* (replaced by '?') | |
730 | wxFontEncoding encoding = wxFONTENCODING_SYSTEM; | |
731 | ||
7411f983 VZ |
732 | wxFont font = m_defaultStyle.GetFont(); |
733 | if ( !font.Ok() ) | |
734 | font = GetFont(); | |
735 | ||
736 | if ( font.Ok() ) | |
737 | { | |
e669d184 VZ |
738 | encoding = font.GetEncoding(); |
739 | } | |
740 | ||
741 | if ( encoding == wxFONTENCODING_SYSTEM ) | |
742 | { | |
743 | encoding = wxLocale::GetSystemEncoding(); | |
744 | } | |
745 | ||
746 | if ( encoding == wxFONTENCODING_SYSTEM ) | |
747 | { | |
748 | encoding = wxFONTENCODING_ISO8859_1; | |
749 | } | |
750 | ||
751 | str = StreamOut(encoding); | |
752 | ||
753 | if ( !str.empty() ) | |
754 | { | |
755 | // we have to manually extract the required part, luckily | |
52a9e329 VZ |
756 | // this is easy in this case as EOL characters in str are |
757 | // just LFs because we remove CRs in wxRichEditStreamOut | |
9ffa7227 | 758 | str = str.Mid(from, to - from); |
7411f983 VZ |
759 | } |
760 | } | |
761 | ||
762 | // StreamOut() wasn't used or failed, try to do it in normal way | |
763 | if ( str.empty() ) | |
11db7d81 | 764 | #endif // !wxUSE_UNICODE |
de564874 MB |
765 | { |
766 | // alloc one extra WORD as needed by the control | |
767 | wxStringBuffer tmp(str, ++len); | |
768 | wxChar *p = tmp; | |
b12915c1 | 769 | |
de564874 MB |
770 | TEXTRANGE textRange; |
771 | textRange.chrg.cpMin = from; | |
11db7d81 | 772 | textRange.chrg.cpMax = to; |
de564874 | 773 | textRange.lpstrText = p; |
b12915c1 | 774 | |
bfbb0b4c WS |
775 | (void)::SendMessage(GetHwnd(), EM_GETTEXTRANGE, |
776 | 0, (LPARAM)&textRange); | |
b12915c1 | 777 | |
de564874 | 778 | if ( m_verRichEdit > 1 ) |
a5aa8086 | 779 | { |
de564874 MB |
780 | // RichEdit 2.0 uses just CR ('\r') for the |
781 | // newlines which is neither Unix nor Windows | |
782 | // style - convert it to something reasonable | |
783 | for ( ; *p; p++ ) | |
784 | { | |
785 | if ( *p == _T('\r') ) | |
786 | *p = _T('\n'); | |
787 | } | |
a5aa8086 | 788 | } |
3988b155 VZ |
789 | } |
790 | ||
a5aa8086 VZ |
791 | if ( m_verRichEdit == 1 ) |
792 | { | |
793 | // convert to the canonical form - see comment below | |
794 | str = wxTextFile::Translate(str, wxTextFileType_Unix); | |
795 | } | |
3988b155 VZ |
796 | } |
797 | //else: no text at all, leave the string empty | |
b12915c1 | 798 | } |
a5aa8086 | 799 | else |
b12915c1 | 800 | #endif // wxUSE_RICHEDIT |
a5aa8086 VZ |
801 | { |
802 | // retrieve all text | |
803 | str = wxGetWindowText(GetHWND()); | |
b12915c1 | 804 | |
a5aa8086 VZ |
805 | // need only a range? |
806 | if ( from < to ) | |
807 | { | |
808 | str = str.Mid(from, to - from); | |
809 | } | |
810 | ||
811 | // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the | |
812 | // canonical one (same one as above) for consistency with the other kinds | |
813 | // of controls and, more importantly, with the other ports | |
814 | str = wxTextFile::Translate(str, wxTextFileType_Unix); | |
815 | } | |
b12915c1 | 816 | |
a5aa8086 | 817 | return str; |
2bda0e17 KB |
818 | } |
819 | ||
f6519b40 | 820 | void wxTextCtrl::DoSetValue(const wxString& value, int flags) |
2bda0e17 | 821 | { |
b12915c1 VZ |
822 | // if the text is long enough, it's faster to just set it instead of first |
823 | // comparing it with the old one (chances are that it will be different | |
824 | // anyhow, this comparison is there to avoid flicker for small single-line | |
825 | // edit controls mostly) | |
826 | if ( (value.length() > 0x400) || (value != GetValue()) ) | |
07cf98cb | 827 | { |
dd1c1631 | 828 | DoWriteText(value, flags /* doesn't include SelectionOnly here */); |
bfbb0b4c | 829 | |
63f84de8 VZ |
830 | // mark the control as being not dirty - we changed its text, not the |
831 | // user | |
832 | DiscardEdits(); | |
833 | ||
120249f6 JS |
834 | // for compatibility, don't move the cursor when doing SetValue() |
835 | SetInsertionPoint(0); | |
da32743f | 836 | } |
199fbd70 VZ |
837 | else // same text |
838 | { | |
63f84de8 VZ |
839 | // still reset the modified flag even if the value didn't really change |
840 | // because now it comes from the program and not the user (and do it | |
841 | // before generating the event so that the event handler could get the | |
842 | // expected value from IsModified()) | |
843 | DiscardEdits(); | |
844 | ||
199fbd70 | 845 | // still send an event for consistency |
f6519b40 VZ |
846 | if (flags & SetValue_SendEvent) |
847 | SendUpdateEvent(); | |
199fbd70 | 848 | } |
aac7e7fe | 849 | } |
a1b82138 | 850 | |
0b8e5844 | 851 | #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU) |
f6bcfd97 | 852 | |
7411f983 VZ |
853 | // TODO: using memcpy() would improve performance a lot for big amounts of text |
854 | ||
855 | DWORD CALLBACK | |
856 | wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb) | |
aac7e7fe VZ |
857 | { |
858 | *pcb = 0; | |
f6bcfd97 | 859 | |
7411f983 VZ |
860 | const wchar_t ** const ppws = (const wchar_t **)dwCookie; |
861 | ||
aac7e7fe | 862 | wchar_t *wbuf = (wchar_t *)buf; |
7411f983 | 863 | const wchar_t *wpc = *ppws; |
aac7e7fe VZ |
864 | while ( cb && *wpc ) |
865 | { | |
866 | *wbuf++ = *wpc++; | |
867 | ||
868 | cb -= sizeof(wchar_t); | |
869 | (*pcb) += sizeof(wchar_t); | |
07cf98cb | 870 | } |
aac7e7fe | 871 | |
7411f983 VZ |
872 | *ppws = wpc; |
873 | ||
874 | return 0; | |
875 | } | |
876 | ||
52a9e329 VZ |
877 | // helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut |
878 | struct wxStreamOutData | |
879 | { | |
880 | wchar_t *wpc; | |
881 | size_t len; | |
882 | }; | |
883 | ||
7411f983 | 884 | DWORD CALLBACK |
975b6bcf | 885 | wxRichEditStreamOut(DWORD_PTR dwCookie, BYTE *buf, LONG cb, LONG *pcb) |
7411f983 VZ |
886 | { |
887 | *pcb = 0; | |
888 | ||
52a9e329 | 889 | wxStreamOutData *data = (wxStreamOutData *)dwCookie; |
7411f983 VZ |
890 | |
891 | const wchar_t *wbuf = (const wchar_t *)buf; | |
52a9e329 VZ |
892 | wchar_t *wpc = data->wpc; |
893 | while ( cb ) | |
7411f983 | 894 | { |
52a9e329 VZ |
895 | wchar_t wch = *wbuf++; |
896 | ||
897 | // turn "\r\n" into "\n" on the fly | |
898 | if ( wch != L'\r' ) | |
899 | *wpc++ = wch; | |
900 | else | |
901 | data->len--; | |
7411f983 VZ |
902 | |
903 | cb -= sizeof(wchar_t); | |
904 | (*pcb) += sizeof(wchar_t); | |
905 | } | |
906 | ||
52a9e329 | 907 | data->wpc = wpc; |
aac7e7fe VZ |
908 | |
909 | return 0; | |
2bda0e17 KB |
910 | } |
911 | ||
7411f983 | 912 | |
0b8e5844 | 913 | #if wxUSE_UNICODE_MSLU |
7411f983 VZ |
914 | #define UNUSED_IF_MSLU(param) |
915 | #else | |
916 | #define UNUSED_IF_MSLU(param) param | |
917 | #endif | |
918 | ||
919 | bool | |
920 | wxTextCtrl::StreamIn(const wxString& value, | |
921 | wxFontEncoding UNUSED_IF_MSLU(encoding), | |
922 | bool selectionOnly) | |
0b8e5844 | 923 | { |
7411f983 | 924 | #if wxUSE_UNICODE_MSLU |
0b8e5844 | 925 | const wchar_t *wpc = value.c_str(); |
79d26b32 | 926 | #else // !wxUSE_UNICODE_MSLU |
6a983211 | 927 | wxCSConv conv(encoding); |
aac7e7fe | 928 | |
6a983211 | 929 | const size_t len = conv.MB2WC(NULL, value, value.length()); |
855d6be7 VZ |
930 | |
931 | #if wxUSE_WCHAR_T | |
aac7e7fe | 932 | wxWCharBuffer wchBuf(len); |
6a983211 | 933 | wchar_t *wpc = wchBuf.data(); |
855d6be7 VZ |
934 | #else |
935 | wchar_t *wchBuf = (wchar_t *)malloc((len + 1)*sizeof(wchar_t)); | |
6a983211 | 936 | wchar_t *wpc = wchBuf; |
855d6be7 VZ |
937 | #endif |
938 | ||
6a983211 | 939 | conv.MB2WC(wpc, value, value.length()); |
0b8e5844 | 940 | #endif // wxUSE_UNICODE_MSLU |
aac7e7fe | 941 | |
6a983211 | 942 | // finally, stream it in the control |
aac7e7fe VZ |
943 | EDITSTREAM eds; |
944 | wxZeroMemory(eds); | |
945 | eds.dwCookie = (DWORD)&wpc; | |
7a25a27c VZ |
946 | // the cast below is needed for broken (very) old mingw32 headers |
947 | eds.pfnCallback = (EDITSTREAMCALLBACK)wxRichEditStreamIn; | |
92209a39 | 948 | |
2c62dd25 VZ |
949 | // same problem as in DoWriteText(): we can get multiple events here |
950 | UpdatesCountFilter ucf(m_updatesCount); | |
2b5f62a0 | 951 | |
07601f59 VZ |
952 | ::SendMessage(GetHwnd(), EM_STREAMIN, |
953 | SF_TEXT | | |
954 | SF_UNICODE | | |
955 | (selectionOnly ? SFF_SELECTION : 0), | |
956 | (LPARAM)&eds); | |
957 | ||
fa31aeda RD |
958 | // It's okay for EN_UPDATE to not be sent if the selection is empty and |
959 | // the text is empty, otherwise warn the programmer about it. | |
960 | wxASSERT_MSG( ucf.GotUpdate() || ( !HasSelection() && value.empty() ), | |
961 | _T("EM_STREAMIN didn't send EN_UPDATE?") ); | |
2c62dd25 | 962 | |
07601f59 | 963 | if ( eds.dwError ) |
aac7e7fe VZ |
964 | { |
965 | wxLogLastError(_T("EM_STREAMIN")); | |
aac7e7fe VZ |
966 | } |
967 | ||
855d6be7 VZ |
968 | #if !wxUSE_WCHAR_T |
969 | free(wchBuf); | |
970 | #endif // !wxUSE_WCHAR_T | |
971 | ||
bfbb0b4c | 972 | return true; |
aac7e7fe VZ |
973 | } |
974 | ||
7411f983 VZ |
975 | #if !wxUSE_UNICODE_MSLU |
976 | ||
977 | wxString | |
978 | wxTextCtrl::StreamOut(wxFontEncoding encoding, bool selectionOnly) const | |
979 | { | |
980 | wxString out; | |
981 | ||
982 | const int len = GetWindowTextLength(GetHwnd()); | |
983 | ||
984 | #if wxUSE_WCHAR_T | |
985 | wxWCharBuffer wchBuf(len); | |
986 | wchar_t *wpc = wchBuf.data(); | |
987 | #else | |
988 | wchar_t *wchBuf = (wchar_t *)malloc((len + 1)*sizeof(wchar_t)); | |
989 | wchar_t *wpc = wchBuf; | |
990 | #endif | |
991 | ||
52a9e329 VZ |
992 | wxStreamOutData data; |
993 | data.wpc = wpc; | |
994 | data.len = len; | |
995 | ||
7411f983 VZ |
996 | EDITSTREAM eds; |
997 | wxZeroMemory(eds); | |
52a9e329 | 998 | eds.dwCookie = (DWORD)&data; |
7411f983 VZ |
999 | eds.pfnCallback = wxRichEditStreamOut; |
1000 | ||
1001 | ::SendMessage | |
1002 | ( | |
1003 | GetHwnd(), | |
1004 | EM_STREAMOUT, | |
1005 | SF_TEXT | SF_UNICODE | (selectionOnly ? SFF_SELECTION : 0), | |
1006 | (LPARAM)&eds | |
1007 | ); | |
1008 | ||
1009 | if ( eds.dwError ) | |
1010 | { | |
1011 | wxLogLastError(_T("EM_STREAMOUT")); | |
1012 | } | |
1013 | else // streamed out ok | |
1014 | { | |
52a9e329 VZ |
1015 | // NUL-terminate the string because its length could have been |
1016 | // decreased by wxRichEditStreamOut | |
1017 | *(wchBuf.data() + data.len) = L'\0'; | |
1018 | ||
b26613c2 VZ |
1019 | // now convert to the given encoding (this is a possibly lossful |
1020 | // conversion but what else can we do) | |
7411f983 | 1021 | wxCSConv conv(encoding); |
b26613c2 VZ |
1022 | size_t lenNeeded = conv.WC2MB(NULL, wchBuf, 0); |
1023 | if ( lenNeeded++ ) | |
7411f983 | 1024 | { |
b26613c2 | 1025 | conv.WC2MB(wxStringBuffer(out, lenNeeded), wchBuf, lenNeeded); |
7411f983 VZ |
1026 | } |
1027 | } | |
1028 | ||
1029 | #if !wxUSE_WCHAR_T | |
1030 | free(wchBuf); | |
1031 | #endif // !wxUSE_WCHAR_T | |
1032 | ||
1033 | return out; | |
1034 | } | |
1035 | ||
1036 | #endif // !wxUSE_UNICODE_MSLU | |
1037 | ||
aac7e7fe VZ |
1038 | #endif // wxUSE_RICHEDIT |
1039 | ||
a1b82138 | 1040 | void wxTextCtrl::WriteText(const wxString& value) |
79d26b32 VZ |
1041 | { |
1042 | DoWriteText(value); | |
1043 | } | |
1044 | ||
f6519b40 | 1045 | void wxTextCtrl::DoWriteText(const wxString& value, int flags) |
2bda0e17 | 1046 | { |
f6519b40 | 1047 | bool selectionOnly = (flags & SetValue_SelectionOnly) != 0; |
a5aa8086 VZ |
1048 | wxString valueDos; |
1049 | if ( m_windowStyle & wxTE_MULTILINE ) | |
1050 | valueDos = wxTextFile::Translate(value, wxTextFileType_Dos); | |
1051 | else | |
1052 | valueDos = value; | |
2bda0e17 | 1053 | |
4bc1afd5 | 1054 | #if wxUSE_RICHEDIT |
aac7e7fe | 1055 | // there are several complications with the rich edit controls here |
bfbb0b4c | 1056 | bool done = false; |
aac7e7fe | 1057 | if ( IsRich() ) |
4bc1afd5 | 1058 | { |
aac7e7fe VZ |
1059 | // first, ensure that the new text will be in the default style |
1060 | if ( !m_defaultStyle.IsDefault() ) | |
1061 | { | |
1062 | long start, end; | |
1063 | GetSelection(&start, &end); | |
0b8e5844 VS |
1064 | SetStyle(start, end, m_defaultStyle); |
1065 | } | |
1066 | ||
1067 | #if wxUSE_UNICODE_MSLU | |
1068 | // RichEdit doesn't have Unicode version of EM_REPLACESEL on Win9x, | |
1069 | // but EM_STREAMIN works | |
136cb3c7 | 1070 | if ( wxUsingUnicowsDll() && GetRichVersion() > 1 ) |
0b8e5844 | 1071 | { |
79d26b32 | 1072 | done = StreamIn(valueDos, wxFONTENCODING_SYSTEM, selectionOnly); |
aac7e7fe | 1073 | } |
0b8e5844 | 1074 | #endif // wxUSE_UNICODE_MSLU |
aac7e7fe | 1075 | |
b4da152e | 1076 | #if !wxUSE_UNICODE |
aac7e7fe VZ |
1077 | // next check if the text we're inserting must be shown in a non |
1078 | // default charset -- this only works for RichEdit > 1.0 | |
1079 | if ( GetRichVersion() > 1 ) | |
1080 | { | |
1081 | wxFont font = m_defaultStyle.GetFont(); | |
1082 | if ( !font.Ok() ) | |
1083 | font = GetFont(); | |
1084 | ||
1085 | if ( font.Ok() ) | |
1086 | { | |
1087 | wxFontEncoding encoding = font.GetEncoding(); | |
1088 | if ( encoding != wxFONTENCODING_SYSTEM ) | |
1089 | { | |
6a983211 VZ |
1090 | // we have to use EM_STREAMIN to force richedit control 2.0+ |
1091 | // to show any text in the non default charset -- otherwise | |
1092 | // it thinks it knows better than we do and always shows it | |
1093 | // in the default one | |
79d26b32 | 1094 | done = StreamIn(valueDos, encoding, selectionOnly); |
aac7e7fe VZ |
1095 | } |
1096 | } | |
1097 | } | |
9d7de3c2 | 1098 | #endif // !wxUSE_UNICODE |
4bc1afd5 | 1099 | } |
4bc1afd5 | 1100 | |
aac7e7fe VZ |
1101 | if ( !done ) |
1102 | #endif // wxUSE_RICHEDIT | |
1103 | { | |
2b5f62a0 | 1104 | // in some cases we get 2 EN_CHANGE notifications after the SendMessage |
2c62dd25 VZ |
1105 | // call (this happens for plain EDITs with EM_REPLACESEL and under some |
1106 | // -- undetermined -- conditions with rich edit) and sometimes we don't | |
1107 | // get any events at all (plain EDIT with WM_SETTEXT), so ensure that | |
1108 | // we generate exactly one of them by ignoring all but the first one in | |
1109 | // SendUpdateEvent() and generating one ourselves if we hadn't got any | |
1110 | // notifications from Windows | |
f6519b40 VZ |
1111 | if ( !(flags & SetValue_SendEvent) ) |
1112 | m_updatesCount = -2; // suppress any update event | |
1113 | ||
2c62dd25 | 1114 | UpdatesCountFilter ucf(m_updatesCount); |
79d26b32 | 1115 | |
5036ea90 | 1116 | ::SendMessage(GetHwnd(), selectionOnly ? EM_REPLACESEL : WM_SETTEXT, |
6e9e2d94 JS |
1117 | // EM_REPLACESEL takes 1 to indicate the operation should be redoable |
1118 | selectionOnly ? 1 : 0, (LPARAM)valueDos.c_str()); | |
2b5f62a0 | 1119 | |
f6519b40 | 1120 | if ( !ucf.GotUpdate() && (flags & SetValue_SendEvent) ) |
2b5f62a0 | 1121 | { |
2c62dd25 | 1122 | SendUpdateEvent(); |
2b5f62a0 | 1123 | } |
aac7e7fe | 1124 | } |
2bda0e17 KB |
1125 | } |
1126 | ||
a1b82138 VZ |
1127 | void wxTextCtrl::AppendText(const wxString& text) |
1128 | { | |
1129 | SetInsertionPointEnd(); | |
aac7e7fe | 1130 | |
a1b82138 | 1131 | WriteText(text); |
2b5f62a0 VZ |
1132 | |
1133 | #if wxUSE_RICHEDIT | |
caea50ac VZ |
1134 | // don't do this if we're frozen, saves some time |
1135 | if ( !IsFrozen() && IsMultiLine() && GetRichVersion() > 1 ) | |
2b5f62a0 VZ |
1136 | { |
1137 | // setting the caret to the end and showing it simply doesn't work for | |
1138 | // RichEdit 2.0 -- force it to still do what we want | |
1139 | ::SendMessage(GetHwnd(), EM_LINESCROLL, 0, GetNumberOfLines()); | |
1140 | } | |
1141 | #endif // wxUSE_RICHEDIT | |
a1b82138 VZ |
1142 | } |
1143 | ||
1144 | void wxTextCtrl::Clear() | |
1145 | { | |
fda7962d | 1146 | ::SetWindowText(GetHwnd(), wxEmptyString); |
5036ea90 VZ |
1147 | |
1148 | #if wxUSE_RICHEDIT | |
1149 | if ( !IsRich() ) | |
1150 | #endif // wxUSE_RICHEDIT | |
1151 | { | |
1152 | // rich edit controls send EN_UPDATE from WM_SETTEXT handler themselves | |
1153 | // but the normal ones don't -- make Clear() behaviour consistent by | |
1154 | // always sending this event | |
8d1e36f7 JS |
1155 | |
1156 | // Windows already sends an update event for single-line | |
1157 | // controls. | |
1158 | if ( m_windowStyle & wxTE_MULTILINE ) | |
1159 | SendUpdateEvent(); | |
5036ea90 | 1160 | } |
a1b82138 VZ |
1161 | } |
1162 | ||
94af7d45 VZ |
1163 | #ifdef __WIN32__ |
1164 | ||
1165 | bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent& event) | |
1166 | { | |
1167 | SetFocus(); | |
1168 | ||
1169 | size_t lenOld = GetValue().length(); | |
1170 | ||
1171 | wxUint32 code = event.GetRawKeyCode(); | |
5c519b6c WS |
1172 | ::keybd_event((BYTE)code, 0, 0 /* key press */, 0); |
1173 | ::keybd_event((BYTE)code, 0, KEYEVENTF_KEYUP, 0); | |
94af7d45 VZ |
1174 | |
1175 | // assume that any alphanumeric key changes the total number of characters | |
1176 | // in the control - this should work in 99% of cases | |
1177 | return GetValue().length() != lenOld; | |
1178 | } | |
1179 | ||
1180 | #endif // __WIN32__ | |
1181 | ||
a1b82138 | 1182 | // ---------------------------------------------------------------------------- |
2bda0e17 | 1183 | // Clipboard operations |
a1b82138 VZ |
1184 | // ---------------------------------------------------------------------------- |
1185 | ||
cd471848 | 1186 | void wxTextCtrl::Copy() |
2bda0e17 | 1187 | { |
e702ff0f JS |
1188 | if (CanCopy()) |
1189 | { | |
a5aa8086 | 1190 | ::SendMessage(GetHwnd(), WM_COPY, 0, 0L); |
e702ff0f | 1191 | } |
2bda0e17 KB |
1192 | } |
1193 | ||
cd471848 | 1194 | void wxTextCtrl::Cut() |
2bda0e17 | 1195 | { |
e702ff0f JS |
1196 | if (CanCut()) |
1197 | { | |
a5aa8086 | 1198 | ::SendMessage(GetHwnd(), WM_CUT, 0, 0L); |
e702ff0f | 1199 | } |
2bda0e17 KB |
1200 | } |
1201 | ||
cd471848 | 1202 | void wxTextCtrl::Paste() |
2bda0e17 | 1203 | { |
e702ff0f JS |
1204 | if (CanPaste()) |
1205 | { | |
a5aa8086 | 1206 | ::SendMessage(GetHwnd(), WM_PASTE, 0, 0L); |
e702ff0f | 1207 | } |
2bda0e17 KB |
1208 | } |
1209 | ||
2b5f62a0 | 1210 | bool wxTextCtrl::HasSelection() const |
a1b82138 | 1211 | { |
a1b82138 | 1212 | long from, to; |
a5aa8086 VZ |
1213 | GetSelection(&from, &to); |
1214 | return from != to; | |
a1b82138 VZ |
1215 | } |
1216 | ||
2b5f62a0 VZ |
1217 | bool wxTextCtrl::CanCopy() const |
1218 | { | |
1219 | // Can copy if there's a selection | |
1220 | return HasSelection(); | |
1221 | } | |
1222 | ||
a1b82138 VZ |
1223 | bool wxTextCtrl::CanCut() const |
1224 | { | |
a5aa8086 | 1225 | return CanCopy() && IsEditable(); |
a1b82138 VZ |
1226 | } |
1227 | ||
1228 | bool wxTextCtrl::CanPaste() const | |
1229 | { | |
aac7e7fe | 1230 | if ( !IsEditable() ) |
bfbb0b4c | 1231 | return false; |
aac7e7fe | 1232 | |
a1b82138 | 1233 | #if wxUSE_RICHEDIT |
aac7e7fe | 1234 | if ( IsRich() ) |
a1b82138 | 1235 | { |
aac7e7fe VZ |
1236 | UINT cf = 0; // 0 == any format |
1237 | ||
1238 | return ::SendMessage(GetHwnd(), EM_CANPASTE, cf, 0) != 0; | |
a1b82138 | 1239 | } |
aac7e7fe | 1240 | #endif // wxUSE_RICHEDIT |
a1b82138 VZ |
1241 | |
1242 | // Standard edit control: check for straight text on clipboard | |
aac7e7fe | 1243 | if ( !::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) ) |
bfbb0b4c | 1244 | return false; |
aac7e7fe VZ |
1245 | |
1246 | bool isTextAvailable = ::IsClipboardFormatAvailable(CF_TEXT) != 0; | |
1247 | ::CloseClipboard(); | |
a1b82138 VZ |
1248 | |
1249 | return isTextAvailable; | |
1250 | } | |
1251 | ||
1252 | // ---------------------------------------------------------------------------- | |
1253 | // Accessors | |
1254 | // ---------------------------------------------------------------------------- | |
1255 | ||
debe6624 | 1256 | void wxTextCtrl::SetEditable(bool editable) |
2bda0e17 | 1257 | { |
a1b82138 | 1258 | HWND hWnd = GetHwnd(); |
bfbb0b4c | 1259 | ::SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L); |
2bda0e17 KB |
1260 | } |
1261 | ||
debe6624 | 1262 | void wxTextCtrl::SetInsertionPoint(long pos) |
2bda0e17 | 1263 | { |
a5aa8086 | 1264 | DoSetSelection(pos, pos); |
2bda0e17 KB |
1265 | } |
1266 | ||
cd471848 | 1267 | void wxTextCtrl::SetInsertionPointEnd() |
2bda0e17 | 1268 | { |
a9d3434a VZ |
1269 | // we must not do anything if the caret is already there because calling |
1270 | // SetInsertionPoint() thaws the controls if Freeze() had been called even | |
1271 | // if it doesn't actually move the caret anywhere and so the simple fact of | |
1272 | // doing it results in horrible flicker when appending big amounts of text | |
1273 | // to the control in a few chunks (see DoAddText() test in the text sample) | |
37f11dee VZ |
1274 | const wxTextPos lastPosition = GetLastPosition(); |
1275 | if ( GetInsertionPoint() == lastPosition ) | |
caea50ac | 1276 | { |
a9d3434a | 1277 | return; |
caea50ac | 1278 | } |
a9d3434a | 1279 | |
a5aa8086 VZ |
1280 | long pos; |
1281 | ||
1282 | #if wxUSE_RICHEDIT | |
1283 | if ( m_verRichEdit == 1 ) | |
1284 | { | |
1285 | // we don't have to waste time calling GetLastPosition() in this case | |
1286 | pos = -1; | |
1287 | } | |
1288 | else // !RichEdit 1.0 | |
1289 | #endif // wxUSE_RICHEDIT | |
1290 | { | |
37f11dee | 1291 | pos = lastPosition; |
a5aa8086 VZ |
1292 | } |
1293 | ||
a1b82138 | 1294 | SetInsertionPoint(pos); |
2bda0e17 KB |
1295 | } |
1296 | ||
cd471848 | 1297 | long wxTextCtrl::GetInsertionPoint() const |
2bda0e17 | 1298 | { |
57c208c5 | 1299 | #if wxUSE_RICHEDIT |
aac7e7fe | 1300 | if ( IsRich() ) |
a1b82138 VZ |
1301 | { |
1302 | CHARRANGE range; | |
1303 | range.cpMin = 0; | |
1304 | range.cpMax = 0; | |
bfbb0b4c | 1305 | ::SendMessage(GetHwnd(), EM_EXGETSEL, 0, (LPARAM) &range); |
a1b82138 VZ |
1306 | return range.cpMin; |
1307 | } | |
aac7e7fe | 1308 | #endif // wxUSE_RICHEDIT |
2bda0e17 | 1309 | |
bfbb0b4c | 1310 | DWORD Pos = (DWORD)::SendMessage(GetHwnd(), EM_GETSEL, 0, 0L); |
a1b82138 | 1311 | return Pos & 0xFFFF; |
2bda0e17 KB |
1312 | } |
1313 | ||
7d8268a1 | 1314 | wxTextPos wxTextCtrl::GetLastPosition() const |
2bda0e17 | 1315 | { |
a5aa8086 VZ |
1316 | int numLines = GetNumberOfLines(); |
1317 | long posStartLastLine = XYToPosition(0, numLines - 1); | |
39136494 | 1318 | |
a5aa8086 | 1319 | long lenLastLine = GetLengthOfLineContainingPos(posStartLastLine); |
2bda0e17 | 1320 | |
a5aa8086 | 1321 | return posStartLastLine + lenLastLine; |
2bda0e17 KB |
1322 | } |
1323 | ||
a1b82138 VZ |
1324 | // If the return values from and to are the same, there is no |
1325 | // selection. | |
1326 | void wxTextCtrl::GetSelection(long* from, long* to) const | |
1327 | { | |
1328 | #if wxUSE_RICHEDIT | |
aac7e7fe | 1329 | if ( IsRich() ) |
a1b82138 VZ |
1330 | { |
1331 | CHARRANGE charRange; | |
aac7e7fe | 1332 | ::SendMessage(GetHwnd(), EM_EXGETSEL, 0, (LPARAM) &charRange); |
a1b82138 VZ |
1333 | |
1334 | *from = charRange.cpMin; | |
1335 | *to = charRange.cpMax; | |
a1b82138 | 1336 | } |
4bc1afd5 | 1337 | else |
aac7e7fe | 1338 | #endif // !wxUSE_RICHEDIT |
4bc1afd5 VZ |
1339 | { |
1340 | DWORD dwStart, dwEnd; | |
aac7e7fe | 1341 | ::SendMessage(GetHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd); |
a1b82138 | 1342 | |
4bc1afd5 VZ |
1343 | *from = dwStart; |
1344 | *to = dwEnd; | |
1345 | } | |
a1b82138 VZ |
1346 | } |
1347 | ||
1348 | bool wxTextCtrl::IsEditable() const | |
1349 | { | |
51c14c62 VZ |
1350 | // strangely enough, we may be called before the control is created: our |
1351 | // own Create() calls MSWGetStyle() which calls AcceptsFocus() which calls | |
1352 | // us | |
1353 | if ( !m_hWnd ) | |
bfbb0b4c | 1354 | return true; |
51c14c62 | 1355 | |
a1b82138 VZ |
1356 | long style = ::GetWindowLong(GetHwnd(), GWL_STYLE); |
1357 | ||
a5aa8086 | 1358 | return (style & ES_READONLY) == 0; |
a1b82138 VZ |
1359 | } |
1360 | ||
1361 | // ---------------------------------------------------------------------------- | |
aac7e7fe | 1362 | // selection |
a1b82138 VZ |
1363 | // ---------------------------------------------------------------------------- |
1364 | ||
aac7e7fe | 1365 | void wxTextCtrl::SetSelection(long from, long to) |
2bda0e17 | 1366 | { |
77ffb593 | 1367 | // if from and to are both -1, it means (in wxWidgets) that all text should |
aac7e7fe VZ |
1368 | // be selected - translate into Windows convention |
1369 | if ( (from == -1) && (to == -1) ) | |
1370 | { | |
1371 | from = 0; | |
1372 | to = -1; | |
1373 | } | |
1374 | ||
a5aa8086 VZ |
1375 | DoSetSelection(from, to); |
1376 | } | |
1377 | ||
1378 | void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret) | |
1379 | { | |
789295bf | 1380 | HWND hWnd = GetHwnd(); |
39136494 | 1381 | |
aac7e7fe VZ |
1382 | #if wxUSE_RICHEDIT |
1383 | if ( IsRich() ) | |
1384 | { | |
db50ec5a VZ |
1385 | CHARRANGE range; |
1386 | range.cpMin = from; | |
1387 | range.cpMax = to; | |
bfbb0b4c | 1388 | ::SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM) &range); |
db50ec5a VZ |
1389 | } |
1390 | else | |
1391 | #endif // wxUSE_RICHEDIT | |
1392 | { | |
bfbb0b4c | 1393 | ::SendMessage(hWnd, EM_SETSEL, (WPARAM)from, (LPARAM)to); |
db50ec5a VZ |
1394 | } |
1395 | ||
caea50ac | 1396 | if ( scrollCaret && !IsFrozen() ) |
db50ec5a VZ |
1397 | { |
1398 | #if wxUSE_RICHEDIT | |
98e19a58 VZ |
1399 | // richedit 3.0 (i.e. the version living in riched20.dll distributed |
1400 | // with Windows 2000 and beyond) doesn't honour EM_SCROLLCARET when | |
1401 | // emulating richedit 2.0 unless the control has focus or ECO_NOHIDESEL | |
1402 | // option is set (but it does work ok in richedit 1.0 mode...) | |
1403 | // | |
1404 | // so to make it work we either need to give focus to it here which | |
1405 | // will probably create many problems (dummy focus events; window | |
1406 | // containing the text control being brought to foreground | |
1407 | // unexpectedly; ...) or to temporarily set ECO_NOHIDESEL which may | |
db50ec5a VZ |
1408 | // create other problems too -- and in fact it does because if we turn |
1409 | // on/off this style while appending the text to the control, the | |
1410 | // vertical scrollbar never appears in it even if we append tons of | |
1411 | // text and to work around this the only solution I found was to use | |
1412 | // ES_DISABLENOSCROLL | |
1413 | // | |
1414 | // this is very ugly but I don't see any other way to make this work | |
b7a3ba7d | 1415 | long style = 0; |
98e19a58 VZ |
1416 | if ( GetRichVersion() > 1 ) |
1417 | { | |
1418 | if ( !HasFlag(wxTE_NOHIDESEL) ) | |
1419 | { | |
b7a3ba7d JG |
1420 | // setting ECO_NOHIDESEL also sets WS_VISIBLE and possibly |
1421 | // others, remember the style so we can reset it later if needed | |
1422 | style = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
98e19a58 VZ |
1423 | ::SendMessage(GetHwnd(), EM_SETOPTIONS, |
1424 | ECOOP_OR, ECO_NOHIDESEL); | |
1425 | } | |
1426 | //else: everything is already ok | |
1427 | } | |
aac7e7fe | 1428 | #endif // wxUSE_RICHEDIT |
a1b82138 | 1429 | |
bfbb0b4c | 1430 | ::SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); |
98e19a58 VZ |
1431 | |
1432 | #if wxUSE_RICHEDIT | |
db50ec5a VZ |
1433 | // restore ECO_NOHIDESEL if we changed it |
1434 | if ( GetRichVersion() > 1 && !HasFlag(wxTE_NOHIDESEL) ) | |
1435 | { | |
1436 | ::SendMessage(GetHwnd(), EM_SETOPTIONS, | |
1437 | ECOOP_AND, ~ECO_NOHIDESEL); | |
b7a3ba7d JG |
1438 | if ( style != ::GetWindowLong(GetHwnd(), GWL_STYLE) ) |
1439 | ::SetWindowLong(GetHwnd(), GWL_STYLE, style); | |
db50ec5a | 1440 | } |
98e19a58 | 1441 | #endif // wxUSE_RICHEDIT |
db50ec5a | 1442 | } |
aac7e7fe VZ |
1443 | } |
1444 | ||
efe66bbc VZ |
1445 | // ---------------------------------------------------------------------------- |
1446 | // Working with files | |
1447 | // ---------------------------------------------------------------------------- | |
1448 | ||
3306aec1 | 1449 | bool wxTextCtrl::DoLoadFile(const wxString& file, int fileType) |
efe66bbc | 1450 | { |
3306aec1 | 1451 | if ( wxTextCtrlBase::DoLoadFile(file, fileType) ) |
efe66bbc VZ |
1452 | { |
1453 | // update the size limit if needed | |
1454 | AdjustSpaceLimit(); | |
1455 | ||
bfbb0b4c | 1456 | return true; |
efe66bbc VZ |
1457 | } |
1458 | ||
bfbb0b4c | 1459 | return false; |
efe66bbc VZ |
1460 | } |
1461 | ||
aac7e7fe VZ |
1462 | // ---------------------------------------------------------------------------- |
1463 | // Editing | |
1464 | // ---------------------------------------------------------------------------- | |
39136494 | 1465 | |
aac7e7fe VZ |
1466 | void wxTextCtrl::Replace(long from, long to, const wxString& value) |
1467 | { | |
1468 | // Set selection and remove it | |
bfbb0b4c | 1469 | DoSetSelection(from, to, false /* don't scroll caret into view */); |
aac7e7fe | 1470 | |
dd1c1631 | 1471 | DoWriteText(value); |
aac7e7fe VZ |
1472 | } |
1473 | ||
1474 | void wxTextCtrl::Remove(long from, long to) | |
1475 | { | |
fda7962d | 1476 | Replace(from, to, wxEmptyString); |
2bda0e17 KB |
1477 | } |
1478 | ||
cd471848 | 1479 | bool wxTextCtrl::IsModified() const |
2bda0e17 | 1480 | { |
bfbb0b4c | 1481 | return ::SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0; |
2bda0e17 KB |
1482 | } |
1483 | ||
3a9fa0d6 VZ |
1484 | void wxTextCtrl::MarkDirty() |
1485 | { | |
bfbb0b4c | 1486 | ::SendMessage(GetHwnd(), EM_SETMODIFY, TRUE, 0L); |
3a9fa0d6 VZ |
1487 | } |
1488 | ||
cd471848 | 1489 | void wxTextCtrl::DiscardEdits() |
2bda0e17 | 1490 | { |
bfbb0b4c | 1491 | ::SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L); |
2bda0e17 KB |
1492 | } |
1493 | ||
cd471848 | 1494 | int wxTextCtrl::GetNumberOfLines() const |
2bda0e17 | 1495 | { |
bfbb0b4c | 1496 | return (int)::SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0); |
2bda0e17 KB |
1497 | } |
1498 | ||
efe66bbc VZ |
1499 | // ---------------------------------------------------------------------------- |
1500 | // Positions <-> coords | |
1501 | // ---------------------------------------------------------------------------- | |
1502 | ||
debe6624 | 1503 | long wxTextCtrl::XYToPosition(long x, long y) const |
2bda0e17 | 1504 | { |
2bda0e17 | 1505 | // This gets the char index for the _beginning_ of this line |
bfbb0b4c | 1506 | long charIndex = ::SendMessage(GetHwnd(), EM_LINEINDEX, (WPARAM)y, (LPARAM)0); |
a5aa8086 VZ |
1507 | |
1508 | return charIndex + x; | |
2bda0e17 KB |
1509 | } |
1510 | ||
0efe5ba7 | 1511 | bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const |
2bda0e17 | 1512 | { |
789295bf | 1513 | HWND hWnd = GetHwnd(); |
2bda0e17 KB |
1514 | |
1515 | // This gets the line number containing the character | |
a5aa8086 | 1516 | long lineNo; |
0efe5ba7 | 1517 | #if wxUSE_RICHEDIT |
aac7e7fe | 1518 | if ( IsRich() ) |
0efe5ba7 | 1519 | { |
bfbb0b4c | 1520 | lineNo = ::SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, (LPARAM)pos); |
0efe5ba7 VZ |
1521 | } |
1522 | else | |
1523 | #endif // wxUSE_RICHEDIT | |
a5aa8086 | 1524 | { |
bfbb0b4c | 1525 | lineNo = ::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0); |
a5aa8086 | 1526 | } |
0efe5ba7 VZ |
1527 | |
1528 | if ( lineNo == -1 ) | |
1529 | { | |
1530 | // no such line | |
bfbb0b4c | 1531 | return false; |
0efe5ba7 VZ |
1532 | } |
1533 | ||
2bda0e17 | 1534 | // This gets the char index for the _beginning_ of this line |
bfbb0b4c | 1535 | long charIndex = ::SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0); |
0efe5ba7 VZ |
1536 | if ( charIndex == -1 ) |
1537 | { | |
bfbb0b4c | 1538 | return false; |
0efe5ba7 VZ |
1539 | } |
1540 | ||
2bda0e17 | 1541 | // The X position must therefore be the different between pos and charIndex |
0efe5ba7 | 1542 | if ( x ) |
a5aa8086 | 1543 | *x = pos - charIndex; |
0efe5ba7 | 1544 | if ( y ) |
a5aa8086 | 1545 | *y = lineNo; |
0efe5ba7 | 1546 | |
bfbb0b4c | 1547 | return true; |
2bda0e17 KB |
1548 | } |
1549 | ||
efe66bbc | 1550 | wxTextCtrlHitTestResult |
6726a6b0 | 1551 | wxTextCtrl::HitTest(const wxPoint& pt, long *posOut) const |
efe66bbc VZ |
1552 | { |
1553 | // first get the position from Windows | |
1554 | LPARAM lParam; | |
1555 | ||
1556 | #if wxUSE_RICHEDIT | |
1557 | POINTL ptl; | |
1558 | if ( IsRich() ) | |
1559 | { | |
1560 | // for rich edit controls the position is passed iva the struct fields | |
1561 | ptl.x = pt.x; | |
1562 | ptl.y = pt.y; | |
1563 | lParam = (LPARAM)&ptl; | |
1564 | } | |
1565 | else | |
1566 | #endif // wxUSE_RICHEDIT | |
1567 | { | |
1568 | // for the plain ones, we are limited to 16 bit positions which are | |
1569 | // combined in a single 32 bit value | |
1570 | lParam = MAKELPARAM(pt.x, pt.y); | |
1571 | } | |
1572 | ||
bfbb0b4c | 1573 | LRESULT pos = ::SendMessage(GetHwnd(), EM_CHARFROMPOS, 0, lParam); |
efe66bbc VZ |
1574 | |
1575 | if ( pos == -1 ) | |
1576 | { | |
1577 | // this seems to indicate an error... | |
1578 | return wxTE_HT_UNKNOWN; | |
1579 | } | |
1580 | ||
1581 | #if wxUSE_RICHEDIT | |
1582 | if ( !IsRich() ) | |
1583 | #endif // wxUSE_RICHEDIT | |
1584 | { | |
1585 | // for plain EDIT controls the higher word contains something else | |
1586 | pos = LOWORD(pos); | |
1587 | } | |
1588 | ||
1589 | ||
1590 | // next determine where it is relatively to our point: EM_CHARFROMPOS | |
1591 | // always returns the closest character but we need to be more precise, so | |
1592 | // double check that we really are where it pretends | |
1593 | POINTL ptReal; | |
1594 | ||
1595 | #if wxUSE_RICHEDIT | |
1596 | // FIXME: we need to distinguish between richedit 2 and 3 here somehow but | |
1597 | // we don't know how to do it | |
1598 | if ( IsRich() ) | |
1599 | { | |
bfbb0b4c | 1600 | ::SendMessage(GetHwnd(), EM_POSFROMCHAR, (WPARAM)&ptReal, pos); |
efe66bbc VZ |
1601 | } |
1602 | else | |
1603 | #endif // wxUSE_RICHEDIT | |
1604 | { | |
bfbb0b4c | 1605 | LRESULT lRc = ::SendMessage(GetHwnd(), EM_POSFROMCHAR, pos, 0); |
efe66bbc VZ |
1606 | |
1607 | if ( lRc == -1 ) | |
1608 | { | |
1609 | // this is apparently returned when pos corresponds to the last | |
1610 | // position | |
1611 | ptReal.x = | |
1612 | ptReal.y = 0; | |
1613 | } | |
1614 | else | |
1615 | { | |
1616 | ptReal.x = LOWORD(lRc); | |
1617 | ptReal.y = HIWORD(lRc); | |
1618 | } | |
1619 | } | |
1620 | ||
1621 | wxTextCtrlHitTestResult rc; | |
1622 | ||
1623 | if ( pt.y > ptReal.y + GetCharHeight() ) | |
1624 | rc = wxTE_HT_BELOW; | |
1625 | else if ( pt.x > ptReal.x + GetCharWidth() ) | |
1626 | rc = wxTE_HT_BEYOND; | |
1627 | else | |
1628 | rc = wxTE_HT_ON_TEXT; | |
1629 | ||
6726a6b0 VZ |
1630 | if ( posOut ) |
1631 | *posOut = pos; | |
efe66bbc VZ |
1632 | |
1633 | return rc; | |
1634 | } | |
1635 | ||
1636 | // ---------------------------------------------------------------------------- | |
bfbb0b4c | 1637 | // |
efe66bbc VZ |
1638 | // ---------------------------------------------------------------------------- |
1639 | ||
debe6624 | 1640 | void wxTextCtrl::ShowPosition(long pos) |
2bda0e17 | 1641 | { |
789295bf | 1642 | HWND hWnd = GetHwnd(); |
2bda0e17 KB |
1643 | |
1644 | // To scroll to a position, we pass the number of lines and characters | |
1645 | // to scroll *by*. This means that we need to: | |
1646 | // (1) Find the line position of the current line. | |
1647 | // (2) Find the line position of pos. | |
1648 | // (3) Scroll by (pos - current). | |
1649 | // For now, ignore the horizontal scrolling. | |
1650 | ||
1651 | // Is this where scrolling is relative to - the line containing the caret? | |
1652 | // Or is the first visible line??? Try first visible line. | |
bfbb0b4c | 1653 | // int currentLineLineNo1 = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L); |
2bda0e17 | 1654 | |
bfbb0b4c | 1655 | int currentLineLineNo = (int)::SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L); |
2bda0e17 | 1656 | |
bfbb0b4c | 1657 | int specifiedLineLineNo = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L); |
39136494 | 1658 | |
2bda0e17 KB |
1659 | int linesToScroll = specifiedLineLineNo - currentLineLineNo; |
1660 | ||
2bda0e17 | 1661 | if (linesToScroll != 0) |
bfbb0b4c | 1662 | (void)::SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll); |
2bda0e17 KB |
1663 | } |
1664 | ||
a5aa8086 VZ |
1665 | long wxTextCtrl::GetLengthOfLineContainingPos(long pos) const |
1666 | { | |
1667 | return ::SendMessage(GetHwnd(), EM_LINELENGTH, (WPARAM)pos, 0); | |
1668 | } | |
1669 | ||
debe6624 | 1670 | int wxTextCtrl::GetLineLength(long lineNo) const |
2bda0e17 | 1671 | { |
a5aa8086 VZ |
1672 | long pos = XYToPosition(0, lineNo); |
1673 | ||
1674 | return GetLengthOfLineContainingPos(pos); | |
2bda0e17 KB |
1675 | } |
1676 | ||
debe6624 | 1677 | wxString wxTextCtrl::GetLineText(long lineNo) const |
2bda0e17 | 1678 | { |
a1b82138 | 1679 | size_t len = (size_t)GetLineLength(lineNo) + 1; |
488fe1fe | 1680 | |
f6bcfd97 BP |
1681 | // there must be at least enough place for the length WORD in the |
1682 | // buffer | |
1683 | len += sizeof(WORD); | |
4438caf4 | 1684 | |
f6bcfd97 | 1685 | wxString str; |
de564874 MB |
1686 | { |
1687 | wxStringBufferLength tmp(str, len); | |
1688 | wxChar *buf = tmp; | |
1689 | ||
1690 | *(WORD *)buf = (WORD)len; | |
60ab0c52 VZ |
1691 | len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf); |
1692 | ||
1693 | #if wxUSE_RICHEDIT | |
1694 | if ( IsRich() ) | |
1695 | { | |
1696 | // remove the '\r' returned by the rich edit control, the user code | |
1697 | // should never see it | |
1698 | if ( buf[len - 2] == _T('\r') && buf[len - 1] == _T('\n') ) | |
1699 | { | |
1700 | buf[len - 2] = _T('\n'); | |
1701 | len--; | |
1702 | } | |
1703 | } | |
1704 | #endif // wxUSE_RICHEDIT | |
1705 | ||
8f387d13 VZ |
1706 | // remove the '\n' at the end, if any (this is how this function is |
1707 | // supposed to work according to the docs) | |
1708 | if ( buf[len - 1] == _T('\n') ) | |
1709 | { | |
1710 | len--; | |
1711 | } | |
1712 | ||
de564874 MB |
1713 | buf[len] = 0; |
1714 | tmp.SetLength(len); | |
1715 | } | |
4438caf4 VZ |
1716 | |
1717 | return str; | |
2bda0e17 KB |
1718 | } |
1719 | ||
d7eee191 VZ |
1720 | void wxTextCtrl::SetMaxLength(unsigned long len) |
1721 | { | |
4a82116e | 1722 | #if wxUSE_RICHEDIT |
4fa80851 VZ |
1723 | if ( IsRich() ) |
1724 | { | |
1725 | ::SendMessage(GetHwnd(), EM_EXLIMITTEXT, 0, len ? len : 0x7fffffff); | |
1726 | } | |
4a82116e | 1727 | else |
4fa80851 VZ |
1728 | #endif // wxUSE_RICHEDIT |
1729 | { | |
1730 | if ( len >= 0xffff ) | |
1731 | { | |
1732 | // this will set it to a platform-dependent maximum (much more | |
1733 | // than 64Kb under NT) | |
1734 | len = 0; | |
1735 | } | |
1736 | ||
1737 | ::SendMessage(GetHwnd(), EM_LIMITTEXT, len, 0); | |
1738 | } | |
d7eee191 VZ |
1739 | } |
1740 | ||
a1b82138 | 1741 | // ---------------------------------------------------------------------------- |
ca8b28f2 | 1742 | // Undo/redo |
a1b82138 VZ |
1743 | // ---------------------------------------------------------------------------- |
1744 | ||
ca8b28f2 JS |
1745 | void wxTextCtrl::Undo() |
1746 | { | |
1747 | if (CanUndo()) | |
1748 | { | |
789295bf | 1749 | ::SendMessage(GetHwnd(), EM_UNDO, 0, 0); |
ca8b28f2 JS |
1750 | } |
1751 | } | |
1752 | ||
1753 | void wxTextCtrl::Redo() | |
1754 | { | |
1755 | if (CanRedo()) | |
1756 | { | |
4a82116e JS |
1757 | #if wxUSE_RICHEDIT |
1758 | if (GetRichVersion() > 1) | |
1759 | ::SendMessage(GetHwnd(), EM_REDO, 0, 0); | |
1760 | else | |
1761 | #endif | |
ca8b28f2 | 1762 | // Same as Undo, since Undo undoes the undo, i.e. a redo. |
789295bf | 1763 | ::SendMessage(GetHwnd(), EM_UNDO, 0, 0); |
ca8b28f2 JS |
1764 | } |
1765 | } | |
1766 | ||
1767 | bool wxTextCtrl::CanUndo() const | |
1768 | { | |
a5aa8086 | 1769 | return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0; |
ca8b28f2 JS |
1770 | } |
1771 | ||
1772 | bool wxTextCtrl::CanRedo() const | |
1773 | { | |
4a82116e JS |
1774 | #if wxUSE_RICHEDIT |
1775 | if (GetRichVersion() > 1) | |
1776 | return ::SendMessage(GetHwnd(), EM_CANREDO, 0, 0) != 0; | |
1777 | else | |
1778 | #endif | |
a5aa8086 | 1779 | return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0; |
ca8b28f2 JS |
1780 | } |
1781 | ||
e3a6a6b2 VZ |
1782 | // ---------------------------------------------------------------------------- |
1783 | // caret handling (Windows only) | |
1784 | // ---------------------------------------------------------------------------- | |
1785 | ||
1786 | bool wxTextCtrl::ShowNativeCaret(bool show) | |
1787 | { | |
1788 | if ( show != m_isNativeCaretShown ) | |
1789 | { | |
1790 | if ( !(show ? ::ShowCaret(GetHwnd()) : ::HideCaret(GetHwnd())) ) | |
1791 | { | |
1792 | // not an error, may simply indicate that it's not shown/hidden | |
1793 | // yet (i.e. it had been hidden/showh 2 times before) | |
1794 | return false; | |
1795 | } | |
1796 | ||
1797 | m_isNativeCaretShown = show; | |
1798 | } | |
1799 | ||
1800 | return true; | |
1801 | } | |
1802 | ||
a1b82138 VZ |
1803 | // ---------------------------------------------------------------------------- |
1804 | // implemenation details | |
1805 | // ---------------------------------------------------------------------------- | |
39136494 | 1806 | |
2bda0e17 KB |
1807 | void wxTextCtrl::Command(wxCommandEvent & event) |
1808 | { | |
a1b82138 VZ |
1809 | SetValue(event.GetString()); |
1810 | ProcessCommand (event); | |
2bda0e17 KB |
1811 | } |
1812 | ||
1813 | void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) | |
1814 | { | |
a1b82138 VZ |
1815 | // By default, load the first file into the text window. |
1816 | if (event.GetNumberOfFiles() > 0) | |
1817 | { | |
1818 | LoadFile(event.GetFiles()[0]); | |
1819 | } | |
2bda0e17 KB |
1820 | } |
1821 | ||
a37d422a VZ |
1822 | // ---------------------------------------------------------------------------- |
1823 | // kbd input processing | |
1824 | // ---------------------------------------------------------------------------- | |
1825 | ||
90c6edd7 | 1826 | bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* msg) |
a37d422a | 1827 | { |
a37d422a VZ |
1828 | // check for our special keys here: if we don't do it and the parent frame |
1829 | // uses them as accelerators, they wouldn't work at all, so we disable | |
1830 | // usual preprocessing for them | |
1831 | if ( msg->message == WM_KEYDOWN ) | |
1832 | { | |
90c6edd7 VZ |
1833 | const WPARAM vkey = msg->wParam; |
1834 | if ( HIWORD(msg->lParam) & KF_ALTDOWN ) | |
a37d422a | 1835 | { |
90c6edd7 | 1836 | // Alt-Backspace is accelerator for "Undo" |
a37d422a | 1837 | if ( vkey == VK_BACK ) |
bfbb0b4c | 1838 | return false; |
a37d422a VZ |
1839 | } |
1840 | else // no Alt | |
1841 | { | |
cf6e951c VZ |
1842 | // we want to process some Ctrl-foo and Shift-bar but no key |
1843 | // combinations without either Ctrl or Shift nor with both of them | |
1844 | // pressed | |
1845 | const int ctrl = wxIsCtrlDown(), | |
1846 | shift = wxIsShiftDown(); | |
1847 | switch ( ctrl + shift ) | |
a37d422a | 1848 | { |
cf6e951c VZ |
1849 | default: |
1850 | wxFAIL_MSG( _T("how many modifiers have we got?") ); | |
1851 | // fall through | |
1852 | ||
1853 | case 0: | |
eedf954b | 1854 | if ( IsMultiLine() && vkey == VK_RETURN ) |
90c6edd7 VZ |
1855 | return false; |
1856 | // fall through | |
cf6e951c VZ |
1857 | case 2: |
1858 | break; | |
1859 | ||
1860 | case 1: | |
1861 | // either Ctrl or Shift pressed | |
1862 | if ( ctrl ) | |
1863 | { | |
1864 | switch ( vkey ) | |
1865 | { | |
1866 | case 'C': | |
1867 | case 'V': | |
1868 | case 'X': | |
1869 | case VK_INSERT: | |
1870 | case VK_DELETE: | |
1871 | case VK_HOME: | |
1872 | case VK_END: | |
bfbb0b4c | 1873 | return false; |
cf6e951c VZ |
1874 | } |
1875 | } | |
1876 | else // Shift is pressed | |
1877 | { | |
1878 | if ( vkey == VK_INSERT || vkey == VK_DELETE ) | |
bfbb0b4c | 1879 | return false; |
cf6e951c | 1880 | } |
a37d422a VZ |
1881 | } |
1882 | } | |
1883 | } | |
1884 | ||
90c6edd7 | 1885 | return wxControl::MSWShouldPreProcessMessage(msg); |
a37d422a VZ |
1886 | } |
1887 | ||
2bda0e17 KB |
1888 | void wxTextCtrl::OnChar(wxKeyEvent& event) |
1889 | { | |
77e00fe9 | 1890 | switch ( event.GetKeyCode() ) |
cd471848 | 1891 | { |
cd471848 | 1892 | case WXK_RETURN: |
cd471848 VZ |
1893 | { |
1894 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
bfbd6dc1 | 1895 | InitCommandEvent(event); |
f6bcfd97 | 1896 | event.SetString(GetValue()); |
cd471848 | 1897 | if ( GetEventHandler()->ProcessEvent(event) ) |
9a3952fa | 1898 | if ( !HasFlag(wxTE_MULTILINE) ) |
cd471848 | 1899 | return; |
9a3952fa | 1900 | //else: multiline controls need Enter for themselves |
cd471848 | 1901 | } |
5fb9fcfc | 1902 | break; |
4d91c1d1 | 1903 | |
cd471848 | 1904 | case WXK_TAB: |
818d407a VZ |
1905 | // ok, so this is getting absolutely ridiculous but I don't see |
1906 | // any other way to fix this bug: when a multiline text control is | |
1907 | // inside a wxFrame, we need to generate the navigation event as | |
1908 | // otherwise nothing happens at all, but when the same control is | |
1909 | // created inside a dialog, IsDialogMessage() *does* switch focus | |
1910 | // all by itself and so if we do it here as well, it is advanced | |
1911 | // twice and goes to the next control... to prevent this from | |
1912 | // happening we're doing this ugly check, the logic being that if | |
1913 | // we don't have focus then it had been already changed to the next | |
1914 | // control | |
1915 | // | |
1916 | // the right thing to do would, of course, be to understand what | |
1917 | // the hell is IsDialogMessage() doing but this is beyond my feeble | |
1918 | // forces at the moment unfortunately | |
5f6cfda7 | 1919 | if ( !(m_windowStyle & wxTE_PROCESS_TAB)) |
cd471848 | 1920 | { |
5f6cfda7 JS |
1921 | if ( FindFocus() == this ) |
1922 | { | |
eedc82f4 JS |
1923 | int flags = 0; |
1924 | if (!event.ShiftDown()) | |
1925 | flags |= wxNavigationKeyEvent::IsForward ; | |
1926 | if (event.ControlDown()) | |
1927 | flags |= wxNavigationKeyEvent::WinChange ; | |
1928 | if (Navigate(flags)) | |
5f6cfda7 JS |
1929 | return; |
1930 | } | |
1931 | } | |
1932 | else | |
1933 | { | |
1934 | // Insert tab since calling the default Windows handler | |
1935 | // doesn't seem to do it | |
1936 | WriteText(wxT("\t")); | |
d1fd98cc | 1937 | return; |
cd471848 | 1938 | } |
341c92a8 | 1939 | break; |
cd471848 | 1940 | } |
39136494 | 1941 | |
8614c467 | 1942 | // no, we didn't process it |
42e69d6b | 1943 | event.Skip(); |
2bda0e17 KB |
1944 | } |
1945 | ||
c140b7e7 | 1946 | WXLRESULT wxTextCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
0cf5b099 | 1947 | { |
c140b7e7 | 1948 | WXLRESULT lRc = wxTextCtrlBase::MSWWindowProc(nMsg, wParam, lParam); |
e7e91e03 | 1949 | |
9fcbe076 | 1950 | switch ( nMsg ) |
0cf5b099 | 1951 | { |
9fcbe076 VZ |
1952 | case WM_GETDLGCODE: |
1953 | { | |
1954 | // we always want the chars and the arrows: the arrows for | |
1955 | // navigation and the chars because we want Ctrl-C to work even | |
1956 | // in a read only control | |
1957 | long lDlgCode = DLGC_WANTCHARS | DLGC_WANTARROWS; | |
2b5f62a0 | 1958 | |
9fcbe076 VZ |
1959 | if ( IsEditable() ) |
1960 | { | |
1961 | // we may have several different cases: | |
1962 | // 1. normal: both TAB and ENTER are used for navigation | |
1963 | // 2. ctrl wants TAB for itself: ENTER is used to pass to | |
1964 | // the next control in the dialog | |
1965 | // 3. ctrl wants ENTER for itself: TAB is used for dialog | |
1966 | // navigation | |
1967 | // 4. ctrl wants both TAB and ENTER: Ctrl-ENTER is used to | |
1968 | // go to the next control (we need some way to do it) | |
1969 | ||
1970 | // multiline controls should always get ENTER for themselves | |
1971 | if ( HasFlag(wxTE_PROCESS_ENTER) || HasFlag(wxTE_MULTILINE) ) | |
1972 | lDlgCode |= DLGC_WANTMESSAGE; | |
1973 | ||
1974 | if ( HasFlag(wxTE_PROCESS_TAB) ) | |
1975 | lDlgCode |= DLGC_WANTTAB; | |
1976 | ||
1977 | lRc |= lDlgCode; | |
1978 | } | |
1979 | else // !editable | |
1980 | { | |
1981 | // NB: use "=", not "|=" as the base class version returns | |
1982 | // the same flags is this state as usual (i.e. | |
1983 | // including DLGC_WANTMESSAGE). This is strange (how | |
1984 | // does it work in the native Win32 apps?) but for now | |
1985 | // live with it. | |
1986 | lRc = lDlgCode; | |
1987 | } | |
1988 | } | |
1989 | break; | |
1990 | ||
1991 | case WM_CUT: | |
1992 | case WM_COPY: | |
1993 | case WM_PASTE: | |
1994 | if ( HandleClipboardEvent(nMsg) ) | |
1995 | lRc = 0; | |
1996 | break; | |
0cf5b099 VZ |
1997 | } |
1998 | ||
e7e91e03 | 1999 | return lRc; |
129223d6 VZ |
2000 | } |
2001 | ||
2002 | // ---------------------------------------------------------------------------- | |
2003 | // text control event processing | |
2004 | // ---------------------------------------------------------------------------- | |
2005 | ||
5036ea90 VZ |
2006 | bool wxTextCtrl::SendUpdateEvent() |
2007 | { | |
2c62dd25 | 2008 | switch ( m_updatesCount ) |
5036ea90 | 2009 | { |
2c62dd25 VZ |
2010 | case 0: |
2011 | // remember that we've got an update | |
2012 | m_updatesCount++; | |
2013 | break; | |
5036ea90 | 2014 | |
2c62dd25 VZ |
2015 | case 1: |
2016 | // we had already sent one event since the last control modification | |
2017 | return false; | |
2018 | ||
2019 | default: | |
2020 | wxFAIL_MSG( _T("unexpected wxTextCtrl::m_updatesCount value") ); | |
2021 | // fall through | |
2022 | ||
2023 | case -1: | |
2024 | // we hadn't updated the control ourselves, this event comes from | |
2025 | // the user, don't need to ignore it nor update the count | |
2026 | break; | |
f6519b40 VZ |
2027 | |
2028 | case -2: | |
2029 | // the control was updated programmatically and we do NOT want to | |
2030 | // send events | |
2031 | return false; | |
5036ea90 VZ |
2032 | } |
2033 | ||
2034 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId()); | |
2035 | InitCommandEvent(event); | |
5036ea90 VZ |
2036 | |
2037 | return ProcessCommand(event); | |
2038 | } | |
2039 | ||
debe6624 | 2040 | bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) |
2bda0e17 | 2041 | { |
5036ea90 | 2042 | switch ( param ) |
789295bf VZ |
2043 | { |
2044 | case EN_SETFOCUS: | |
2045 | case EN_KILLFOCUS: | |
2046 | { | |
2047 | wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS | |
d7eee191 VZ |
2048 | : wxEVT_SET_FOCUS, |
2049 | m_windowId); | |
5036ea90 | 2050 | event.SetEventObject(this); |
789295bf VZ |
2051 | GetEventHandler()->ProcessEvent(event); |
2052 | } | |
2053 | break; | |
ae29de83 | 2054 | |
789295bf | 2055 | case EN_CHANGE: |
5036ea90 | 2056 | SendUpdateEvent(); |
789295bf | 2057 | break; |
2bda0e17 | 2058 | |
b12915c1 | 2059 | case EN_MAXTEXT: |
5036ea90 | 2060 | // the text size limit has been hit -- try to increase it |
d7eee191 VZ |
2061 | if ( !AdjustSpaceLimit() ) |
2062 | { | |
2063 | wxCommandEvent event(wxEVT_COMMAND_TEXT_MAXLEN, m_windowId); | |
2064 | InitCommandEvent(event); | |
2065 | event.SetString(GetValue()); | |
2066 | ProcessCommand(event); | |
2067 | } | |
789295bf VZ |
2068 | break; |
2069 | ||
5036ea90 | 2070 | // the other edit notification messages are not processed |
789295bf | 2071 | default: |
bfbb0b4c | 2072 | return false; |
789295bf VZ |
2073 | } |
2074 | ||
2075 | // processed | |
bfbb0b4c | 2076 | return true; |
2bda0e17 KB |
2077 | } |
2078 | ||
2bae4332 | 2079 | WXHBRUSH wxTextCtrl::MSWControlColor(WXHDC hDC, WXHWND hWnd) |
f6bcfd97 | 2080 | { |
48fa6bd3 VZ |
2081 | if ( !IsEnabled() && !HasFlag(wxTE_MULTILINE) ) |
2082 | return MSWControlColorDisabled(hDC); | |
f6bcfd97 | 2083 | |
2bae4332 | 2084 | return wxTextCtrlBase::MSWControlColor(hDC, hWnd); |
f6bcfd97 BP |
2085 | } |
2086 | ||
4fa80851 | 2087 | bool wxTextCtrl::HasSpaceLimit(unsigned int *len) const |
789295bf | 2088 | { |
d7eee191 VZ |
2089 | // HACK: we try to automatically extend the limit for the amount of text |
2090 | // to allow (interactively) entering more than 64Kb of text under | |
2091 | // Win9x but we shouldn't reset the text limit which was previously | |
2092 | // set explicitly with SetMaxLength() | |
2093 | // | |
4fa80851 VZ |
2094 | // Unfortunately there is no EM_GETLIMITTEXTSETBYUSER and so we don't |
2095 | // know the limit we set (if any). We could solve this by storing the | |
2096 | // limit we set in wxTextCtrl but to save space we prefer to simply | |
2097 | // test here the actual limit value: we consider that SetMaxLength() | |
2098 | // can only be called for small values while EN_MAXTEXT is only sent | |
2099 | // for large values (in practice the default limit seems to be 30000 | |
2100 | // but make it smaller just to be on the safe side) | |
2101 | *len = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0); | |
2102 | return *len < 10001; | |
2103 | ||
2104 | } | |
2105 | ||
2106 | bool wxTextCtrl::AdjustSpaceLimit() | |
2107 | { | |
2108 | unsigned int limit; | |
2109 | if ( HasSpaceLimit(&limit) ) | |
bfbb0b4c | 2110 | return false; |
d7eee191 VZ |
2111 | |
2112 | unsigned int len = ::GetWindowTextLength(GetHwnd()); | |
17d8ee1c | 2113 | if ( len >= limit ) |
789295bf | 2114 | { |
4fa80851 VZ |
2115 | // increment in 32Kb chunks |
2116 | SetMaxLength(len + 0x8000); | |
789295bf | 2117 | } |
d7eee191 VZ |
2118 | |
2119 | // we changed the limit | |
bfbb0b4c | 2120 | return true; |
789295bf | 2121 | } |
2bda0e17 | 2122 | |
a1b82138 | 2123 | bool wxTextCtrl::AcceptsFocus() const |
2bda0e17 | 2124 | { |
589c7163 VZ |
2125 | // we don't want focus if we can't be edited unless we're a multiline |
2126 | // control because then it might be still nice to get focus from keyboard | |
2127 | // to be able to scroll it without mouse | |
2128 | return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus(); | |
a1b82138 | 2129 | } |
c085e333 | 2130 | |
f68586e5 | 2131 | wxSize wxTextCtrl::DoGetBestSize() const |
a1b82138 VZ |
2132 | { |
2133 | int cx, cy; | |
7a5e53ab | 2134 | wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); |
a1b82138 VZ |
2135 | |
2136 | int wText = DEFAULT_ITEM_WIDTH; | |
2137 | ||
f60e797e | 2138 | int hText = cy; |
a1b82138 VZ |
2139 | if ( m_windowStyle & wxTE_MULTILINE ) |
2140 | { | |
b7a3ba7d | 2141 | hText *= wxMax(wxMin(GetNumberOfLines(), 10), 2); |
a1b82138 VZ |
2142 | } |
2143 | //else: for single line control everything is ok | |
2144 | ||
f60e797e VZ |
2145 | // we have to add the adjustments for the control height only once, not |
2146 | // once per line, so do it after multiplication above | |
2147 | hText += EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) - cy; | |
2148 | ||
a1b82138 | 2149 | return wxSize(wText, hText); |
2bda0e17 | 2150 | } |
a1b82138 VZ |
2151 | |
2152 | // ---------------------------------------------------------------------------- | |
2153 | // standard handlers for standard edit menu events | |
2154 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 2155 | |
bfbd6dc1 | 2156 | void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) |
e702ff0f JS |
2157 | { |
2158 | Cut(); | |
2159 | } | |
2160 | ||
bfbd6dc1 | 2161 | void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) |
e702ff0f JS |
2162 | { |
2163 | Copy(); | |
2164 | } | |
2165 | ||
bfbd6dc1 | 2166 | void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) |
e702ff0f JS |
2167 | { |
2168 | Paste(); | |
2169 | } | |
2170 | ||
bfbd6dc1 | 2171 | void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) |
e702ff0f JS |
2172 | { |
2173 | Undo(); | |
2174 | } | |
2175 | ||
bfbd6dc1 | 2176 | void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) |
e702ff0f JS |
2177 | { |
2178 | Redo(); | |
2179 | } | |
2180 | ||
2eb10e2a | 2181 | void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) |
2b5f62a0 VZ |
2182 | { |
2183 | long from, to; | |
2184 | GetSelection(& from, & to); | |
2185 | if (from != -1 && to != -1) | |
2186 | Remove(from, to); | |
2187 | } | |
2188 | ||
2eb10e2a | 2189 | void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) |
2b5f62a0 VZ |
2190 | { |
2191 | SetSelection(-1, -1); | |
2192 | } | |
2193 | ||
e702ff0f JS |
2194 | void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) |
2195 | { | |
2196 | event.Enable( CanCut() ); | |
2197 | } | |
2198 | ||
2199 | void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) | |
2200 | { | |
2201 | event.Enable( CanCopy() ); | |
2202 | } | |
2203 | ||
2204 | void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) | |
2205 | { | |
2206 | event.Enable( CanPaste() ); | |
2207 | } | |
2208 | ||
2209 | void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) | |
2210 | { | |
2211 | event.Enable( CanUndo() ); | |
2212 | } | |
2213 | ||
2214 | void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) | |
2215 | { | |
2216 | event.Enable( CanRedo() ); | |
2217 | } | |
2218 | ||
2b5f62a0 VZ |
2219 | void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) |
2220 | { | |
2221 | long from, to; | |
2222 | GetSelection(& from, & to); | |
2223 | event.Enable(from != -1 && to != -1 && from != to && IsEditable()) ; | |
2224 | } | |
2225 | ||
2226 | void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) | |
2227 | { | |
2228 | event.Enable(GetLastPosition() > 0); | |
2229 | } | |
2230 | ||
26f60eb6 | 2231 | void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) |
2b5f62a0 VZ |
2232 | { |
2233 | #if wxUSE_RICHEDIT | |
2234 | if (IsRich()) | |
2235 | { | |
2236 | if (!m_privateContextMenu) | |
2237 | { | |
2238 | m_privateContextMenu = new wxMenu; | |
2239 | m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); | |
2240 | m_privateContextMenu->Append(wxID_REDO, _("&Redo")); | |
2241 | m_privateContextMenu->AppendSeparator(); | |
2242 | m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); | |
2243 | m_privateContextMenu->Append(wxID_COPY, _("&Copy")); | |
2244 | m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); | |
2245 | m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); | |
2246 | m_privateContextMenu->AppendSeparator(); | |
2247 | m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); | |
2248 | } | |
26f60eb6 | 2249 | PopupMenu(m_privateContextMenu); |
2b5f62a0 VZ |
2250 | return; |
2251 | } | |
2252 | else | |
2253 | #endif | |
2254 | event.Skip(); | |
2255 | } | |
2256 | ||
2eb10e2a | 2257 | void wxTextCtrl::OnSetFocus(wxFocusEvent& WXUNUSED(event)) |
e3a6a6b2 VZ |
2258 | { |
2259 | // be sure the caret remains invisible if the user had hidden it | |
2260 | if ( !m_isNativeCaretShown ) | |
2261 | { | |
2262 | ::HideCaret(GetHwnd()); | |
2263 | } | |
2264 | } | |
2265 | ||
9e67e541 JS |
2266 | // ---------------------------------------------------------------------------- |
2267 | // Default colors for MSW text control | |
2268 | // | |
2269 | // Set default background color to the native white instead of | |
7d8268a1 | 2270 | // the default wxSYS_COLOUR_BTNFACE (is triggered with wxNullColour). |
9e67e541 JS |
2271 | // ---------------------------------------------------------------------------- |
2272 | ||
2273 | wxVisualAttributes wxTextCtrl::GetDefaultAttributes() const | |
2274 | { | |
2275 | wxVisualAttributes attrs; | |
2276 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
2277 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
2278 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); //white | |
2279 | ||
2280 | return attrs; | |
2281 | } | |
2282 | ||
4bc1afd5 VZ |
2283 | // the rest of the file only deals with the rich edit controls |
2284 | #if wxUSE_RICHEDIT | |
2285 | ||
c57e3339 VZ |
2286 | // ---------------------------------------------------------------------------- |
2287 | // EN_LINK processing | |
2288 | // ---------------------------------------------------------------------------- | |
2289 | ||
a64c3b74 | 2290 | bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) |
c57e3339 VZ |
2291 | { |
2292 | NMHDR *hdr = (NMHDR* )lParam; | |
1dae1d00 | 2293 | switch ( hdr->code ) |
c57e3339 | 2294 | { |
3bce6687 | 2295 | case EN_MSGFILTER: |
1dae1d00 VZ |
2296 | { |
2297 | const MSGFILTER *msgf = (MSGFILTER *)lParam; | |
2298 | UINT msg = msgf->msg; | |
2299 | ||
2300 | // this is a bit crazy but richedit 1.0 sends us all mouse | |
2301 | // events _except_ WM_LBUTTONUP (don't ask me why) so we have | |
2302 | // generate the wxWin events for this message manually | |
2303 | // | |
2304 | // NB: in fact, this is still not totally correct as it does | |
2305 | // send us WM_LBUTTONUP if the selection was cleared by the | |
2306 | // last click -- so currently we get 2 events in this case, | |
2307 | // but as I don't see any obvious way to check for this I | |
2308 | // leave this code in place because it's still better than | |
2309 | // not getting left up events at all | |
2310 | if ( msg == WM_LBUTTONUP ) | |
c57e3339 | 2311 | { |
1dae1d00 VZ |
2312 | WXUINT flags = msgf->wParam; |
2313 | int x = GET_X_LPARAM(msgf->lParam), | |
2314 | y = GET_Y_LPARAM(msgf->lParam); | |
2315 | ||
2316 | HandleMouseEvent(msg, x, y, flags); | |
c57e3339 | 2317 | } |
1dae1d00 | 2318 | } |
c57e3339 | 2319 | |
bfbb0b4c WS |
2320 | // return true to process the event (and false to ignore it) |
2321 | return true; | |
1dae1d00 VZ |
2322 | |
2323 | case EN_LINK: | |
2324 | { | |
2325 | const ENLINK *enlink = (ENLINK *)hdr; | |
2326 | ||
2327 | switch ( enlink->msg ) | |
2328 | { | |
2329 | case WM_SETCURSOR: | |
2330 | // ok, so it is hardcoded - do we really nee to | |
2331 | // customize it? | |
5c519b6c WS |
2332 | { |
2333 | wxCursor cur(wxCURSOR_HAND); | |
2334 | ::SetCursor(GetHcursorOf(cur)); | |
2335 | *result = TRUE; | |
2336 | break; | |
2337 | } | |
1dae1d00 VZ |
2338 | |
2339 | case WM_MOUSEMOVE: | |
2340 | case WM_LBUTTONDOWN: | |
2341 | case WM_LBUTTONUP: | |
2342 | case WM_LBUTTONDBLCLK: | |
2343 | case WM_RBUTTONDOWN: | |
2344 | case WM_RBUTTONUP: | |
2345 | case WM_RBUTTONDBLCLK: | |
2346 | // send a mouse event | |
2347 | { | |
2348 | static const wxEventType eventsMouse[] = | |
2349 | { | |
2350 | wxEVT_MOTION, | |
2351 | wxEVT_LEFT_DOWN, | |
2352 | wxEVT_LEFT_UP, | |
2353 | wxEVT_LEFT_DCLICK, | |
2354 | wxEVT_RIGHT_DOWN, | |
2355 | wxEVT_RIGHT_UP, | |
2356 | wxEVT_RIGHT_DCLICK, | |
2357 | }; | |
2358 | ||
2359 | // the event ids are consecutive | |
2360 | wxMouseEvent | |
2361 | evtMouse(eventsMouse[enlink->msg - WM_MOUSEMOVE]); | |
2362 | ||
2363 | InitMouseEvent(evtMouse, | |
2364 | GET_X_LPARAM(enlink->lParam), | |
2365 | GET_Y_LPARAM(enlink->lParam), | |
2366 | enlink->wParam); | |
2367 | ||
2368 | wxTextUrlEvent event(m_windowId, evtMouse, | |
2369 | enlink->chrg.cpMin, | |
2370 | enlink->chrg.cpMax); | |
2371 | ||
2372 | InitCommandEvent(event); | |
2373 | ||
2374 | *result = ProcessCommand(event); | |
2375 | } | |
2376 | break; | |
2377 | } | |
2378 | } | |
bfbb0b4c | 2379 | return true; |
c57e3339 | 2380 | } |
7f5d8b00 | 2381 | |
d86ab8e2 VZ |
2382 | // not processed, leave it to the base class |
2383 | return wxTextCtrlBase::MSWOnNotify(idCtrl, lParam, result); | |
c57e3339 VZ |
2384 | } |
2385 | ||
52f2f7b2 | 2386 | // ---------------------------------------------------------------------------- |
f6bcfd97 BP |
2387 | // colour setting for the rich edit controls |
2388 | // ---------------------------------------------------------------------------- | |
2389 | ||
f6bcfd97 BP |
2390 | bool wxTextCtrl::SetBackgroundColour(const wxColour& colour) |
2391 | { | |
2392 | if ( !wxTextCtrlBase::SetBackgroundColour(colour) ) | |
2393 | { | |
2394 | // colour didn't really change | |
bfbb0b4c | 2395 | return false; |
f6bcfd97 BP |
2396 | } |
2397 | ||
2398 | if ( IsRich() ) | |
2399 | { | |
2400 | // rich edit doesn't use WM_CTLCOLOR, hence we need to send | |
2401 | // EM_SETBKGNDCOLOR additionally | |
2402 | ::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR, 0, wxColourToRGB(colour)); | |
2403 | } | |
2404 | ||
bfbb0b4c | 2405 | return true; |
f6bcfd97 BP |
2406 | } |
2407 | ||
2408 | bool wxTextCtrl::SetForegroundColour(const wxColour& colour) | |
2409 | { | |
2410 | if ( !wxTextCtrlBase::SetForegroundColour(colour) ) | |
2411 | { | |
2412 | // colour didn't really change | |
bfbb0b4c | 2413 | return false; |
f6bcfd97 BP |
2414 | } |
2415 | ||
2416 | if ( IsRich() ) | |
2417 | { | |
2418 | // change the colour of everything | |
2419 | CHARFORMAT cf; | |
2420 | wxZeroMemory(cf); | |
2421 | cf.cbSize = sizeof(cf); | |
2422 | cf.dwMask = CFM_COLOR; | |
2423 | cf.crTextColor = wxColourToRGB(colour); | |
2424 | ::SendMessage(GetHwnd(), EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); | |
2425 | } | |
2426 | ||
bfbb0b4c | 2427 | return true; |
f6bcfd97 BP |
2428 | } |
2429 | ||
4bc1afd5 VZ |
2430 | // ---------------------------------------------------------------------------- |
2431 | // styling support for rich edit controls | |
2432 | // ---------------------------------------------------------------------------- | |
2433 | ||
cc164686 RD |
2434 | #if wxUSE_RICHEDIT |
2435 | ||
4bc1afd5 VZ |
2436 | bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) |
2437 | { | |
2438 | if ( !IsRich() ) | |
2439 | { | |
2440 | // can't do it with normal text control | |
bfbb0b4c | 2441 | return false; |
4bc1afd5 VZ |
2442 | } |
2443 | ||
a5aa8086 VZ |
2444 | // the richedit 1.0 doesn't handle setting background colour, so don't |
2445 | // even try to do anything if it's the only thing we want to change | |
e00a5d3c JS |
2446 | if ( m_verRichEdit == 1 && !style.HasFont() && !style.HasTextColour() && |
2447 | !style.HasLeftIndent() && !style.HasRightIndent() && !style.HasAlignment() && | |
2448 | !style.HasTabs() ) | |
4bc1afd5 | 2449 | { |
bfbb0b4c WS |
2450 | // nothing to do: return true if there was really nothing to do and |
2451 | // false if we failed to set bg colour | |
4bc1afd5 VZ |
2452 | return !style.HasBackgroundColour(); |
2453 | } | |
2454 | ||
2455 | // order the range if needed | |
2456 | if ( start > end ) | |
2457 | { | |
2458 | long tmp = start; | |
2459 | start = end; | |
2460 | end = tmp; | |
2461 | } | |
2462 | ||
2463 | // we can only change the format of the selection, so select the range we | |
2464 | // want and restore the old selection later | |
2465 | long startOld, endOld; | |
2466 | GetSelection(&startOld, &endOld); | |
2467 | ||
2468 | // but do we really have to change the selection? | |
2469 | bool changeSel = start != startOld || end != endOld; | |
2470 | ||
2471 | if ( changeSel ) | |
aac7e7fe | 2472 | { |
bfbb0b4c | 2473 | DoSetSelection(start, end, false /* don't scroll caret into view */); |
aac7e7fe | 2474 | } |
4bc1afd5 VZ |
2475 | |
2476 | // initialize CHARFORMAT struct | |
be329a3d RD |
2477 | #if wxUSE_RICHEDIT2 |
2478 | CHARFORMAT2 cf; | |
2479 | #else | |
4bc1afd5 | 2480 | CHARFORMAT cf; |
be329a3d | 2481 | #endif |
a5aa8086 | 2482 | |
4bc1afd5 | 2483 | wxZeroMemory(cf); |
a5aa8086 VZ |
2484 | |
2485 | // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple | |
2486 | // CHARFORMAT in that case | |
2487 | #if wxUSE_RICHEDIT2 | |
2488 | if ( m_verRichEdit == 1 ) | |
2489 | { | |
2490 | // this is the only thing the control is going to grok | |
2491 | cf.cbSize = sizeof(CHARFORMAT); | |
2492 | } | |
2493 | else | |
2494 | #endif | |
2495 | { | |
2496 | // CHARFORMAT or CHARFORMAT2 | |
2497 | cf.cbSize = sizeof(cf); | |
2498 | } | |
4bc1afd5 VZ |
2499 | |
2500 | if ( style.HasFont() ) | |
2501 | { | |
aac7e7fe VZ |
2502 | // VZ: CFM_CHARSET doesn't seem to do anything at all in RichEdit 2.0 |
2503 | // but using it doesn't seem to hurt neither so leaving it for now | |
2504 | ||
784164e1 VZ |
2505 | cf.dwMask |= CFM_FACE | CFM_SIZE | CFM_CHARSET | |
2506 | CFM_ITALIC | CFM_BOLD | CFM_UNDERLINE; | |
4bc1afd5 VZ |
2507 | |
2508 | // fill in data from LOGFONT but recalculate lfHeight because we need | |
2509 | // the real height in twips and not the negative number which | |
2510 | // wxFillLogFont() returns (this is correct in general and works with | |
2511 | // the Windows font mapper, but not here) | |
2512 | LOGFONT lf; | |
2513 | wxFillLogFont(&lf, &style.GetFont()); | |
2514 | cf.yHeight = 20*style.GetFont().GetPointSize(); // 1 pt = 20 twips | |
2515 | cf.bCharSet = lf.lfCharSet; | |
2516 | cf.bPitchAndFamily = lf.lfPitchAndFamily; | |
2517 | wxStrncpy( cf.szFaceName, lf.lfFaceName, WXSIZEOF(cf.szFaceName) ); | |
2518 | ||
784164e1 VZ |
2519 | // also deal with underline/italic/bold attributes: note that we must |
2520 | // always set CFM_ITALIC &c bits in dwMask, even if we don't set the | |
2521 | // style to allow clearing it | |
4bc1afd5 VZ |
2522 | if ( lf.lfItalic ) |
2523 | { | |
4bc1afd5 VZ |
2524 | cf.dwEffects |= CFE_ITALIC; |
2525 | } | |
2526 | ||
2527 | if ( lf.lfWeight == FW_BOLD ) | |
2528 | { | |
4bc1afd5 VZ |
2529 | cf.dwEffects |= CFE_BOLD; |
2530 | } | |
2531 | ||
2532 | if ( lf.lfUnderline ) | |
2533 | { | |
4bc1afd5 VZ |
2534 | cf.dwEffects |= CFE_UNDERLINE; |
2535 | } | |
2536 | ||
77ffb593 | 2537 | // strikeout fonts are not supported by wxWidgets |
4bc1afd5 VZ |
2538 | } |
2539 | ||
2540 | if ( style.HasTextColour() ) | |
2541 | { | |
2542 | cf.dwMask |= CFM_COLOR; | |
2543 | cf.crTextColor = wxColourToRGB(style.GetTextColour()); | |
2544 | } | |
2545 | ||
be329a3d | 2546 | #if wxUSE_RICHEDIT2 |
a5aa8086 | 2547 | if ( m_verRichEdit != 1 && style.HasBackgroundColour() ) |
be329a3d RD |
2548 | { |
2549 | cf.dwMask |= CFM_BACKCOLOR; | |
2550 | cf.crBackColor = wxColourToRGB(style.GetBackgroundColour()); | |
2551 | } | |
784164e1 VZ |
2552 | #endif // wxUSE_RICHEDIT2 |
2553 | ||
4bc1afd5 VZ |
2554 | // do format the selection |
2555 | bool ok = ::SendMessage(GetHwnd(), EM_SETCHARFORMAT, | |
2556 | SCF_SELECTION, (LPARAM)&cf) != 0; | |
2557 | if ( !ok ) | |
2558 | { | |
2559 | wxLogDebug(_T("SendMessage(EM_SETCHARFORMAT, SCF_SELECTION) failed")); | |
2560 | } | |
2561 | ||
e00a5d3c JS |
2562 | // now do the paragraph formatting |
2563 | PARAFORMAT2 pf; | |
2564 | wxZeroMemory(pf); | |
2565 | // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple | |
2566 | // PARAFORMAT in that case | |
2567 | #if wxUSE_RICHEDIT2 | |
2568 | if ( m_verRichEdit == 1 ) | |
2569 | { | |
2570 | // this is the only thing the control is going to grok | |
2571 | pf.cbSize = sizeof(PARAFORMAT); | |
2572 | } | |
2573 | else | |
2574 | #endif | |
2575 | { | |
2576 | // PARAFORMAT or PARAFORMAT2 | |
2577 | pf.cbSize = sizeof(pf); | |
2578 | } | |
2579 | ||
2580 | if (style.HasAlignment()) | |
2581 | { | |
2582 | pf.dwMask |= PFM_ALIGNMENT; | |
2583 | if (style.GetAlignment() == wxTEXT_ALIGNMENT_RIGHT) | |
2584 | pf.wAlignment = PFA_RIGHT; | |
2585 | else if (style.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE) | |
2586 | pf.wAlignment = PFA_CENTER; | |
2587 | else if (style.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED) | |
2588 | pf.wAlignment = PFA_JUSTIFY; | |
2589 | else | |
2590 | pf.wAlignment = PFA_LEFT; | |
2591 | } | |
2592 | ||
2593 | if (style.HasLeftIndent()) | |
2594 | { | |
89b67477 | 2595 | pf.dwMask |= PFM_STARTINDENT | PFM_OFFSET; |
e00a5d3c JS |
2596 | |
2597 | // Convert from 1/10 mm to TWIPS | |
2598 | pf.dxStartIndent = (int) (((double) style.GetLeftIndent()) * mm2twips / 10.0) ; | |
89b67477 | 2599 | pf.dxOffset = (int) (((double) style.GetLeftSubIndent()) * mm2twips / 10.0) ; |
e00a5d3c JS |
2600 | } |
2601 | ||
2602 | if (style.HasRightIndent()) | |
2603 | { | |
2604 | pf.dwMask |= PFM_RIGHTINDENT; | |
2605 | ||
2606 | // Convert from 1/10 mm to TWIPS | |
2607 | pf.dxRightIndent = (int) (((double) style.GetRightIndent()) * mm2twips / 10.0) ; | |
2608 | } | |
2609 | ||
2610 | if (style.HasTabs()) | |
2611 | { | |
2612 | pf.dwMask |= PFM_TABSTOPS; | |
2613 | ||
2614 | const wxArrayInt& tabs = style.GetTabs(); | |
2615 | ||
5c519b6c | 2616 | pf.cTabCount = (SHORT)wxMin(tabs.GetCount(), MAX_TAB_STOPS); |
e00a5d3c JS |
2617 | size_t i; |
2618 | for (i = 0; i < (size_t) pf.cTabCount; i++) | |
2619 | { | |
2620 | // Convert from 1/10 mm to TWIPS | |
2621 | pf.rgxTabs[i] = (int) (((double) tabs[i]) * mm2twips / 10.0) ; | |
2622 | } | |
2623 | } | |
2624 | ||
3488be9c VZ |
2625 | #if wxUSE_RICHEDIT2 |
2626 | if ( m_verRichEdit > 1 ) | |
2627 | { | |
2628 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) | |
2629 | { | |
2630 | // Use RTL paragraphs in RTL mode to get proper layout | |
2631 | pf.dwMask |= PFM_RTLPARA; | |
2632 | pf.wEffects |= PFE_RTLPARA; | |
2633 | } | |
2634 | } | |
2635 | #endif // wxUSE_RICHEDIT2 | |
2636 | ||
2637 | if ( pf.dwMask ) | |
e00a5d3c JS |
2638 | { |
2639 | // do format the selection | |
2640 | bool ok = ::SendMessage(GetHwnd(), EM_SETPARAFORMAT, | |
3488be9c | 2641 | 0, (LPARAM) &pf) != 0; |
e00a5d3c JS |
2642 | if ( !ok ) |
2643 | { | |
2644 | wxLogDebug(_T("SendMessage(EM_SETPARAFORMAT, 0) failed")); | |
2645 | } | |
2646 | } | |
2647 | ||
4bc1afd5 VZ |
2648 | if ( changeSel ) |
2649 | { | |
2650 | // restore the original selection | |
bfbb0b4c | 2651 | DoSetSelection(startOld, endOld, false); |
4bc1afd5 VZ |
2652 | } |
2653 | ||
2654 | return ok; | |
2655 | } | |
f6bcfd97 | 2656 | |
5bf75ae7 VZ |
2657 | bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) |
2658 | { | |
2659 | if ( !wxTextCtrlBase::SetDefaultStyle(style) ) | |
bfbb0b4c | 2660 | return false; |
5bf75ae7 | 2661 | |
caea50ac VZ |
2662 | if ( IsEditable() ) |
2663 | { | |
2664 | // we have to do this or the style wouldn't apply for the text typed by | |
2665 | // the user | |
7d8268a1 | 2666 | wxTextPos posLast = GetLastPosition(); |
caea50ac VZ |
2667 | SetStyle(posLast, posLast, m_defaultStyle); |
2668 | } | |
5bf75ae7 | 2669 | |
bfbb0b4c | 2670 | return true; |
5bf75ae7 VZ |
2671 | } |
2672 | ||
80185c6c | 2673 | bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) |
e00a5d3c | 2674 | { |
80185c6c JS |
2675 | if ( !IsRich() ) |
2676 | { | |
2677 | // can't do it with normal text control | |
bfbb0b4c | 2678 | return false; |
80185c6c JS |
2679 | } |
2680 | ||
2681 | // initialize CHARFORMAT struct | |
2682 | #if wxUSE_RICHEDIT2 | |
2683 | CHARFORMAT2 cf; | |
2684 | #else | |
2685 | CHARFORMAT cf; | |
2686 | #endif | |
2687 | ||
2688 | wxZeroMemory(cf); | |
2689 | ||
2690 | // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple | |
2691 | // CHARFORMAT in that case | |
2692 | #if wxUSE_RICHEDIT2 | |
2693 | if ( m_verRichEdit == 1 ) | |
2694 | { | |
2695 | // this is the only thing the control is going to grok | |
2696 | cf.cbSize = sizeof(CHARFORMAT); | |
2697 | } | |
2698 | else | |
2699 | #endif | |
2700 | { | |
2701 | // CHARFORMAT or CHARFORMAT2 | |
2702 | cf.cbSize = sizeof(cf); | |
2703 | } | |
2704 | // we can only change the format of the selection, so select the range we | |
2705 | // want and restore the old selection later | |
2706 | long startOld, endOld; | |
2707 | GetSelection(&startOld, &endOld); | |
2708 | ||
2709 | // but do we really have to change the selection? | |
2710 | bool changeSel = position != startOld || position != endOld; | |
2711 | ||
2712 | if ( changeSel ) | |
2713 | { | |
f1a777fe | 2714 | DoSetSelection(position, position+1, false /* don't scroll caret into view */); |
80185c6c JS |
2715 | } |
2716 | ||
2717 | // get the selection formatting | |
2718 | (void) ::SendMessage(GetHwnd(), EM_GETCHARFORMAT, | |
2719 | SCF_SELECTION, (LPARAM)&cf) ; | |
2720 | ||
093dee5e | 2721 | |
80185c6c JS |
2722 | LOGFONT lf; |
2723 | lf.lfHeight = cf.yHeight; | |
2724 | lf.lfWidth = 0; | |
2725 | lf.lfCharSet = ANSI_CHARSET; // FIXME: how to get correct charset? | |
2726 | lf.lfClipPrecision = 0; | |
2727 | lf.lfEscapement = 0; | |
2728 | wxStrcpy(lf.lfFaceName, cf.szFaceName); | |
093dee5e RN |
2729 | |
2730 | //NOTE: we _MUST_ set each of these values to _something_ since we | |
7d8268a1 | 2731 | //do not call wxZeroMemory on the LOGFONT lf |
80185c6c JS |
2732 | if (cf.dwEffects & CFE_ITALIC) |
2733 | lf.lfItalic = TRUE; | |
093dee5e RN |
2734 | else |
2735 | lf.lfItalic = FALSE; | |
2736 | ||
80185c6c JS |
2737 | lf.lfOrientation = 0; |
2738 | lf.lfPitchAndFamily = cf.bPitchAndFamily; | |
2739 | lf.lfQuality = 0; | |
093dee5e | 2740 | |
80185c6c JS |
2741 | if (cf.dwEffects & CFE_STRIKEOUT) |
2742 | lf.lfStrikeOut = TRUE; | |
093dee5e RN |
2743 | else |
2744 | lf.lfStrikeOut = FALSE; | |
2745 | ||
80185c6c JS |
2746 | if (cf.dwEffects & CFE_UNDERLINE) |
2747 | lf.lfUnderline = TRUE; | |
093dee5e RN |
2748 | else |
2749 | lf.lfUnderline = FALSE; | |
2750 | ||
80185c6c JS |
2751 | if (cf.dwEffects & CFE_BOLD) |
2752 | lf.lfWeight = FW_BOLD; | |
093dee5e RN |
2753 | else |
2754 | lf.lfWeight = FW_NORMAL; | |
80185c6c JS |
2755 | |
2756 | wxFont font = wxCreateFontFromLogFont(& lf); | |
2757 | if (font.Ok()) | |
2758 | { | |
2759 | style.SetFont(font); | |
2760 | } | |
2761 | style.SetTextColour(wxColour(cf.crTextColor)); | |
2762 | ||
2763 | #if wxUSE_RICHEDIT2 | |
2764 | if ( m_verRichEdit != 1 ) | |
2765 | { | |
2766 | // cf.dwMask |= CFM_BACKCOLOR; | |
2767 | style.SetBackgroundColour(wxColour(cf.crBackColor)); | |
2768 | } | |
2769 | #endif // wxUSE_RICHEDIT2 | |
2770 | ||
2771 | // now get the paragraph formatting | |
2772 | PARAFORMAT2 pf; | |
2773 | wxZeroMemory(pf); | |
2774 | // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple | |
2775 | // PARAFORMAT in that case | |
2776 | #if wxUSE_RICHEDIT2 | |
2777 | if ( m_verRichEdit == 1 ) | |
2778 | { | |
2779 | // this is the only thing the control is going to grok | |
2780 | pf.cbSize = sizeof(PARAFORMAT); | |
2781 | } | |
2782 | else | |
2783 | #endif | |
2784 | { | |
2785 | // PARAFORMAT or PARAFORMAT2 | |
2786 | pf.cbSize = sizeof(pf); | |
2787 | } | |
2788 | ||
2789 | // do format the selection | |
2790 | (void) ::SendMessage(GetHwnd(), EM_GETPARAFORMAT, 0, (LPARAM) &pf) ; | |
2791 | ||
89b67477 | 2792 | style.SetLeftIndent( (int) ((double) pf.dxStartIndent * twips2mm * 10.0), (int) ((double) pf.dxOffset * twips2mm * 10.0) ); |
80185c6c JS |
2793 | style.SetRightIndent( (int) ((double) pf.dxRightIndent * twips2mm * 10.0) ); |
2794 | ||
2795 | if (pf.wAlignment == PFA_CENTER) | |
2796 | style.SetAlignment(wxTEXT_ALIGNMENT_CENTRE); | |
2797 | else if (pf.wAlignment == PFA_RIGHT) | |
2798 | style.SetAlignment(wxTEXT_ALIGNMENT_RIGHT); | |
2799 | else if (pf.wAlignment == PFA_JUSTIFY) | |
2800 | style.SetAlignment(wxTEXT_ALIGNMENT_JUSTIFIED); | |
2801 | else | |
2802 | style.SetAlignment(wxTEXT_ALIGNMENT_LEFT); | |
2803 | ||
2804 | wxArrayInt tabStops; | |
2805 | size_t i; | |
2806 | for (i = 0; i < (size_t) pf.cTabCount; i++) | |
2807 | { | |
89b67477 | 2808 | tabStops.Add( (int) ((double) (pf.rgxTabs[i] & 0xFFFF) * twips2mm * 10.0) ); |
80185c6c JS |
2809 | } |
2810 | ||
2811 | if ( changeSel ) | |
2812 | { | |
2813 | // restore the original selection | |
bfbb0b4c | 2814 | DoSetSelection(startOld, endOld, false); |
80185c6c JS |
2815 | } |
2816 | ||
bfbb0b4c | 2817 | return true; |
e00a5d3c JS |
2818 | } |
2819 | ||
cc164686 RD |
2820 | #endif |
2821 | ||
b12915c1 VZ |
2822 | // ---------------------------------------------------------------------------- |
2823 | // wxRichEditModule | |
2824 | // ---------------------------------------------------------------------------- | |
2825 | ||
628c219e VZ |
2826 | static const HINSTANCE INVALID_HINSTANCE = (HINSTANCE)-1; |
2827 | ||
b12915c1 VZ |
2828 | bool wxRichEditModule::OnInit() |
2829 | { | |
2830 | // don't do anything - we will load it when needed | |
bfbb0b4c | 2831 | return true; |
b12915c1 VZ |
2832 | } |
2833 | ||
2834 | void wxRichEditModule::OnExit() | |
2835 | { | |
136cb3c7 | 2836 | for ( size_t i = 0; i < WXSIZEOF(ms_hRichEdit); i++ ) |
b12915c1 | 2837 | { |
628c219e | 2838 | if ( ms_hRichEdit[i] && ms_hRichEdit[i] != INVALID_HINSTANCE ) |
a5aa8086 VZ |
2839 | { |
2840 | ::FreeLibrary(ms_hRichEdit[i]); | |
8c74e477 | 2841 | ms_hRichEdit[i] = NULL; |
a5aa8086 | 2842 | } |
b12915c1 | 2843 | } |
8ef51d67 JS |
2844 | #if wxUSE_INKEDIT |
2845 | if (ms_inkEditLib.IsLoaded()) | |
2846 | ms_inkEditLib.Unload(); | |
2847 | #endif | |
b12915c1 VZ |
2848 | } |
2849 | ||
2850 | /* static */ | |
628c219e | 2851 | bool wxRichEditModule::Load(Version version) |
b12915c1 | 2852 | { |
628c219e | 2853 | if ( ms_hRichEdit[version] == INVALID_HINSTANCE ) |
b12915c1 | 2854 | { |
a5aa8086 | 2855 | // we had already tried to load it and failed |
bfbb0b4c | 2856 | return false; |
b12915c1 VZ |
2857 | } |
2858 | ||
28978e0c VZ |
2859 | if ( ms_hRichEdit[version] ) |
2860 | { | |
2861 | // we've already got this one | |
bfbb0b4c | 2862 | return true; |
28978e0c VZ |
2863 | } |
2864 | ||
628c219e VZ |
2865 | static const wxChar *dllnames[] = |
2866 | { | |
2867 | _T("riched32"), | |
2868 | _T("riched20"), | |
2869 | _T("msftedit"), | |
2870 | }; | |
2871 | ||
2872 | wxCOMPILE_TIME_ASSERT( WXSIZEOF(dllnames) == Version_Max, | |
2873 | RichEditDllNamesVersionsMismatch ); | |
b12915c1 | 2874 | |
628c219e | 2875 | ms_hRichEdit[version] = ::LoadLibrary(dllnames[version]); |
b12915c1 | 2876 | |
a5aa8086 | 2877 | if ( !ms_hRichEdit[version] ) |
b12915c1 | 2878 | { |
628c219e | 2879 | ms_hRichEdit[version] = INVALID_HINSTANCE; |
b12915c1 | 2880 | |
bfbb0b4c | 2881 | return false; |
b12915c1 VZ |
2882 | } |
2883 | ||
bfbb0b4c | 2884 | return true; |
b12915c1 VZ |
2885 | } |
2886 | ||
8ef51d67 JS |
2887 | #if wxUSE_INKEDIT |
2888 | // load the InkEdit library | |
2889 | bool wxRichEditModule::LoadInkEdit() | |
2890 | { | |
2891 | static wxDynamicLibrary ms_inkEditLib; | |
2892 | static bool ms_inkEditLibLoadAttemped; | |
2893 | if (ms_inkEditLibLoadAttemped) | |
2894 | ms_inkEditLib.IsLoaded(); | |
40ff126a | 2895 | |
8ef51d67 | 2896 | ms_inkEditLibLoadAttemped = true; |
40ff126a | 2897 | |
8ef51d67 JS |
2898 | wxLogNull logNull; |
2899 | return ms_inkEditLib.Load(wxT("inked")); | |
2900 | } | |
2901 | #endif | |
2902 | ||
2903 | ||
b12915c1 VZ |
2904 | #endif // wxUSE_RICHEDIT |
2905 | ||
3180bc0e | 2906 | #endif // wxUSE_TEXTCTRL && !(__SMARTPHONE__ && __WXWINCE__) |