]> git.saurik.com Git - wxWidgets.git/blame - src/msw/textctrl.cpp
Applied patch [ 571965 ] update stc contrib stuff
[wxWidgets.git] / src / msw / textctrl.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
bfbd6dc1 2// Name: msw/textctrl.cpp
2bda0e17
KB
3// Purpose: wxTextCtrl
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c085e333 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
a1b82138
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
2bda0e17 16#ifdef __GNUG__
a1b82138 17 #pragma implementation "textctrl.h"
2bda0e17
KB
18#endif
19
a1b82138
VZ
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
23
2bda0e17
KB
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
a1b82138 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
1e6feb95
VZ
31#if wxUSE_TEXTCTRL
32
2bda0e17 33#ifndef WX_PRECOMP
a1b82138
VZ
34 #include "wx/textctrl.h"
35 #include "wx/settings.h"
36 #include "wx/brush.h"
37 #include "wx/utils.h"
381dd4bf 38 #include "wx/intl.h"
a1b82138 39 #include "wx/log.h"
381dd4bf 40 #include "wx/app.h"
2bda0e17
KB
41#endif
42
f6bcfd97
BP
43#include "wx/module.h"
44
47d67540 45#if wxUSE_CLIPBOARD
a1b82138 46 #include "wx/clipbrd.h"
2bda0e17
KB
47#endif
48
a1b82138
VZ
49#include "wx/textfile.h"
50
51#include <windowsx.h>
52
2bda0e17
KB
53#include "wx/msw/private.h"
54
a1b82138 55#include <string.h>
2bda0e17 56#include <stdlib.h>
a1b82138 57#include <sys/types.h>
fbc535ff 58
ae090fdb 59#if wxUSE_RICHEDIT && (!defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__))
cd471848 60 #include <richedit.h>
2bda0e17
KB
61#endif
62
e80591b9
VZ
63// old mingw32 doesn't define this
64#ifndef CFM_CHARSET
65 #define CFM_CHARSET 0x08000000
66#endif // CFM_CHARSET
67
784164e1
VZ
68#ifndef CFM_BACKCOLOR
69 #define CFM_BACKCOLOR 0x04000000
70#endif
71
733e8cf3
VZ
72// cygwin does not have these defined for richedit
73#ifndef ENM_LINK
74 #define ENM_LINK 0x04000000
75#endif
76
77#ifndef EM_AUTOURLDETECT
78 #define EM_AUTOURLDETECT (WM_USER + 91)
79#endif
80
81#ifndef EN_LINK
82 #define EN_LINK 0x070b
83
84 typedef struct _enlink
85 {
86 NMHDR nmhdr;
87 UINT msg;
88 WPARAM wParam;
89 LPARAM lParam;
90 CHARRANGE chrg;
91 } ENLINK;
92#endif // ENLINK
93
7a25a27c
VZ
94#ifndef SF_UNICODE
95 #define SF_UNICODE 0x0010
96#endif
97
a5aa8086
VZ
98// Watcom C++ doesn't define this
99#ifndef SCF_ALL
100#define SCF_ALL 0x0004
101#endif
102
aac7e7fe
VZ
103// ----------------------------------------------------------------------------
104// private functions
105// ----------------------------------------------------------------------------
106
107#if wxUSE_RICHEDIT
108
109DWORD CALLBACK wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb);
110
111#endif // wxUSE_RICHEDIT
112
b12915c1
VZ
113// ----------------------------------------------------------------------------
114// private classes
115// ----------------------------------------------------------------------------
116
117#if wxUSE_RICHEDIT
118
a5aa8086 119// this module initializes RichEdit DLL(s) if needed
b12915c1
VZ
120class wxRichEditModule : public wxModule
121{
122public:
123 virtual bool OnInit();
124 virtual void OnExit();
125
b12915c1
VZ
126 // load the richedit DLL of at least of required version
127 static bool Load(int version = 1);
128
129private:
a5aa8086
VZ
130 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
131 static HINSTANCE ms_hRichEdit[2];
b12915c1
VZ
132
133 DECLARE_DYNAMIC_CLASS(wxRichEditModule)
134};
135
a5aa8086 136HINSTANCE wxRichEditModule::ms_hRichEdit[2] = { NULL, NULL };
b12915c1
VZ
137
138IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule, wxModule)
139
140#endif // wxUSE_RICHEDIT
e702ff0f 141
a1b82138
VZ
142// ----------------------------------------------------------------------------
143// event tables and other macros
144// ----------------------------------------------------------------------------
145
2bda0e17
KB
146IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
147
148BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
a1b82138
VZ
149 EVT_CHAR(wxTextCtrl::OnChar)
150 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
151
152 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
153 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
154 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
155 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
156 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
157
158 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
159 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
160 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
161 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
162 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
f6bcfd97
BP
163#ifdef __WIN16__
164 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground)
165#endif
2bda0e17 166END_EVENT_TABLE()
e702ff0f 167
a1b82138
VZ
168// ============================================================================
169// implementation
170// ============================================================================
171
172// ----------------------------------------------------------------------------
173// creation
174// ----------------------------------------------------------------------------
175
aac7e7fe 176void wxTextCtrl::Init()
2bda0e17 177{
cd471848 178#if wxUSE_RICHEDIT
aac7e7fe 179 m_verRichEdit = 0;
cd471848 180#endif
2bda0e17
KB
181}
182
debe6624 183bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
c085e333
VZ
184 const wxString& value,
185 const wxPoint& pos,
a1b82138
VZ
186 const wxSize& size,
187 long style,
c085e333
VZ
188 const wxValidator& validator,
189 const wxString& name)
2bda0e17 190{
a1b82138 191 // base initialization
8d99be5f 192 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
a1b82138 193 return FALSE;
2bda0e17 194
a1b82138
VZ
195 if ( parent )
196 parent->AddChild(this);
2bda0e17 197
b2d5a7ee
VZ
198 // translate wxWin style flags to MSW ones
199 WXDWORD msStyle = MSWGetCreateWindowFlags();
cfdd3a98 200
a1b82138 201 // do create the control - either an EDIT or RICHEDIT
b12915c1 202 wxString windowClass = wxT("EDIT");
cd471848 203
57c208c5 204#if wxUSE_RICHEDIT
a5aa8086
VZ
205 if ( m_windowStyle & wxTE_AUTO_URL )
206 {
207 // automatic URL detection only works in RichEdit 2.0+
208 m_windowStyle |= wxTE_RICH2;
209 }
210
211 if ( m_windowStyle & wxTE_RICH2 )
212 {
213 // using richedit 2.0 implies using wxTE_RICH
214 m_windowStyle |= wxTE_RICH;
215 }
216
217 // we need to load the richedit DLL before creating the rich edit control
c49245f8 218 if ( m_windowStyle & wxTE_RICH )
a1b82138 219 {
a5aa8086
VZ
220 static bool s_errorGiven = FALSE;// MT-FIXME
221
222 // Which version do we need? Use 1.0 by default because it is much more
223 // like the the standard EDIT or 2.0 if explicitly requested, but use
224 // only 2.0 in Unicode mode as 1.0 doesn't support Unicode at all
225 //
226 // TODO: RichEdit 3.0 is apparently capable of emulating RichEdit 1.0
227 // (and thus EDIT) much better than RichEdit 2.0 so we probably
228 // should use 3.0 if available as it is the best of both worlds -
229 // but as I can't test it right now I don't do it (VZ)
230#if wxUSE_UNICODE
231 const int verRichEdit = 2;
232#else // !wxUSE_UNICODE
233 int verRichEdit = m_windowStyle & wxTE_RICH2 ? 2 : 1;
234#endif // wxUSE_UNICODE/!wxUSE_UNICODE
0d0512bd
VZ
235
236 // only give the error msg once if the DLL can't be loaded
237 if ( !s_errorGiven )
238 {
a5aa8086
VZ
239 // try to load the RichEdit DLL (will do nothing if already done)
240 if ( !wxRichEditModule::Load(verRichEdit) )
0d0512bd 241 {
a5aa8086
VZ
242#if !wxUSE_UNICODE
243 // try another version?
244 verRichEdit = 3 - verRichEdit; // 1 <-> 2
245
246 if ( !wxRichEditModule::Load(verRichEdit) )
247#endif // wxUSE_UNICODE
248 {
249 wxLogError(_("Impossible to create a rich edit control, using simple text control instead. Please reinstall riched32.dll"));
0d0512bd 250
a5aa8086
VZ
251 s_errorGiven = TRUE;
252 }
0d0512bd
VZ
253 }
254 }
255
a5aa8086 256 // have we managed to load any richedit version?
aac7e7fe 257 if ( !s_errorGiven )
0d0512bd
VZ
258 {
259 msStyle |= ES_AUTOVSCROLL;
aac7e7fe 260
a5aa8086 261 m_verRichEdit = verRichEdit;
aac7e7fe 262 if ( m_verRichEdit == 1 )
b12915c1
VZ
263 {
264 windowClass = wxT("RICHEDIT");
265 }
266 else
267 {
268#ifndef RICHEDIT_CLASS
269 wxString RICHEDIT_CLASS;
aac7e7fe 270 RICHEDIT_CLASS.Printf(_T("RichEdit%d0"), m_verRichEdit);
5fb2f4ba 271#if wxUSE_UNICODE
b12915c1
VZ
272 RICHEDIT_CLASS += _T('W');
273#else // ANSI
274 RICHEDIT_CLASS += _T('A');
275#endif // Unicode/ANSI
276#endif // !RICHEDIT_CLASS
277
278 windowClass = RICHEDIT_CLASS;
279 }
0d0512bd 280 }
a1b82138 281 }
b12915c1 282#endif // wxUSE_RICHEDIT
2bda0e17 283
c8b204e6
VZ
284 // we need to turn '\n's into "\r\n"s for the multiline controls
285 wxString valueWin;
286 if ( m_windowStyle & wxTE_MULTILINE )
287 {
288 valueWin = wxTextFile::Translate(value, wxTextFileType_Dos);
289 }
290 else // single line
291 {
292 valueWin = value;
293 }
294
295 if ( !MSWCreateControl(windowClass, msStyle, pos, size, valueWin) )
7da982c4 296 return FALSE;
2bda0e17 297
a756f210 298 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
86f14582 299
57c208c5 300#if wxUSE_RICHEDIT
aac7e7fe 301 if ( IsRich() )
a1b82138 302 {
1dae1d00
VZ
303 // enable the events we're interested in: we want to get EN_CHANGE and
304 // EN_UPDATE as for the normal controls
305 LPARAM mask = ENM_CHANGE | ENM_UPDATE;
c57e3339 306
1dae1d00
VZ
307 if ( GetRichVersion() == 1 )
308 {
309 // we also need EN_MSGFILTER for richedit 1.0 for the reasons
310 // explained in its handler
311 mask |= ENM_MOUSEEVENTS;
312 }
313 else if ( m_windowStyle & wxTE_AUTO_URL )
c57e3339
VZ
314 {
315 mask |= ENM_LINK;
316
317 ::SendMessage(GetHwnd(), EM_AUTOURLDETECT, TRUE, 0);
318 }
319
320 ::SendMessage(GetHwnd(), EM_SETEVENTMASK, 0, mask);
a1b82138 321 }
c57e3339 322#endif // wxUSE_RICHEDIT
2bda0e17 323
a1b82138 324 return TRUE;
2bda0e17
KB
325}
326
327// Make sure the window style (etc.) reflects the HWND style (roughly)
cd471848 328void wxTextCtrl::AdoptAttributesFromHWND()
2bda0e17 329{
aac7e7fe 330 wxWindow::AdoptAttributesFromHWND();
2bda0e17 331
aac7e7fe
VZ
332 HWND hWnd = GetHwnd();
333 long style = ::GetWindowLong(hWnd, GWL_STYLE);
2bda0e17 334
aac7e7fe 335 // retrieve the style to see whether this is an edit or richedit ctrl
cd471848 336#if wxUSE_RICHEDIT
aac7e7fe 337 wxString classname = wxGetWindowClass(GetHWND());
2bda0e17 338
aac7e7fe
VZ
339 if ( classname.IsSameAs(_T("EDIT"), FALSE /* no case */) )
340 {
341 m_verRichEdit = 0;
342 }
343 else // rich edit?
344 {
345 wxChar c;
346 if ( wxSscanf(classname, _T("RichEdit%d0%c"), &m_verRichEdit, &c) != 2 )
347 {
348 wxLogDebug(_T("Unknown edit control '%s'."), classname.c_str());
2bda0e17 349
aac7e7fe
VZ
350 m_verRichEdit = 0;
351 }
352 }
a1b82138 353#endif // wxUSE_RICHEDIT
c085e333 354
aac7e7fe
VZ
355 if (style & ES_MULTILINE)
356 m_windowStyle |= wxTE_MULTILINE;
357 if (style & ES_PASSWORD)
358 m_windowStyle |= wxTE_PASSWORD;
359 if (style & ES_READONLY)
360 m_windowStyle |= wxTE_READONLY;
361 if (style & ES_WANTRETURN)
362 m_windowStyle |= wxTE_PROCESS_ENTER;
2bda0e17
KB
363}
364
b2d5a7ee
VZ
365WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const
366{
3a01bb1b
VZ
367 // default border for the text controls is the sunken one
368 if ( (style & wxBORDER_MASK) == wxBORDER_DEFAULT )
369 {
370 style |= wxBORDER_SUNKEN;
371 }
372
b2d5a7ee
VZ
373 long msStyle = wxControl::MSWGetStyle(style, exstyle);
374
375 // default styles
5b2f31eb 376 msStyle |= ES_LEFT;
b2d5a7ee
VZ
377
378 if ( style & wxTE_MULTILINE )
379 {
380 wxASSERT_MSG( !(style & wxTE_PROCESS_ENTER),
381 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
382
383 msStyle |= ES_MULTILINE | ES_WANTRETURN;
384 if ( !(style & wxTE_NO_VSCROLL) )
385 msStyle |= WS_VSCROLL;
386
387 style |= wxTE_PROCESS_ENTER;
388 }
389 else // !multiline
390 {
391 // there is really no reason to not have this style for single line
392 // text controls
393 msStyle |= ES_AUTOHSCROLL;
394 }
395
396 if ( style & wxHSCROLL )
397 msStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
398
399 if ( style & wxTE_READONLY )
400 msStyle |= ES_READONLY;
401
402 if ( style & wxTE_PASSWORD )
403 msStyle |= ES_PASSWORD;
404
405 if ( style & wxTE_AUTO_SCROLL )
406 msStyle |= ES_AUTOHSCROLL;
407
408 if ( style & wxTE_NOHIDESEL )
409 msStyle |= ES_NOHIDESEL;
410
411 return msStyle;
412}
413
414void wxTextCtrl::SetWindowStyleFlag(long style)
415{
416#if wxUSE_RICHEDIT
417 // we have to deal with some styles separately because they can't be
418 // changed by simply calling SetWindowLong(GWL_STYLE) but can be changed
419 // using richedit-specific EM_SETOPTIONS
420 if ( IsRich() &&
421 ((style & wxTE_NOHIDESEL) != (GetWindowStyle() & wxTE_NOHIDESEL)) )
422 {
423 bool set = (style & wxTE_NOHIDESEL) != 0;
424
425 ::SendMessage(GetHwnd(), EM_SETOPTIONS, set ? ECOOP_OR : ECOOP_AND,
426 set ? ECO_NOHIDESEL : ~ECO_NOHIDESEL);
427 }
428#endif // wxUSE_RICHEDIT
429
430 wxControl::SetWindowStyleFlag(style);
431}
432
a1b82138
VZ
433// ----------------------------------------------------------------------------
434// set/get the controls text
435// ----------------------------------------------------------------------------
436
cd471848 437wxString wxTextCtrl::GetValue() const
2bda0e17 438{
a5aa8086
VZ
439 // range 0..-1 is special for GetRange() and means to retrieve all text
440 return GetRange(0, -1);
441}
442
443wxString wxTextCtrl::GetRange(long from, long to) const
444{
445 wxString str;
446
447 if ( from >= to && to != -1 )
448 {
449 // nothing to retrieve
450 return str;
451 }
452
b12915c1 453#if wxUSE_RICHEDIT
aac7e7fe 454 if ( IsRich() )
b12915c1 455 {
3988b155 456 int len = GetWindowTextLength(GetHwnd());
a5aa8086 457 if ( len > from )
3988b155
VZ
458 {
459 // alloc one extra WORD as needed by the control
460 wxChar *p = str.GetWriteBuf(++len);
b12915c1 461
3988b155 462 TEXTRANGE textRange;
a5aa8086
VZ
463 textRange.chrg.cpMin = from;
464 textRange.chrg.cpMax = to == -1 ? len : to;
3988b155 465 textRange.lpstrText = p;
b12915c1 466
3988b155 467 (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
b12915c1 468
a5aa8086 469 if ( m_verRichEdit > 1 )
3988b155 470 {
a5aa8086
VZ
471 // RichEdit 2.0 uses just CR ('\r') for the newlines which is
472 // neither Unix nor Windows style - convert it to something
473 // reasonable
474 for ( ; *p; p++ )
475 {
476 if ( *p == _T('\r') )
477 *p = _T('\n');
478 }
3988b155
VZ
479 }
480
481 str.UngetWriteBuf();
a5aa8086
VZ
482
483 if ( m_verRichEdit == 1 )
484 {
485 // convert to the canonical form - see comment below
486 str = wxTextFile::Translate(str, wxTextFileType_Unix);
487 }
3988b155
VZ
488 }
489 //else: no text at all, leave the string empty
b12915c1 490 }
a5aa8086 491 else
b12915c1 492#endif // wxUSE_RICHEDIT
a5aa8086
VZ
493 {
494 // retrieve all text
495 str = wxGetWindowText(GetHWND());
b12915c1 496
a5aa8086
VZ
497 // need only a range?
498 if ( from < to )
499 {
500 str = str.Mid(from, to - from);
501 }
502
503 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
504 // canonical one (same one as above) for consistency with the other kinds
505 // of controls and, more importantly, with the other ports
506 str = wxTextFile::Translate(str, wxTextFileType_Unix);
507 }
b12915c1 508
a5aa8086 509 return str;
2bda0e17
KB
510}
511
512void wxTextCtrl::SetValue(const wxString& value)
513{
b12915c1
VZ
514 // if the text is long enough, it's faster to just set it instead of first
515 // comparing it with the old one (chances are that it will be different
516 // anyhow, this comparison is there to avoid flicker for small single-line
517 // edit controls mostly)
518 if ( (value.length() > 0x400) || (value != GetValue()) )
07cf98cb 519 {
79d26b32 520 DoWriteText(value, FALSE /* not selection only */);
af01f1ba 521
104d7404
VZ
522 // mark the control as being not dirty - we changed its text, not the
523 // user
524 DiscardEdits();
525
af01f1ba
VZ
526 // for compatibility, don't move the cursor when doing SetValue()
527 SetInsertionPoint(0);
aac7e7fe
VZ
528 }
529}
a1b82138 530
0b8e5844 531#if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
f6bcfd97 532
aac7e7fe
VZ
533DWORD CALLBACK wxRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb)
534{
535 *pcb = 0;
f6bcfd97 536
aac7e7fe
VZ
537 wchar_t *wbuf = (wchar_t *)buf;
538 const wchar_t *wpc = *(const wchar_t **)dwCookie;
539 while ( cb && *wpc )
540 {
541 *wbuf++ = *wpc++;
542
543 cb -= sizeof(wchar_t);
544 (*pcb) += sizeof(wchar_t);
07cf98cb 545 }
aac7e7fe
VZ
546
547 *(const wchar_t **)dwCookie = wpc;
548
549 return 0;
2bda0e17
KB
550}
551
373658eb 552extern long wxEncodingToCodepage(wxFontEncoding encoding); // from utils.cpp
aac7e7fe 553
0b8e5844 554#if wxUSE_UNICODE_MSLU
79d26b32
VZ
555bool wxTextCtrl::StreamIn(const wxString& value,
556 wxFontEncoding WXUNUSED(encoding),
557 bool selectionOnly)
0b8e5844
VS
558{
559 const wchar_t *wpc = value.c_str();
79d26b32
VZ
560#else // !wxUSE_UNICODE_MSLU
561bool wxTextCtrl::StreamIn(const wxString& value,
562 wxFontEncoding encoding,
563 bool selectionOnly)
aac7e7fe
VZ
564{
565 // we have to use EM_STREAMIN to force richedit control 2.0+ to show any
566 // text in the non default charset - otherwise it thinks it knows better
567 // than we do and always shows it in the default one
568
569 // first get the Windows code page for this encoding
570 long codepage = wxEncodingToCodepage(encoding);
571 if ( codepage == -1 )
572 {
573 // unknown encoding
574 return FALSE;
575 }
576
577 // next translate to Unicode using this code page
578 int len = ::MultiByteToWideChar(codepage, 0, value, -1, NULL, 0);
855d6be7
VZ
579
580#if wxUSE_WCHAR_T
aac7e7fe 581 wxWCharBuffer wchBuf(len);
855d6be7
VZ
582#else
583 wchar_t *wchBuf = (wchar_t *)malloc((len + 1)*sizeof(wchar_t));
584#endif
585
aac7e7fe 586 if ( !::MultiByteToWideChar(codepage, 0, value, -1,
855d6be7 587 (wchar_t *)(const wchar_t *)wchBuf, len) )
aac7e7fe
VZ
588 {
589 wxLogLastError(_T("MultiByteToWideChar"));
590 }
591
592 // finally, stream it in the control
593 const wchar_t *wpc = wchBuf;
0b8e5844 594#endif // wxUSE_UNICODE_MSLU
aac7e7fe
VZ
595
596 EDITSTREAM eds;
597 wxZeroMemory(eds);
598 eds.dwCookie = (DWORD)&wpc;
7a25a27c
VZ
599 // the cast below is needed for broken (very) old mingw32 headers
600 eds.pfnCallback = (EDITSTREAMCALLBACK)wxRichEditStreamIn;
92209a39 601
aac7e7fe 602 if ( !::SendMessage(GetHwnd(), EM_STREAMIN,
79d26b32
VZ
603 SF_TEXT |
604 SF_UNICODE |
605 (selectionOnly ? SFF_SELECTION : 0),
aac7e7fe
VZ
606 (LPARAM)&eds) || eds.dwError )
607 {
608 wxLogLastError(_T("EM_STREAMIN"));
aac7e7fe
VZ
609 }
610
855d6be7
VZ
611#if !wxUSE_WCHAR_T
612 free(wchBuf);
613#endif // !wxUSE_WCHAR_T
614
aac7e7fe
VZ
615 return TRUE;
616}
617
618#endif // wxUSE_RICHEDIT
619
a1b82138 620void wxTextCtrl::WriteText(const wxString& value)
79d26b32
VZ
621{
622 DoWriteText(value);
623}
624
625void wxTextCtrl::DoWriteText(const wxString& value, bool selectionOnly)
2bda0e17 626{
a5aa8086
VZ
627 wxString valueDos;
628 if ( m_windowStyle & wxTE_MULTILINE )
629 valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
630 else
631 valueDos = value;
2bda0e17 632
4bc1afd5 633#if wxUSE_RICHEDIT
aac7e7fe
VZ
634 // there are several complications with the rich edit controls here
635 bool done = FALSE;
636 if ( IsRich() )
4bc1afd5 637 {
aac7e7fe
VZ
638 // first, ensure that the new text will be in the default style
639 if ( !m_defaultStyle.IsDefault() )
640 {
641 long start, end;
642 GetSelection(&start, &end);
0b8e5844
VS
643 SetStyle(start, end, m_defaultStyle);
644 }
645
646#if wxUSE_UNICODE_MSLU
647 // RichEdit doesn't have Unicode version of EM_REPLACESEL on Win9x,
648 // but EM_STREAMIN works
136cb3c7 649 if ( wxUsingUnicowsDll() && GetRichVersion() > 1 )
0b8e5844 650 {
79d26b32 651 done = StreamIn(valueDos, wxFONTENCODING_SYSTEM, selectionOnly);
aac7e7fe 652 }
0b8e5844 653#endif // wxUSE_UNICODE_MSLU
aac7e7fe 654
9d7de3c2 655#if !wxUSE_UNICODE
aac7e7fe
VZ
656 // next check if the text we're inserting must be shown in a non
657 // default charset -- this only works for RichEdit > 1.0
658 if ( GetRichVersion() > 1 )
659 {
660 wxFont font = m_defaultStyle.GetFont();
661 if ( !font.Ok() )
662 font = GetFont();
663
664 if ( font.Ok() )
665 {
666 wxFontEncoding encoding = font.GetEncoding();
667 if ( encoding != wxFONTENCODING_SYSTEM )
668 {
79d26b32 669 done = StreamIn(valueDos, encoding, selectionOnly);
aac7e7fe
VZ
670 }
671 }
672 }
9d7de3c2 673#endif // !wxUSE_UNICODE
4bc1afd5 674 }
4bc1afd5 675
aac7e7fe
VZ
676 if ( !done )
677#endif // wxUSE_RICHEDIT
678 {
79d26b32
VZ
679 if ( !selectionOnly )
680 {
681 SetSelection(-1, -1);
682 }
683
aac7e7fe
VZ
684 ::SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)valueDos.c_str());
685 }
2bda0e17 686
a1b82138 687 AdjustSpaceLimit();
2bda0e17
KB
688}
689
a1b82138
VZ
690void wxTextCtrl::AppendText(const wxString& text)
691{
692 SetInsertionPointEnd();
aac7e7fe 693
a1b82138
VZ
694 WriteText(text);
695}
696
697void wxTextCtrl::Clear()
698{
aac7e7fe 699 ::SetWindowText(GetHwnd(), wxT(""));
a1b82138
VZ
700}
701
94af7d45
VZ
702#ifdef __WIN32__
703
704bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent& event)
705{
706 SetFocus();
707
708 size_t lenOld = GetValue().length();
709
710 wxUint32 code = event.GetRawKeyCode();
566d84a7
RL
711 ::keybd_event(code, 0, 0 /* key press */, 0);
712 ::keybd_event(code, 0, KEYEVENTF_KEYUP, 0);
94af7d45
VZ
713
714 // assume that any alphanumeric key changes the total number of characters
715 // in the control - this should work in 99% of cases
716 return GetValue().length() != lenOld;
717}
718
719#endif // __WIN32__
720
a1b82138 721// ----------------------------------------------------------------------------
2bda0e17 722// Clipboard operations
a1b82138
VZ
723// ----------------------------------------------------------------------------
724
cd471848 725void wxTextCtrl::Copy()
2bda0e17 726{
e702ff0f
JS
727 if (CanCopy())
728 {
a5aa8086 729 ::SendMessage(GetHwnd(), WM_COPY, 0, 0L);
e702ff0f 730 }
2bda0e17
KB
731}
732
cd471848 733void wxTextCtrl::Cut()
2bda0e17 734{
e702ff0f
JS
735 if (CanCut())
736 {
a5aa8086 737 ::SendMessage(GetHwnd(), WM_CUT, 0, 0L);
e702ff0f 738 }
2bda0e17
KB
739}
740
cd471848 741void wxTextCtrl::Paste()
2bda0e17 742{
e702ff0f
JS
743 if (CanPaste())
744 {
a5aa8086 745 ::SendMessage(GetHwnd(), WM_PASTE, 0, 0L);
e702ff0f 746 }
2bda0e17
KB
747}
748
a1b82138
VZ
749bool wxTextCtrl::CanCopy() const
750{
751 // Can copy if there's a selection
752 long from, to;
a5aa8086
VZ
753 GetSelection(&from, &to);
754 return from != to;
a1b82138
VZ
755}
756
757bool wxTextCtrl::CanCut() const
758{
a5aa8086 759 return CanCopy() && IsEditable();
a1b82138
VZ
760}
761
762bool wxTextCtrl::CanPaste() const
763{
aac7e7fe
VZ
764 if ( !IsEditable() )
765 return FALSE;
766
a1b82138 767#if wxUSE_RICHEDIT
aac7e7fe 768 if ( IsRich() )
a1b82138 769 {
aac7e7fe
VZ
770 UINT cf = 0; // 0 == any format
771
772 return ::SendMessage(GetHwnd(), EM_CANPASTE, cf, 0) != 0;
a1b82138 773 }
aac7e7fe 774#endif // wxUSE_RICHEDIT
a1b82138
VZ
775
776 // Standard edit control: check for straight text on clipboard
aac7e7fe
VZ
777 if ( !::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
778 return FALSE;
779
780 bool isTextAvailable = ::IsClipboardFormatAvailable(CF_TEXT) != 0;
781 ::CloseClipboard();
a1b82138
VZ
782
783 return isTextAvailable;
784}
785
786// ----------------------------------------------------------------------------
787// Accessors
788// ----------------------------------------------------------------------------
789
debe6624 790void wxTextCtrl::SetEditable(bool editable)
2bda0e17 791{
a1b82138
VZ
792 HWND hWnd = GetHwnd();
793 SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
2bda0e17
KB
794}
795
debe6624 796void wxTextCtrl::SetInsertionPoint(long pos)
2bda0e17 797{
a5aa8086 798 DoSetSelection(pos, pos);
2bda0e17
KB
799}
800
cd471848 801void wxTextCtrl::SetInsertionPointEnd()
2bda0e17 802{
a5aa8086
VZ
803 long pos;
804
805#if wxUSE_RICHEDIT
806 if ( m_verRichEdit == 1 )
807 {
808 // we don't have to waste time calling GetLastPosition() in this case
809 pos = -1;
810 }
811 else // !RichEdit 1.0
812#endif // wxUSE_RICHEDIT
813 {
814 pos = GetLastPosition();
815 }
816
a1b82138 817 SetInsertionPoint(pos);
2bda0e17
KB
818}
819
cd471848 820long wxTextCtrl::GetInsertionPoint() const
2bda0e17 821{
57c208c5 822#if wxUSE_RICHEDIT
aac7e7fe 823 if ( IsRich() )
a1b82138
VZ
824 {
825 CHARRANGE range;
826 range.cpMin = 0;
827 range.cpMax = 0;
828 SendMessage(GetHwnd(), EM_EXGETSEL, 0, (LPARAM) &range);
829 return range.cpMin;
830 }
aac7e7fe 831#endif // wxUSE_RICHEDIT
2bda0e17 832
a1b82138
VZ
833 DWORD Pos = (DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
834 return Pos & 0xFFFF;
2bda0e17
KB
835}
836
cd471848 837long wxTextCtrl::GetLastPosition() const
2bda0e17 838{
a5aa8086
VZ
839 int numLines = GetNumberOfLines();
840 long posStartLastLine = XYToPosition(0, numLines - 1);
39136494 841
a5aa8086 842 long lenLastLine = GetLengthOfLineContainingPos(posStartLastLine);
2bda0e17 843
a5aa8086 844 return posStartLastLine + lenLastLine;
2bda0e17
KB
845}
846
a1b82138
VZ
847// If the return values from and to are the same, there is no
848// selection.
849void wxTextCtrl::GetSelection(long* from, long* to) const
850{
851#if wxUSE_RICHEDIT
aac7e7fe 852 if ( IsRich() )
a1b82138
VZ
853 {
854 CHARRANGE charRange;
aac7e7fe 855 ::SendMessage(GetHwnd(), EM_EXGETSEL, 0, (LPARAM) &charRange);
a1b82138
VZ
856
857 *from = charRange.cpMin;
858 *to = charRange.cpMax;
a1b82138 859 }
4bc1afd5 860 else
aac7e7fe 861#endif // !wxUSE_RICHEDIT
4bc1afd5
VZ
862 {
863 DWORD dwStart, dwEnd;
aac7e7fe 864 ::SendMessage(GetHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
a1b82138 865
4bc1afd5
VZ
866 *from = dwStart;
867 *to = dwEnd;
868 }
a1b82138
VZ
869}
870
871bool wxTextCtrl::IsEditable() const
872{
51c14c62
VZ
873 // strangely enough, we may be called before the control is created: our
874 // own Create() calls MSWGetStyle() which calls AcceptsFocus() which calls
875 // us
876 if ( !m_hWnd )
877 return TRUE;
878
a1b82138
VZ
879 long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
880
a5aa8086 881 return (style & ES_READONLY) == 0;
a1b82138
VZ
882}
883
884// ----------------------------------------------------------------------------
aac7e7fe 885// selection
a1b82138
VZ
886// ----------------------------------------------------------------------------
887
aac7e7fe 888void wxTextCtrl::SetSelection(long from, long to)
2bda0e17 889{
aac7e7fe
VZ
890 // if from and to are both -1, it means (in wxWindows) that all text should
891 // be selected - translate into Windows convention
892 if ( (from == -1) && (to == -1) )
893 {
894 from = 0;
895 to = -1;
896 }
897
a5aa8086
VZ
898 DoSetSelection(from, to);
899}
900
901void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret)
902{
789295bf 903 HWND hWnd = GetHwnd();
39136494 904
2bda0e17 905#ifdef __WIN32__
aac7e7fe
VZ
906#if wxUSE_RICHEDIT
907 if ( IsRich() )
908 {
909 CHARRANGE range;
910 range.cpMin = from;
911 range.cpMax = to;
912 SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM) &range);
913 }
914 else
915#endif // wxUSE_RICHEDIT
916 {
917 SendMessage(hWnd, EM_SETSEL, (WPARAM)from, (LPARAM)to);
918 }
a1b82138 919
aac7e7fe 920 if ( scrollCaret )
2bda0e17 921 {
aac7e7fe 922 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
2bda0e17 923 }
aac7e7fe
VZ
924#else // Win16
925 // WPARAM is 0: selection is scrolled into view
926 SendMessage(hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)MAKELONG(from, to));
927#endif // Win32/16
928}
929
930// ----------------------------------------------------------------------------
931// Editing
932// ----------------------------------------------------------------------------
39136494 933
aac7e7fe
VZ
934void wxTextCtrl::Replace(long from, long to, const wxString& value)
935{
936 // Set selection and remove it
f882d57e 937 DoSetSelection(from, to, FALSE /* don't scroll caret into view */);
aac7e7fe
VZ
938
939 SendMessage(GetHwnd(), EM_REPLACESEL,
2bda0e17 940#ifdef __WIN32__
aac7e7fe 941 TRUE,
2bda0e17 942#else
aac7e7fe 943 FALSE,
2bda0e17 944#endif
aac7e7fe
VZ
945 (LPARAM)value.c_str());
946}
947
948void wxTextCtrl::Remove(long from, long to)
949{
950 Replace(from, to, _T(""));
2bda0e17
KB
951}
952
953bool wxTextCtrl::LoadFile(const wxString& file)
954{
a1b82138 955 if ( wxTextCtrlBase::LoadFile(file) )
cd471848 956 {
a1b82138
VZ
957 // update the size limit if needed
958 AdjustSpaceLimit();
2bda0e17 959
a1b82138 960 return TRUE;
2bda0e17 961 }
2bda0e17 962
a1b82138 963 return FALSE;
2bda0e17
KB
964}
965
cd471848 966bool wxTextCtrl::IsModified() const
2bda0e17 967{
a5aa8086 968 return SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0;
2bda0e17
KB
969}
970
971// Makes 'unmodified'
cd471848 972void wxTextCtrl::DiscardEdits()
2bda0e17 973{
a1b82138 974 SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L);
2bda0e17
KB
975}
976
cd471848 977int wxTextCtrl::GetNumberOfLines() const
2bda0e17 978{
789295bf 979 return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
2bda0e17
KB
980}
981
debe6624 982long wxTextCtrl::XYToPosition(long x, long y) const
2bda0e17 983{
2bda0e17 984 // This gets the char index for the _beginning_ of this line
a5aa8086
VZ
985 long charIndex = SendMessage(GetHwnd(), EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
986
987 return charIndex + x;
2bda0e17
KB
988}
989
0efe5ba7 990bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
2bda0e17 991{
789295bf 992 HWND hWnd = GetHwnd();
2bda0e17
KB
993
994 // This gets the line number containing the character
a5aa8086 995 long lineNo;
0efe5ba7 996#if wxUSE_RICHEDIT
aac7e7fe 997 if ( IsRich() )
0efe5ba7 998 {
a5aa8086 999 lineNo = SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, (LPARAM)pos);
0efe5ba7
VZ
1000 }
1001 else
1002#endif // wxUSE_RICHEDIT
a5aa8086
VZ
1003 {
1004 lineNo = SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
1005 }
0efe5ba7
VZ
1006
1007 if ( lineNo == -1 )
1008 {
1009 // no such line
1010 return FALSE;
1011 }
1012
2bda0e17 1013 // This gets the char index for the _beginning_ of this line
a5aa8086 1014 long charIndex = SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
0efe5ba7
VZ
1015 if ( charIndex == -1 )
1016 {
1017 return FALSE;
1018 }
1019
2bda0e17 1020 // The X position must therefore be the different between pos and charIndex
0efe5ba7 1021 if ( x )
a5aa8086 1022 *x = pos - charIndex;
0efe5ba7 1023 if ( y )
a5aa8086 1024 *y = lineNo;
0efe5ba7
VZ
1025
1026 return TRUE;
2bda0e17
KB
1027}
1028
debe6624 1029void wxTextCtrl::ShowPosition(long pos)
2bda0e17 1030{
789295bf 1031 HWND hWnd = GetHwnd();
2bda0e17
KB
1032
1033 // To scroll to a position, we pass the number of lines and characters
1034 // to scroll *by*. This means that we need to:
1035 // (1) Find the line position of the current line.
1036 // (2) Find the line position of pos.
1037 // (3) Scroll by (pos - current).
1038 // For now, ignore the horizontal scrolling.
1039
1040 // Is this where scrolling is relative to - the line containing the caret?
1041 // Or is the first visible line??? Try first visible line.
1042// int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
1043
1044 int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
1045
1046 int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
39136494 1047
2bda0e17
KB
1048 int linesToScroll = specifiedLineLineNo - currentLineLineNo;
1049
2bda0e17 1050 if (linesToScroll != 0)
de4d7713 1051 (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
2bda0e17
KB
1052}
1053
a5aa8086
VZ
1054long wxTextCtrl::GetLengthOfLineContainingPos(long pos) const
1055{
1056 return ::SendMessage(GetHwnd(), EM_LINELENGTH, (WPARAM)pos, 0);
1057}
1058
debe6624 1059int wxTextCtrl::GetLineLength(long lineNo) const
2bda0e17 1060{
a5aa8086
VZ
1061 long pos = XYToPosition(0, lineNo);
1062
1063 return GetLengthOfLineContainingPos(pos);
2bda0e17
KB
1064}
1065
debe6624 1066wxString wxTextCtrl::GetLineText(long lineNo) const
2bda0e17 1067{
a1b82138 1068 size_t len = (size_t)GetLineLength(lineNo) + 1;
488fe1fe 1069
f6bcfd97
BP
1070 // there must be at least enough place for the length WORD in the
1071 // buffer
1072 len += sizeof(WORD);
4438caf4 1073
f6bcfd97
BP
1074 wxString str;
1075 wxChar *buf = str.GetWriteBuf(len);
1076
33ac7e6f 1077 *(WORD *)buf = (WORD)len;
f6bcfd97
BP
1078 len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
1079 buf[len] = 0;
4438caf4 1080
f6bcfd97 1081 str.UngetWriteBuf(len);
4438caf4
VZ
1082
1083 return str;
2bda0e17
KB
1084}
1085
d7eee191
VZ
1086void wxTextCtrl::SetMaxLength(unsigned long len)
1087{
1088 ::SendMessage(GetHwnd(), EM_LIMITTEXT, len, 0);
1089}
1090
a1b82138 1091// ----------------------------------------------------------------------------
ca8b28f2 1092// Undo/redo
a1b82138
VZ
1093// ----------------------------------------------------------------------------
1094
ca8b28f2
JS
1095void wxTextCtrl::Undo()
1096{
1097 if (CanUndo())
1098 {
789295bf 1099 ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
ca8b28f2
JS
1100 }
1101}
1102
1103void wxTextCtrl::Redo()
1104{
1105 if (CanRedo())
1106 {
1107 // Same as Undo, since Undo undoes the undo, i.e. a redo.
789295bf 1108 ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
ca8b28f2
JS
1109 }
1110}
1111
1112bool wxTextCtrl::CanUndo() const
1113{
a5aa8086 1114 return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0;
ca8b28f2
JS
1115}
1116
1117bool wxTextCtrl::CanRedo() const
1118{
a5aa8086 1119 return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0;
ca8b28f2
JS
1120}
1121
a1b82138
VZ
1122// ----------------------------------------------------------------------------
1123// implemenation details
1124// ----------------------------------------------------------------------------
39136494 1125
2bda0e17
KB
1126void wxTextCtrl::Command(wxCommandEvent & event)
1127{
a1b82138
VZ
1128 SetValue(event.GetString());
1129 ProcessCommand (event);
2bda0e17
KB
1130}
1131
1132void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
1133{
a1b82138
VZ
1134 // By default, load the first file into the text window.
1135 if (event.GetNumberOfFiles() > 0)
1136 {
1137 LoadFile(event.GetFiles()[0]);
1138 }
2bda0e17
KB
1139}
1140
a37d422a
VZ
1141// ----------------------------------------------------------------------------
1142// kbd input processing
1143// ----------------------------------------------------------------------------
1144
1145bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg)
1146{
1147 MSG *msg = (MSG *)pMsg;
1148
1149 // check for our special keys here: if we don't do it and the parent frame
1150 // uses them as accelerators, they wouldn't work at all, so we disable
1151 // usual preprocessing for them
1152 if ( msg->message == WM_KEYDOWN )
1153 {
574c939e 1154 WORD vkey = (WORD) msg->wParam;
a37d422a
VZ
1155 if ( (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN )
1156 {
1157 if ( vkey == VK_BACK )
1158 return FALSE;
1159 }
1160 else // no Alt
1161 {
1162 if ( wxIsCtrlDown() )
1163 {
1164 switch ( vkey )
1165 {
1166 case 'C':
1167 case 'V':
1168 case 'X':
1169 case VK_INSERT:
1170 case VK_DELETE:
1171 case VK_HOME:
1172 case VK_END:
1173 return FALSE;
1174 }
1175 }
1176 else if ( wxIsShiftDown() )
1177 {
1178 if ( vkey == VK_INSERT || vkey == VK_DELETE )
1179 return FALSE;
1180 }
1181 }
1182 }
1183
1184 return wxControl::MSWShouldPreProcessMessage(pMsg);
1185}
1186
2bda0e17
KB
1187void wxTextCtrl::OnChar(wxKeyEvent& event)
1188{
42e69d6b 1189 switch ( event.KeyCode() )
cd471848 1190 {
cd471848 1191 case WXK_RETURN:
39136494 1192 if ( !(m_windowStyle & wxTE_MULTILINE) )
cd471848
VZ
1193 {
1194 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
bfbd6dc1 1195 InitCommandEvent(event);
f6bcfd97 1196 event.SetString(GetValue());
cd471848
VZ
1197 if ( GetEventHandler()->ProcessEvent(event) )
1198 return;
1199 }
5fb9fcfc
VZ
1200 //else: multiline controls need Enter for themselves
1201
1202 break;
4d91c1d1 1203
cd471848 1204 case WXK_TAB:
319fefa9
VZ
1205 // always produce navigation event - even if we process TAB
1206 // ourselves the fact that we got here means that the user code
1207 // decided to skip processing of this TAB - probably to let it
1208 // do its default job.
cd471848 1209 {
5fb9fcfc
VZ
1210 wxNavigationKeyEvent eventNav;
1211 eventNav.SetDirection(!event.ShiftDown());
8614c467 1212 eventNav.SetWindowChange(event.ControlDown());
5fb9fcfc 1213 eventNav.SetEventObject(this);
39136494 1214
d9506e77 1215 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
cd471848
VZ
1216 return;
1217 }
341c92a8 1218 break;
cd471848 1219 }
39136494 1220
8614c467 1221 // no, we didn't process it
42e69d6b 1222 event.Skip();
2bda0e17
KB
1223}
1224
0cf5b099
VZ
1225long wxTextCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1226{
e7e91e03
VZ
1227 long lRc = wxTextCtrlBase::MSWWindowProc(nMsg, wParam, lParam);
1228
0cf5b099
VZ
1229 if ( nMsg == WM_GETDLGCODE )
1230 {
1231 // we always want the chars and the arrows
1232 long lDlgCode = DLGC_WANTCHARS | DLGC_WANTARROWS;
1233
1234 // we may have several different cases:
1235 // 1. normal case: both TAB and ENTER are used for dialog navigation
2adfb497
VZ
1236 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the
1237 // next control in the dialog
1238 // 3. ctrl which wants ENTER for itself: TAB is used for dialog
1239 // navigation
1240 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass
1241 // to the next control
1242
1243 // the multiline edit control should always get <Return> for itself
1244 if ( HasFlag(wxTE_PROCESS_ENTER) || HasFlag(wxTE_MULTILINE) )
0cf5b099 1245 lDlgCode |= DLGC_WANTMESSAGE;
2adfb497
VZ
1246
1247 if ( HasFlag(wxTE_PROCESS_TAB) )
0cf5b099
VZ
1248 lDlgCode |= DLGC_WANTTAB;
1249
e7e91e03 1250 lRc |= lDlgCode;
0cf5b099
VZ
1251 }
1252
e7e91e03 1253 return lRc;
129223d6
VZ
1254}
1255
1256// ----------------------------------------------------------------------------
1257// text control event processing
1258// ----------------------------------------------------------------------------
1259
debe6624 1260bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
2bda0e17 1261{
789295bf
VZ
1262 switch (param)
1263 {
1264 case EN_SETFOCUS:
1265 case EN_KILLFOCUS:
1266 {
1267 wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
d7eee191
VZ
1268 : wxEVT_SET_FOCUS,
1269 m_windowId);
789295bf
VZ
1270 event.SetEventObject( this );
1271 GetEventHandler()->ProcessEvent(event);
1272 }
1273 break;
ae29de83 1274
789295bf
VZ
1275 case EN_CHANGE:
1276 {
1277 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
bfbd6dc1
VZ
1278 InitCommandEvent(event);
1279 event.SetString(GetValue());
1280 ProcessCommand(event);
789295bf
VZ
1281 }
1282 break;
2bda0e17 1283
b12915c1 1284 case EN_MAXTEXT:
789295bf 1285 // the text size limit has been hit - increase it
d7eee191
VZ
1286 if ( !AdjustSpaceLimit() )
1287 {
1288 wxCommandEvent event(wxEVT_COMMAND_TEXT_MAXLEN, m_windowId);
1289 InitCommandEvent(event);
1290 event.SetString(GetValue());
1291 ProcessCommand(event);
1292 }
789295bf
VZ
1293 break;
1294
1295 // the other notification messages are not processed
1296 case EN_UPDATE:
b12915c1 1297 case EN_ERRSPACE:
789295bf
VZ
1298 case EN_HSCROLL:
1299 case EN_VSCROLL:
f6bcfd97 1300 return FALSE;
1dae1d00 1301
789295bf
VZ
1302 default:
1303 return FALSE;
1304 }
1305
1306 // processed
1307 return TRUE;
2bda0e17
KB
1308}
1309
33ac7e6f 1310WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
788722ac
JS
1311#if wxUSE_CTL3D
1312 WXUINT message,
1313 WXWPARAM wParam,
1314 WXLPARAM lParam
1315#else
33ac7e6f
KB
1316 WXUINT WXUNUSED(message),
1317 WXWPARAM WXUNUSED(wParam),
788722ac
JS
1318 WXLPARAM WXUNUSED(lParam)
1319#endif
1320 )
f6bcfd97
BP
1321{
1322#if wxUSE_CTL3D
1323 if ( m_useCtl3D )
1324 {
1325 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
1326 return (WXHBRUSH) hbrush;
1327 }
1328#endif // wxUSE_CTL3D
1329
1330 HDC hdc = (HDC)pDC;
1331 if (GetParent()->GetTransparentBackground())
1332 SetBkMode(hdc, TRANSPARENT);
1333 else
1334 SetBkMode(hdc, OPAQUE);
1335
1336 wxColour colBack = GetBackgroundColour();
1337
1338 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE) == 0)
a756f210 1339 colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
f6bcfd97
BP
1340
1341 ::SetBkColor(hdc, wxColourToRGB(colBack));
1342 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
1343
1344 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
1345
1346 return (WXHBRUSH)brush->GetResourceHandle();
1347}
1348
1349// In WIN16, need to override normal erasing because
1350// Ctl3D doesn't use the wxWindows background colour.
1351#ifdef __WIN16__
1352void wxTextCtrl::OnEraseBackground(wxEraseEvent& event)
1353{
1354 wxColour col(m_backgroundColour);
1355
1356#if wxUSE_CTL3D
1357 if (m_useCtl3D)
a756f210 1358 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
f6bcfd97
BP
1359#endif
1360
1361 RECT rect;
1362 ::GetClientRect(GetHwnd(), &rect);
1363
a5aa8086 1364 COLORREF ref = wxColourToRGB(col);
f6bcfd97
BP
1365 HBRUSH hBrush = ::CreateSolidBrush(ref);
1366 if ( !hBrush )
1367 wxLogLastError(wxT("CreateSolidBrush"));
1368
1369 HDC hdc = (HDC)event.GetDC()->GetHDC();
1370
1371 int mode = ::SetMapMode(hdc, MM_TEXT);
1372
1373 ::FillRect(hdc, &rect, hBrush);
1374 ::DeleteObject(hBrush);
1375 ::SetMapMode(hdc, mode);
1376
1377}
aac7e7fe 1378#endif // Win16
f6bcfd97 1379
d7eee191 1380bool wxTextCtrl::AdjustSpaceLimit()
789295bf 1381{
25889d3c 1382#ifndef __WIN16__
d7eee191
VZ
1383 unsigned int limit = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
1384
1385 // HACK: we try to automatically extend the limit for the amount of text
1386 // to allow (interactively) entering more than 64Kb of text under
1387 // Win9x but we shouldn't reset the text limit which was previously
1388 // set explicitly with SetMaxLength()
1389 //
1390 // we could solve this by storing the limit we set in wxTextCtrl but
1391 // to save space we prefer to simply test here the actual limit
1392 // value: we consider that SetMaxLength() can only be called for
1393 // values < 32Kb
1394 if ( limit < 0x8000 )
1395 {
1396 // we've got more text than limit set by SetMaxLength()
1397 return FALSE;
1398 }
1399
1400 unsigned int len = ::GetWindowTextLength(GetHwnd());
17d8ee1c 1401 if ( len >= limit )
789295bf
VZ
1402 {
1403 limit = len + 0x8000; // 32Kb
1404
5ea105e0 1405#if wxUSE_RICHEDIT
aac7e7fe 1406 if ( IsRich() )
b12915c1
VZ
1407 {
1408 // as a nice side effect, this also allows passing limit > 64Kb
1409 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT, 0, limit);
1410 }
789295bf 1411 else
b12915c1
VZ
1412#endif // wxUSE_RICHEDIT
1413 {
1414 if ( limit > 0xffff )
1415 {
1416 // this will set it to a platform-dependent maximum (much more
1417 // than 64Kb under NT)
1418 limit = 0;
1419 }
1420
789295bf 1421 ::SendMessage(GetHwnd(), EM_LIMITTEXT, limit, 0);
b12915c1 1422 }
789295bf 1423 }
b12915c1 1424#endif // !Win16
d7eee191
VZ
1425
1426 // we changed the limit
1427 return TRUE;
789295bf 1428}
2bda0e17 1429
a1b82138 1430bool wxTextCtrl::AcceptsFocus() const
2bda0e17 1431{
a1b82138
VZ
1432 // we don't want focus if we can't be edited
1433 return IsEditable() && wxControl::AcceptsFocus();
1434}
c085e333 1435
f68586e5 1436wxSize wxTextCtrl::DoGetBestSize() const
a1b82138
VZ
1437{
1438 int cx, cy;
1439 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
1440
1441 int wText = DEFAULT_ITEM_WIDTH;
1442
1443 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
1444 if ( m_windowStyle & wxTE_MULTILINE )
1445 {
3988b155 1446 hText *= wxMax(GetNumberOfLines(), 5);
a1b82138
VZ
1447 }
1448 //else: for single line control everything is ok
1449
1450 return wxSize(wText, hText);
2bda0e17 1451}
a1b82138
VZ
1452
1453// ----------------------------------------------------------------------------
1454// standard handlers for standard edit menu events
1455// ----------------------------------------------------------------------------
2bda0e17 1456
bfbd6dc1 1457void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1458{
1459 Cut();
1460}
1461
bfbd6dc1 1462void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1463{
1464 Copy();
1465}
1466
bfbd6dc1 1467void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1468{
1469 Paste();
1470}
1471
bfbd6dc1 1472void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1473{
1474 Undo();
1475}
1476
bfbd6dc1 1477void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1478{
1479 Redo();
1480}
1481
1482void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
1483{
1484 event.Enable( CanCut() );
1485}
1486
1487void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
1488{
1489 event.Enable( CanCopy() );
1490}
1491
1492void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
1493{
1494 event.Enable( CanPaste() );
1495}
1496
1497void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
1498{
1499 event.Enable( CanUndo() );
1500}
1501
1502void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
1503{
1504 event.Enable( CanRedo() );
1505}
1506
4bc1afd5
VZ
1507// the rest of the file only deals with the rich edit controls
1508#if wxUSE_RICHEDIT
1509
c57e3339
VZ
1510// ----------------------------------------------------------------------------
1511// EN_LINK processing
1512// ----------------------------------------------------------------------------
1513
a64c3b74 1514bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
c57e3339
VZ
1515{
1516 NMHDR *hdr = (NMHDR* )lParam;
1dae1d00 1517 switch ( hdr->code )
c57e3339 1518 {
1dae1d00
VZ
1519 case EN_MSGFILTER:
1520 {
1521 const MSGFILTER *msgf = (MSGFILTER *)lParam;
1522 UINT msg = msgf->msg;
1523
1524 // this is a bit crazy but richedit 1.0 sends us all mouse
1525 // events _except_ WM_LBUTTONUP (don't ask me why) so we have
1526 // generate the wxWin events for this message manually
1527 //
1528 // NB: in fact, this is still not totally correct as it does
1529 // send us WM_LBUTTONUP if the selection was cleared by the
1530 // last click -- so currently we get 2 events in this case,
1531 // but as I don't see any obvious way to check for this I
1532 // leave this code in place because it's still better than
1533 // not getting left up events at all
1534 if ( msg == WM_LBUTTONUP )
c57e3339 1535 {
1dae1d00
VZ
1536 WXUINT flags = msgf->wParam;
1537 int x = GET_X_LPARAM(msgf->lParam),
1538 y = GET_Y_LPARAM(msgf->lParam);
1539
1540 HandleMouseEvent(msg, x, y, flags);
c57e3339 1541 }
1dae1d00 1542 }
c57e3339 1543
1dae1d00
VZ
1544 // return TRUE to process the event (and FALSE to ignore it)
1545 return TRUE;
1546
1547 case EN_LINK:
1548 {
1549 const ENLINK *enlink = (ENLINK *)hdr;
1550
1551 switch ( enlink->msg )
1552 {
1553 case WM_SETCURSOR:
1554 // ok, so it is hardcoded - do we really nee to
1555 // customize it?
1556 ::SetCursor(GetHcursorOf(wxCursor(wxCURSOR_HAND)));
1557 *result = TRUE;
1558 break;
1559
1560 case WM_MOUSEMOVE:
1561 case WM_LBUTTONDOWN:
1562 case WM_LBUTTONUP:
1563 case WM_LBUTTONDBLCLK:
1564 case WM_RBUTTONDOWN:
1565 case WM_RBUTTONUP:
1566 case WM_RBUTTONDBLCLK:
1567 // send a mouse event
1568 {
1569 static const wxEventType eventsMouse[] =
1570 {
1571 wxEVT_MOTION,
1572 wxEVT_LEFT_DOWN,
1573 wxEVT_LEFT_UP,
1574 wxEVT_LEFT_DCLICK,
1575 wxEVT_RIGHT_DOWN,
1576 wxEVT_RIGHT_UP,
1577 wxEVT_RIGHT_DCLICK,
1578 };
1579
1580 // the event ids are consecutive
1581 wxMouseEvent
1582 evtMouse(eventsMouse[enlink->msg - WM_MOUSEMOVE]);
1583
1584 InitMouseEvent(evtMouse,
1585 GET_X_LPARAM(enlink->lParam),
1586 GET_Y_LPARAM(enlink->lParam),
1587 enlink->wParam);
1588
1589 wxTextUrlEvent event(m_windowId, evtMouse,
1590 enlink->chrg.cpMin,
1591 enlink->chrg.cpMax);
1592
1593 InitCommandEvent(event);
1594
1595 *result = ProcessCommand(event);
1596 }
1597 break;
1598 }
1599 }
1600 return TRUE;
c57e3339
VZ
1601 }
1602
d86ab8e2
VZ
1603 // not processed, leave it to the base class
1604 return wxTextCtrlBase::MSWOnNotify(idCtrl, lParam, result);
c57e3339
VZ
1605}
1606
f6bcfd97
BP
1607// ----------------------------------------------------------------------------
1608// colour setting for the rich edit controls
1609// ----------------------------------------------------------------------------
1610
f6bcfd97
BP
1611bool wxTextCtrl::SetBackgroundColour(const wxColour& colour)
1612{
1613 if ( !wxTextCtrlBase::SetBackgroundColour(colour) )
1614 {
1615 // colour didn't really change
1616 return FALSE;
1617 }
1618
1619 if ( IsRich() )
1620 {
1621 // rich edit doesn't use WM_CTLCOLOR, hence we need to send
1622 // EM_SETBKGNDCOLOR additionally
1623 ::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR, 0, wxColourToRGB(colour));
1624 }
1625
1626 return TRUE;
1627}
1628
1629bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
1630{
1631 if ( !wxTextCtrlBase::SetForegroundColour(colour) )
1632 {
1633 // colour didn't really change
1634 return FALSE;
1635 }
1636
1637 if ( IsRich() )
1638 {
1639 // change the colour of everything
1640 CHARFORMAT cf;
1641 wxZeroMemory(cf);
1642 cf.cbSize = sizeof(cf);
1643 cf.dwMask = CFM_COLOR;
1644 cf.crTextColor = wxColourToRGB(colour);
1645 ::SendMessage(GetHwnd(), EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1646 }
1647
1648 return TRUE;
1649}
1650
4bc1afd5
VZ
1651// ----------------------------------------------------------------------------
1652// styling support for rich edit controls
1653// ----------------------------------------------------------------------------
1654
1655bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
1656{
1657 if ( !IsRich() )
1658 {
1659 // can't do it with normal text control
1660 return FALSE;
1661 }
1662
a5aa8086
VZ
1663 // the richedit 1.0 doesn't handle setting background colour, so don't
1664 // even try to do anything if it's the only thing we want to change
1665 if ( m_verRichEdit == 1 && !style.HasFont() && !style.HasTextColour() )
4bc1afd5 1666 {
be329a3d
RD
1667 // nothing to do: return TRUE if there was really nothing to do and
1668 // FALSE if we failed to set bg colour
4bc1afd5
VZ
1669 return !style.HasBackgroundColour();
1670 }
1671
1672 // order the range if needed
1673 if ( start > end )
1674 {
1675 long tmp = start;
1676 start = end;
1677 end = tmp;
1678 }
1679
1680 // we can only change the format of the selection, so select the range we
1681 // want and restore the old selection later
1682 long startOld, endOld;
1683 GetSelection(&startOld, &endOld);
1684
1685 // but do we really have to change the selection?
1686 bool changeSel = start != startOld || end != endOld;
1687
1688 if ( changeSel )
aac7e7fe 1689 {
f882d57e 1690 DoSetSelection(start, end, FALSE /* don't scroll caret into view */);
aac7e7fe 1691 }
4bc1afd5
VZ
1692
1693 // initialize CHARFORMAT struct
be329a3d
RD
1694#if wxUSE_RICHEDIT2
1695 CHARFORMAT2 cf;
1696#else
4bc1afd5 1697 CHARFORMAT cf;
be329a3d 1698#endif
a5aa8086 1699
4bc1afd5 1700 wxZeroMemory(cf);
a5aa8086
VZ
1701
1702 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
1703 // CHARFORMAT in that case
1704#if wxUSE_RICHEDIT2
1705 if ( m_verRichEdit == 1 )
1706 {
1707 // this is the only thing the control is going to grok
1708 cf.cbSize = sizeof(CHARFORMAT);
1709 }
1710 else
1711#endif
1712 {
1713 // CHARFORMAT or CHARFORMAT2
1714 cf.cbSize = sizeof(cf);
1715 }
4bc1afd5
VZ
1716
1717 if ( style.HasFont() )
1718 {
aac7e7fe
VZ
1719 // VZ: CFM_CHARSET doesn't seem to do anything at all in RichEdit 2.0
1720 // but using it doesn't seem to hurt neither so leaving it for now
1721
784164e1
VZ
1722 cf.dwMask |= CFM_FACE | CFM_SIZE | CFM_CHARSET |
1723 CFM_ITALIC | CFM_BOLD | CFM_UNDERLINE;
4bc1afd5
VZ
1724
1725 // fill in data from LOGFONT but recalculate lfHeight because we need
1726 // the real height in twips and not the negative number which
1727 // wxFillLogFont() returns (this is correct in general and works with
1728 // the Windows font mapper, but not here)
1729 LOGFONT lf;
1730 wxFillLogFont(&lf, &style.GetFont());
1731 cf.yHeight = 20*style.GetFont().GetPointSize(); // 1 pt = 20 twips
1732 cf.bCharSet = lf.lfCharSet;
1733 cf.bPitchAndFamily = lf.lfPitchAndFamily;
1734 wxStrncpy( cf.szFaceName, lf.lfFaceName, WXSIZEOF(cf.szFaceName) );
1735
784164e1
VZ
1736 // also deal with underline/italic/bold attributes: note that we must
1737 // always set CFM_ITALIC &c bits in dwMask, even if we don't set the
1738 // style to allow clearing it
4bc1afd5
VZ
1739 if ( lf.lfItalic )
1740 {
4bc1afd5
VZ
1741 cf.dwEffects |= CFE_ITALIC;
1742 }
1743
1744 if ( lf.lfWeight == FW_BOLD )
1745 {
4bc1afd5
VZ
1746 cf.dwEffects |= CFE_BOLD;
1747 }
1748
1749 if ( lf.lfUnderline )
1750 {
4bc1afd5
VZ
1751 cf.dwEffects |= CFE_UNDERLINE;
1752 }
1753
1754 // strikeout fonts are not supported by wxWindows
1755 }
1756
1757 if ( style.HasTextColour() )
1758 {
1759 cf.dwMask |= CFM_COLOR;
1760 cf.crTextColor = wxColourToRGB(style.GetTextColour());
1761 }
1762
be329a3d 1763#if wxUSE_RICHEDIT2
a5aa8086 1764 if ( m_verRichEdit != 1 && style.HasBackgroundColour() )
be329a3d
RD
1765 {
1766 cf.dwMask |= CFM_BACKCOLOR;
1767 cf.crBackColor = wxColourToRGB(style.GetBackgroundColour());
1768 }
784164e1
VZ
1769#endif // wxUSE_RICHEDIT2
1770
4bc1afd5
VZ
1771 // do format the selection
1772 bool ok = ::SendMessage(GetHwnd(), EM_SETCHARFORMAT,
1773 SCF_SELECTION, (LPARAM)&cf) != 0;
1774 if ( !ok )
1775 {
1776 wxLogDebug(_T("SendMessage(EM_SETCHARFORMAT, SCF_SELECTION) failed"));
1777 }
1778
1779 if ( changeSel )
1780 {
1781 // restore the original selection
aac7e7fe 1782 DoSetSelection(startOld, endOld, FALSE);
4bc1afd5
VZ
1783 }
1784
1785 return ok;
1786}
f6bcfd97 1787
b12915c1
VZ
1788// ----------------------------------------------------------------------------
1789// wxRichEditModule
1790// ----------------------------------------------------------------------------
1791
b12915c1
VZ
1792bool wxRichEditModule::OnInit()
1793{
1794 // don't do anything - we will load it when needed
1795 return TRUE;
1796}
1797
1798void wxRichEditModule::OnExit()
1799{
136cb3c7 1800 for ( size_t i = 0; i < WXSIZEOF(ms_hRichEdit); i++ )
b12915c1 1801 {
a5aa8086
VZ
1802 if ( ms_hRichEdit[i] )
1803 {
1804 ::FreeLibrary(ms_hRichEdit[i]);
1805 }
b12915c1
VZ
1806 }
1807}
1808
1809/* static */
1810bool wxRichEditModule::Load(int version)
1811{
a5aa8086
VZ
1812 // we don't support loading richedit 3.0 as I don't know how to distinguish
1813 // it from 2.0 anyhow
1814 wxCHECK_MSG( version == 1 || version == 2, FALSE,
b12915c1
VZ
1815 _T("incorrect richedit control version requested") );
1816
a5aa8086
VZ
1817 // make it the index in the array
1818 version--;
1819
a5aa8086 1820 if ( ms_hRichEdit[version] == (HINSTANCE)-1 )
b12915c1 1821 {
a5aa8086
VZ
1822 // we had already tried to load it and failed
1823 return FALSE;
b12915c1
VZ
1824 }
1825
28978e0c
VZ
1826 if ( ms_hRichEdit[version] )
1827 {
1828 // we've already got this one
1829 return TRUE;
1830 }
1831
a5aa8086
VZ
1832 wxString dllname = version ? _T("riched20") : _T("riched32");
1833 dllname += _T(".dll");
b12915c1 1834
a5aa8086 1835 ms_hRichEdit[version] = ::LoadLibrary(dllname);
b12915c1 1836
a5aa8086 1837 if ( !ms_hRichEdit[version] )
b12915c1
VZ
1838 {
1839 wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname.c_str());
1840
a5aa8086 1841 ms_hRichEdit[version] = (HINSTANCE)-1;
b12915c1
VZ
1842
1843 return FALSE;
1844 }
1845
1846 return TRUE;
1847}
1848
1849#endif // wxUSE_RICHEDIT
1850
1e6feb95 1851#endif // wxUSE_TEXTCTRL