]> git.saurik.com Git - wxWidgets.git/blame - src/msw/textctrl.cpp
Added wxWakeUpMainThread, wxMutexGuiEnter, wxMutexGuiLeave,
[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
31#ifndef WX_PRECOMP
a1b82138
VZ
32 #include "wx/textctrl.h"
33 #include "wx/settings.h"
34 #include "wx/brush.h"
35 #include "wx/utils.h"
381dd4bf 36 #include "wx/intl.h"
a1b82138 37 #include "wx/log.h"
381dd4bf 38 #include "wx/app.h"
2bda0e17
KB
39#endif
40
f6bcfd97
BP
41#include "wx/module.h"
42
47d67540 43#if wxUSE_CLIPBOARD
a1b82138 44 #include "wx/clipbrd.h"
2bda0e17
KB
45#endif
46
a1b82138
VZ
47#include "wx/textfile.h"
48
49#include <windowsx.h>
50
2bda0e17
KB
51#include "wx/msw/private.h"
52
a1b82138 53#include <string.h>
2bda0e17 54#include <stdlib.h>
a1b82138 55#include <sys/types.h>
fbc535ff
JS
56
57#if wxUSE_IOSTREAMH
3f4a0c5b 58# include <fstream.h>
fbc535ff 59#else
3f4a0c5b 60# include <fstream>
fbc535ff 61#endif
2bda0e17 62
c42404a5 63#if wxUSE_RICHEDIT && !defined(__GNUWIN32_OLD__)
cd471848 64 #include <richedit.h>
2bda0e17
KB
65#endif
66
b12915c1
VZ
67// ----------------------------------------------------------------------------
68// private classes
69// ----------------------------------------------------------------------------
70
71#if wxUSE_RICHEDIT
72
73// this module initializes RichEdit DLL if needed
74class wxRichEditModule : public wxModule
75{
76public:
77 virtual bool OnInit();
78 virtual void OnExit();
79
80 // get the version currently loaded, -1 if none
81 static int GetLoadedVersion() { return ms_verRichEdit; }
82
83 // load the richedit DLL of at least of required version
84 static bool Load(int version = 1);
85
86private:
87 // the handle to richedit DLL and the version of the DLL loaded
88 static HINSTANCE ms_hRichEdit;
89
90 // the DLL version loaded or -1 if none
91 static int ms_verRichEdit;
92
93 DECLARE_DYNAMIC_CLASS(wxRichEditModule)
94};
95
96HINSTANCE wxRichEditModule::ms_hRichEdit = (HINSTANCE)NULL;
97int wxRichEditModule::ms_verRichEdit = -1;
98
99IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule, wxModule)
100
101#endif // wxUSE_RICHEDIT
e702ff0f 102
a1b82138
VZ
103// ----------------------------------------------------------------------------
104// event tables and other macros
105// ----------------------------------------------------------------------------
106
2bda0e17
KB
107IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
108
109BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
a1b82138
VZ
110 EVT_CHAR(wxTextCtrl::OnChar)
111 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
112
113 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
114 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
115 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
116 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
117 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
118
119 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
120 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
121 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
122 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
123 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
f6bcfd97
BP
124#ifdef __WIN16__
125 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground)
126#endif
2bda0e17 127END_EVENT_TABLE()
e702ff0f 128
2bda0e17 129
a1b82138
VZ
130// ============================================================================
131// implementation
132// ============================================================================
133
134// ----------------------------------------------------------------------------
135// creation
136// ----------------------------------------------------------------------------
137
cd471848 138wxTextCtrl::wxTextCtrl()
2bda0e17 139{
cd471848 140#if wxUSE_RICHEDIT
a1b82138 141 m_isRich = FALSE;
cd471848 142#endif
2bda0e17
KB
143}
144
debe6624 145bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
c085e333
VZ
146 const wxString& value,
147 const wxPoint& pos,
a1b82138
VZ
148 const wxSize& size,
149 long style,
c085e333
VZ
150 const wxValidator& validator,
151 const wxString& name)
2bda0e17 152{
a1b82138 153 // base initialization
8d99be5f 154 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
a1b82138 155 return FALSE;
2bda0e17 156
a1b82138
VZ
157 if ( parent )
158 parent->AddChild(this);
2bda0e17 159
a1b82138
VZ
160 // translate wxWin style flags to MSW ones, checking for consistency while
161 // doing it
f6bcfd97 162 long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP /* | WS_CLIPSIBLINGS */ ;
a1b82138
VZ
163 if ( m_windowStyle & wxTE_MULTILINE )
164 {
165 wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
f6bcfd97 166 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
5fb9fcfc 167
b70ababc
JS
168 msStyle |= ES_MULTILINE | ES_WANTRETURN;
169 if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
170 msStyle |= WS_VSCROLL;
a1b82138
VZ
171 m_windowStyle |= wxTE_PROCESS_ENTER;
172 }
173 else
174 msStyle |= ES_AUTOHSCROLL;
2bda0e17 175
2c738dd8
UM
176 if (m_windowStyle & wxHSCROLL)
177 msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
178
a1b82138
VZ
179 if (m_windowStyle & wxTE_READONLY)
180 msStyle |= ES_READONLY;
2bda0e17 181
a1b82138
VZ
182 if (m_windowStyle & wxTE_PASSWORD) // hidden input
183 msStyle |= ES_PASSWORD;
2bda0e17 184
cfdd3a98
UM
185 if (m_windowStyle & wxTE_AUTO_SCROLL)
186 msStyle |= ES_AUTOHSCROLL;
187
188
101f488c
VZ
189 // we always want the characters and the arrows
190 m_lDlgCode = DLGC_WANTCHARS | DLGC_WANTARROWS;
191
192 // we may have several different cases:
193 // 1. normal case: both TAB and ENTER are used for dialog navigation
194 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
195 // control in the dialog
196 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
197 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
198 // the next control
199 if ( m_windowStyle & wxTE_PROCESS_ENTER )
200 m_lDlgCode |= DLGC_WANTMESSAGE;
201 if ( m_windowStyle & wxTE_PROCESS_TAB )
202 m_lDlgCode |= DLGC_WANTTAB;
203
a1b82138 204 // do create the control - either an EDIT or RICHEDIT
b12915c1 205 wxString windowClass = wxT("EDIT");
cd471848 206
57c208c5 207#if wxUSE_RICHEDIT
c49245f8 208 if ( m_windowStyle & wxTE_RICH )
a1b82138 209 {
0d0512bd
VZ
210 static bool s_errorGiven = FALSE; // MT-FIXME
211
212 // only give the error msg once if the DLL can't be loaded
213 if ( !s_errorGiven )
214 {
215 // first try to load the RichEdit DLL (will do nothing if already
216 // done)
b12915c1 217 if ( !wxRichEditModule::Load() )
0d0512bd 218 {
f6bcfd97 219 wxLogError(_("Impossible to create a rich edit control, using simple text control instead. Please reinstall riched32.dll"));
0d0512bd
VZ
220
221 s_errorGiven = TRUE;
222 }
223 }
224
225 if ( s_errorGiven )
226 {
227 m_isRich = FALSE;
228 }
229 else
230 {
231 msStyle |= ES_AUTOVSCROLL;
232 m_isRich = TRUE;
b12915c1
VZ
233
234 int ver = wxRichEditModule::GetLoadedVersion();
235 if ( ver == 1 )
236 {
237 windowClass = wxT("RICHEDIT");
238 }
239 else
240 {
241#ifndef RICHEDIT_CLASS
242 wxString RICHEDIT_CLASS;
243 RICHEDIT_CLASS.Printf(_T("RichEdit%d0"), ver);
5fb2f4ba 244#if wxUSE_UNICODE
b12915c1
VZ
245 RICHEDIT_CLASS += _T('W');
246#else // ANSI
247 RICHEDIT_CLASS += _T('A');
248#endif // Unicode/ANSI
249#endif // !RICHEDIT_CLASS
250
251 windowClass = RICHEDIT_CLASS;
252 }
0d0512bd 253 }
a1b82138
VZ
254 }
255 else
256 m_isRich = FALSE;
b12915c1 257#endif // wxUSE_RICHEDIT
2bda0e17 258
a1b82138
VZ
259 bool want3D;
260 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
2bda0e17 261
a1b82138
VZ
262 // Even with extended styles, need to combine with WS_BORDER for them to
263 // look right.
264 if ( want3D || wxStyleHasBorder(m_windowStyle) )
265 msStyle |= WS_BORDER;
2bda0e17 266
a1b82138
VZ
267 // NB: don't use pos and size as CreateWindowEx arguments because they
268 // might be -1 in which case we should use the default values (and
269 // SetSize called below takes care of it)
270 m_hWnd = (WXHWND)::CreateWindowEx(exStyle,
5fb2f4ba 271 windowClass.c_str(),
a1b82138
VZ
272 NULL,
273 msStyle,
274 0, 0, 0, 0,
275 GetHwndOf(parent),
276 (HMENU)m_windowId,
277 wxGetInstance(),
278 NULL);
2bda0e17 279
223d09f6 280 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create text ctrl") );
c085e333 281
1f112209 282#if wxUSE_CTL3D
a1b82138
VZ
283 if ( want3D )
284 {
285 Ctl3dSubclassCtl(GetHwnd());
286 m_useCtl3D = TRUE;
287 }
2bda0e17
KB
288#endif
289
57c208c5 290#if wxUSE_RICHEDIT
a1b82138
VZ
291 if (m_isRich)
292 {
293 // Have to enable events
294 ::SendMessage(GetHwnd(), EM_SETEVENTMASK, 0,
295 ENM_CHANGE | ENM_DROPFILES | ENM_SELCHANGE | ENM_UPDATE);
296 }
2bda0e17
KB
297#endif
298
a1b82138 299 SubclassWin(GetHWND());
2bda0e17 300
a1b82138
VZ
301 // set font, position, size and initial value
302 wxFont& fontParent = parent->GetFont();
303 if ( fontParent.Ok() )
304 {
305 SetFont(fontParent);
306 }
307 else
308 {
309 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
310 }
2bda0e17 311
a1b82138 312 // Causes a crash for Symantec C++ and WIN32 for some reason
2bda0e17 313#if !(defined(__SC__) && defined(__WIN32__))
a1b82138
VZ
314 if ( !value.IsEmpty() )
315 {
316 SetValue(value);
317 }
2bda0e17
KB
318#endif
319
d47ebd1e
JS
320 // set colours
321 SetupColours();
322
a1b82138
VZ
323 SetSize(pos.x, pos.y, size.x, size.y);
324
325 return TRUE;
2bda0e17
KB
326}
327
328// Make sure the window style (etc.) reflects the HWND style (roughly)
cd471848 329void wxTextCtrl::AdoptAttributesFromHWND()
2bda0e17 330{
c085e333 331 wxWindow::AdoptAttributesFromHWND();
2bda0e17 332
789295bf 333 HWND hWnd = GetHwnd();
a1b82138 334 long style = GetWindowLong(hWnd, GWL_STYLE);
2bda0e17 335
cd471848
VZ
336 // retrieve the style to see whether this is an edit or richedit ctrl
337#if wxUSE_RICHEDIT
837e5743 338 wxChar buf[256];
2bda0e17 339
a1b82138 340 GetClassName(hWnd, buf, WXSIZEOF(buf));
2bda0e17 341
223d09f6 342 if ( wxStricmp(buf, wxT("EDIT")) == 0 )
c085e333
VZ
343 m_isRich = FALSE;
344 else
345 m_isRich = TRUE;
a1b82138 346#endif // wxUSE_RICHEDIT
c085e333
VZ
347
348 if (style & ES_MULTILINE)
349 m_windowStyle |= wxTE_MULTILINE;
350 if (style & ES_PASSWORD)
351 m_windowStyle |= wxTE_PASSWORD;
352 if (style & ES_READONLY)
353 m_windowStyle |= wxTE_READONLY;
354 if (style & ES_WANTRETURN)
355 m_windowStyle |= wxTE_PROCESS_ENTER;
2bda0e17
KB
356}
357
cd471848 358void wxTextCtrl::SetupColours()
2bda0e17 359{
d47ebd1e 360 wxColour bkgndColour;
f6bcfd97 361// if (IsEditable() || (m_windowStyle & wxTE_MULTILINE))
d47ebd1e 362 bkgndColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW);
f6bcfd97
BP
363// else
364// bkgndColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
d47ebd1e
JS
365
366 SetBackgroundColour(bkgndColour);
a1b82138 367 SetForegroundColour(GetParent()->GetForegroundColour());
2bda0e17
KB
368}
369
a1b82138
VZ
370// ----------------------------------------------------------------------------
371// set/get the controls text
372// ----------------------------------------------------------------------------
373
cd471848 374wxString wxTextCtrl::GetValue() const
2bda0e17 375{
b12915c1
VZ
376 // we can't use wxGetWindowText() (i.e. WM_GETTEXT internally) for
377 // retrieving more than 64Kb under Win9x
378#if wxUSE_RICHEDIT
379 if ( m_isRich )
380 {
5fb2f4ba 381 wxString str;
b12915c1 382
3988b155
VZ
383 int len = GetWindowTextLength(GetHwnd());
384 if ( len )
385 {
386 // alloc one extra WORD as needed by the control
387 wxChar *p = str.GetWriteBuf(++len);
b12915c1 388
3988b155
VZ
389 TEXTRANGE textRange;
390 textRange.chrg.cpMin = 0;
391 textRange.chrg.cpMax = -1;
392 textRange.lpstrText = p;
b12915c1 393
3988b155 394 (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
b12915c1 395
3988b155
VZ
396 // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for
397 // the newlines which is neither Unix nor Windows style (Win95 with
398 // riched20.dll shows this behaviour) - convert it to something
399 // reasonable
400 for ( ; *p; p++ )
401 {
402 if ( *p == _T('\r') )
403 *p = _T('\n');
404 }
405
406 str.UngetWriteBuf();
407 }
408 //else: no text at all, leave the string empty
b12915c1
VZ
409
410 return str;
411 }
412#endif // wxUSE_RICHEDIT
413
414 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
415 // same one as above for consitency
416 wxString str = wxGetWindowText(GetHWND());
417
418 return wxTextFile::Translate(str, wxTextFileType_Unix);
2bda0e17
KB
419}
420
421void wxTextCtrl::SetValue(const wxString& value)
422{
b12915c1
VZ
423 // if the text is long enough, it's faster to just set it instead of first
424 // comparing it with the old one (chances are that it will be different
425 // anyhow, this comparison is there to avoid flicker for small single-line
426 // edit controls mostly)
427 if ( (value.length() > 0x400) || (value != GetValue()) )
07cf98cb 428 {
b12915c1 429 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
c4608a8a 430
5fb2f4ba 431 SetWindowText(GetHwnd(), valueDos.c_str());
a1b82138 432
f6bcfd97
BP
433 // for compatibility with the GTK and because it is more logical, we
434 // move the cursor to the end of the text after SetValue()
435
436 // GRG, Jun/2000: Changed this back after a lot of discussion
437 // in the lists. wxWindows 2.2 will have a set of flags to
438 // customize this behaviour.
439 //SetInsertionPointEnd();
440
07cf98cb
VZ
441 AdjustSpaceLimit();
442 }
2bda0e17
KB
443}
444
a1b82138 445void wxTextCtrl::WriteText(const wxString& value)
2bda0e17 446{
a1b82138 447 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
2bda0e17 448
a1b82138 449 SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)valueDos.c_str());
2bda0e17 450
a1b82138 451 AdjustSpaceLimit();
2bda0e17
KB
452}
453
a1b82138
VZ
454void wxTextCtrl::AppendText(const wxString& text)
455{
456 SetInsertionPointEnd();
457 WriteText(text);
458}
459
460void wxTextCtrl::Clear()
461{
223d09f6 462 SetWindowText(GetHwnd(), wxT(""));
a1b82138
VZ
463}
464
465// ----------------------------------------------------------------------------
2bda0e17 466// Clipboard operations
a1b82138
VZ
467// ----------------------------------------------------------------------------
468
cd471848 469void wxTextCtrl::Copy()
2bda0e17 470{
e702ff0f
JS
471 if (CanCopy())
472 {
789295bf 473 HWND hWnd = GetHwnd();
e702ff0f
JS
474 SendMessage(hWnd, WM_COPY, 0, 0L);
475 }
2bda0e17
KB
476}
477
cd471848 478void wxTextCtrl::Cut()
2bda0e17 479{
e702ff0f
JS
480 if (CanCut())
481 {
789295bf 482 HWND hWnd = GetHwnd();
e702ff0f
JS
483 SendMessage(hWnd, WM_CUT, 0, 0L);
484 }
2bda0e17
KB
485}
486
cd471848 487void wxTextCtrl::Paste()
2bda0e17 488{
e702ff0f
JS
489 if (CanPaste())
490 {
789295bf 491 HWND hWnd = GetHwnd();
e702ff0f
JS
492 SendMessage(hWnd, WM_PASTE, 0, 0L);
493 }
2bda0e17
KB
494}
495
a1b82138
VZ
496bool wxTextCtrl::CanCopy() const
497{
498 // Can copy if there's a selection
499 long from, to;
500 GetSelection(& from, & to);
dbf28859 501 return (from != to) ;
a1b82138
VZ
502}
503
504bool wxTextCtrl::CanCut() const
505{
506 // Can cut if there's a selection
507 long from, to;
508 GetSelection(& from, & to);
dbf28859 509 return (from != to) && (IsEditable());
a1b82138
VZ
510}
511
512bool wxTextCtrl::CanPaste() const
513{
514#if wxUSE_RICHEDIT
515 if (m_isRich)
516 {
517 int dataFormat = 0; // 0 == any format
518 return (::SendMessage( GetHwnd(), EM_CANPASTE, (WPARAM) (UINT) dataFormat, 0) != 0);
519 }
520#endif
521 if (!IsEditable())
522 return FALSE;
523
524 // Standard edit control: check for straight text on clipboard
525 bool isTextAvailable = FALSE;
526 if ( ::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
527 {
528 isTextAvailable = (::IsClipboardFormatAvailable(CF_TEXT) != 0);
529 ::CloseClipboard();
530 }
531
532 return isTextAvailable;
533}
534
535// ----------------------------------------------------------------------------
536// Accessors
537// ----------------------------------------------------------------------------
538
debe6624 539void wxTextCtrl::SetEditable(bool editable)
2bda0e17 540{
a1b82138
VZ
541 HWND hWnd = GetHwnd();
542 SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
2bda0e17
KB
543}
544
debe6624 545void wxTextCtrl::SetInsertionPoint(long pos)
2bda0e17 546{
a1b82138 547 HWND hWnd = GetHwnd();
2bda0e17 548#ifdef __WIN32__
57c208c5 549#if wxUSE_RICHEDIT
a1b82138
VZ
550 if ( m_isRich)
551 {
552 CHARRANGE range;
553 range.cpMin = pos;
554 range.cpMax = pos;
555 SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM) &range);
556 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
557 }
558 else
559#endif // wxUSE_RICHEDIT
560 {
561 SendMessage(hWnd, EM_SETSEL, pos, pos);
562 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
563 }
564#else // Win16
565 SendMessage(hWnd, EM_SETSEL, 0, MAKELPARAM(pos, pos));
566#endif // Win32/16
567
c4608a8a 568 static const wxChar *nothing = _T("");
a1b82138 569 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
2bda0e17
KB
570}
571
cd471848 572void wxTextCtrl::SetInsertionPointEnd()
2bda0e17 573{
a1b82138
VZ
574 long pos = GetLastPosition();
575 SetInsertionPoint(pos);
2bda0e17
KB
576}
577
cd471848 578long wxTextCtrl::GetInsertionPoint() const
2bda0e17 579{
57c208c5 580#if wxUSE_RICHEDIT
a1b82138
VZ
581 if (m_isRich)
582 {
583 CHARRANGE range;
584 range.cpMin = 0;
585 range.cpMax = 0;
586 SendMessage(GetHwnd(), EM_EXGETSEL, 0, (LPARAM) &range);
587 return range.cpMin;
588 }
2bda0e17
KB
589#endif
590
a1b82138
VZ
591 DWORD Pos = (DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
592 return Pos & 0xFFFF;
2bda0e17
KB
593}
594
cd471848 595long wxTextCtrl::GetLastPosition() const
2bda0e17 596{
789295bf 597 HWND hWnd = GetHwnd();
2bda0e17
KB
598
599 // Will always return a number > 0 (according to docs)
600 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
601
602 // This gets the char index for the _beginning_ of the last line
603 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
39136494 604
2bda0e17
KB
605 // Get number of characters in the last line. We'll add this to the character
606 // index for the last line, 1st position.
607 int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
608
609 return (long)(charIndex + lineLength);
610}
611
a1b82138
VZ
612// If the return values from and to are the same, there is no
613// selection.
614void wxTextCtrl::GetSelection(long* from, long* to) const
615{
616#if wxUSE_RICHEDIT
617 if (m_isRich)
618 {
619 CHARRANGE charRange;
620 ::SendMessage(GetHwnd(), EM_EXGETSEL, 0, (LPARAM) (CHARRANGE*) & charRange);
621
622 *from = charRange.cpMin;
623 *to = charRange.cpMax;
624
625 return;
626 }
627#endif
628 DWORD dwStart, dwEnd;
629 WPARAM wParam = (WPARAM) (DWORD*) & dwStart; // receives starting position
630 LPARAM lParam = (LPARAM) (DWORD*) & dwEnd; // receives ending position
631
632 ::SendMessage(GetHwnd(), EM_GETSEL, wParam, lParam);
633
634 *from = dwStart;
635 *to = dwEnd;
636}
637
638bool wxTextCtrl::IsEditable() const
639{
640 long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
641
642 return ((style & ES_READONLY) == 0);
643}
644
645// ----------------------------------------------------------------------------
646// Editing
647// ----------------------------------------------------------------------------
648
debe6624 649void wxTextCtrl::Replace(long from, long to, const wxString& value)
2bda0e17 650{
acbd13a3 651#if wxUSE_CLIPBOARD
789295bf 652 HWND hWnd = GetHwnd();
2bda0e17
KB
653 long fromChar = from;
654 long toChar = to;
39136494 655
2bda0e17
KB
656 // Set selection and remove it
657#ifdef __WIN32__
658 SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
659#else
660 SendMessage(hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar));
661#endif
662 SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
663
664 // Now replace with 'value', by pasting.
837e5743 665 wxSetClipboardData(wxDF_TEXT, (wxObject *) (const wxChar *)value, 0, 0);
2bda0e17
KB
666
667 // Paste into edit control
668 SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
acbd13a3
JS
669#else
670 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
671#endif
2bda0e17
KB
672}
673
debe6624 674void wxTextCtrl::Remove(long from, long to)
2bda0e17 675{
789295bf 676 HWND hWnd = GetHwnd();
2bda0e17
KB
677 long fromChar = from;
678 long toChar = to;
39136494 679
2bda0e17
KB
680 // Cut all selected text
681#ifdef __WIN32__
682 SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
683#else
684 SendMessage(hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar));
685#endif
686 SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
687}
688
debe6624 689void wxTextCtrl::SetSelection(long from, long to)
2bda0e17 690{
789295bf 691 HWND hWnd = GetHwnd();
2bda0e17
KB
692 long fromChar = from;
693 long toChar = to;
a1b82138
VZ
694
695 // if from and to are both -1, it means (in wxWindows) that all text should
696 // be selected. Translate into Windows convention
2bda0e17
KB
697 if ((from == -1) && (to == -1))
698 {
699 fromChar = 0;
700 toChar = -1;
701 }
39136494 702
2bda0e17
KB
703#ifdef __WIN32__
704 SendMessage(hWnd, EM_SETSEL, (WPARAM)fromChar, (LPARAM)toChar);
705 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
706#else
707 // WPARAM is 0: selection is scrolled into view
708 SendMessage(hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar));
709#endif
710}
711
712bool wxTextCtrl::LoadFile(const wxString& file)
713{
a1b82138 714 if ( wxTextCtrlBase::LoadFile(file) )
cd471848 715 {
a1b82138
VZ
716 // update the size limit if needed
717 AdjustSpaceLimit();
2bda0e17 718
a1b82138 719 return TRUE;
2bda0e17 720 }
2bda0e17 721
a1b82138 722 return FALSE;
2bda0e17
KB
723}
724
cd471848 725bool wxTextCtrl::IsModified() const
2bda0e17 726{
789295bf 727 return (SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0);
2bda0e17
KB
728}
729
730// Makes 'unmodified'
cd471848 731void wxTextCtrl::DiscardEdits()
2bda0e17 732{
a1b82138 733 SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L);
2bda0e17
KB
734}
735
cd471848 736int wxTextCtrl::GetNumberOfLines() const
2bda0e17 737{
789295bf 738 return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
2bda0e17
KB
739}
740
debe6624 741long wxTextCtrl::XYToPosition(long x, long y) const
2bda0e17 742{
789295bf 743 HWND hWnd = GetHwnd();
2bda0e17
KB
744
745 // This gets the char index for the _beginning_ of this line
746 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
747 return (long)(x + charIndex);
748}
749
0efe5ba7 750bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
2bda0e17 751{
789295bf 752 HWND hWnd = GetHwnd();
2bda0e17
KB
753
754 // This gets the line number containing the character
0efe5ba7
VZ
755 int lineNo;
756#if wxUSE_RICHEDIT
757 if ( m_isRich )
758 {
759 lineNo = (int)SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, (LPARAM)pos);
760 }
761 else
762#endif // wxUSE_RICHEDIT
763 lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
764
765 if ( lineNo == -1 )
766 {
767 // no such line
768 return FALSE;
769 }
770
2bda0e17
KB
771 // This gets the char index for the _beginning_ of this line
772 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
0efe5ba7
VZ
773 if ( charIndex == -1 )
774 {
775 return FALSE;
776 }
777
2bda0e17 778 // The X position must therefore be the different between pos and charIndex
0efe5ba7
VZ
779 if ( x )
780 *x = (long)(pos - charIndex);
781 if ( y )
782 *y = (long)lineNo;
783
784 return TRUE;
2bda0e17
KB
785}
786
debe6624 787void wxTextCtrl::ShowPosition(long pos)
2bda0e17 788{
789295bf 789 HWND hWnd = GetHwnd();
2bda0e17
KB
790
791 // To scroll to a position, we pass the number of lines and characters
792 // to scroll *by*. This means that we need to:
793 // (1) Find the line position of the current line.
794 // (2) Find the line position of pos.
795 // (3) Scroll by (pos - current).
796 // For now, ignore the horizontal scrolling.
797
798 // Is this where scrolling is relative to - the line containing the caret?
799 // Or is the first visible line??? Try first visible line.
800// int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
801
802 int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
803
804 int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
39136494 805
2bda0e17
KB
806 int linesToScroll = specifiedLineLineNo - currentLineLineNo;
807
2bda0e17 808 if (linesToScroll != 0)
de4d7713 809 (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
2bda0e17
KB
810}
811
debe6624 812int wxTextCtrl::GetLineLength(long lineNo) const
2bda0e17
KB
813{
814 long charIndex = XYToPosition(0, lineNo);
4438caf4 815 int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
2bda0e17
KB
816 return len;
817}
818
debe6624 819wxString wxTextCtrl::GetLineText(long lineNo) const
2bda0e17 820{
a1b82138 821 size_t len = (size_t)GetLineLength(lineNo) + 1;
488fe1fe 822
f6bcfd97
BP
823 // there must be at least enough place for the length WORD in the
824 // buffer
825 len += sizeof(WORD);
4438caf4 826
f6bcfd97
BP
827 wxString str;
828 wxChar *buf = str.GetWriteBuf(len);
829
830 *(WORD *)buf = len;
831 len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
832 buf[len] = 0;
4438caf4 833
f6bcfd97 834 str.UngetWriteBuf(len);
4438caf4
VZ
835
836 return str;
2bda0e17
KB
837}
838
a1b82138 839// ----------------------------------------------------------------------------
ca8b28f2 840// Undo/redo
a1b82138
VZ
841// ----------------------------------------------------------------------------
842
ca8b28f2
JS
843void wxTextCtrl::Undo()
844{
845 if (CanUndo())
846 {
789295bf 847 ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
ca8b28f2
JS
848 }
849}
850
851void wxTextCtrl::Redo()
852{
853 if (CanRedo())
854 {
855 // Same as Undo, since Undo undoes the undo, i.e. a redo.
789295bf 856 ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
ca8b28f2
JS
857 }
858}
859
860bool wxTextCtrl::CanUndo() const
861{
789295bf 862 return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
ca8b28f2
JS
863}
864
865bool wxTextCtrl::CanRedo() const
866{
789295bf 867 return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
ca8b28f2
JS
868}
869
a1b82138
VZ
870// ----------------------------------------------------------------------------
871// implemenation details
872// ----------------------------------------------------------------------------
39136494 873
2bda0e17
KB
874void wxTextCtrl::Command(wxCommandEvent & event)
875{
a1b82138
VZ
876 SetValue(event.GetString());
877 ProcessCommand (event);
2bda0e17
KB
878}
879
880void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
881{
a1b82138
VZ
882 // By default, load the first file into the text window.
883 if (event.GetNumberOfFiles() > 0)
884 {
885 LoadFile(event.GetFiles()[0]);
886 }
2bda0e17
KB
887}
888
2bda0e17
KB
889void wxTextCtrl::OnChar(wxKeyEvent& event)
890{
42e69d6b 891 switch ( event.KeyCode() )
cd471848 892 {
cd471848 893 case WXK_RETURN:
39136494 894 if ( !(m_windowStyle & wxTE_MULTILINE) )
cd471848
VZ
895 {
896 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
bfbd6dc1 897 InitCommandEvent(event);
f6bcfd97 898 event.SetString(GetValue());
cd471848
VZ
899 if ( GetEventHandler()->ProcessEvent(event) )
900 return;
901 }
5fb9fcfc
VZ
902 //else: multiline controls need Enter for themselves
903
904 break;
4d91c1d1 905
cd471848 906 case WXK_TAB:
319fefa9
VZ
907 // always produce navigation event - even if we process TAB
908 // ourselves the fact that we got here means that the user code
909 // decided to skip processing of this TAB - probably to let it
910 // do its default job.
cd471848 911 {
5fb9fcfc
VZ
912 wxNavigationKeyEvent eventNav;
913 eventNav.SetDirection(!event.ShiftDown());
8614c467 914 eventNav.SetWindowChange(event.ControlDown());
5fb9fcfc 915 eventNav.SetEventObject(this);
39136494 916
d9506e77 917 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
cd471848
VZ
918 return;
919 }
341c92a8 920 break;
cd471848 921 }
39136494 922
8614c467 923 // no, we didn't process it
42e69d6b 924 event.Skip();
2bda0e17
KB
925}
926
debe6624 927bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
2bda0e17 928{
789295bf
VZ
929 switch (param)
930 {
931 case EN_SETFOCUS:
932 case EN_KILLFOCUS:
933 {
934 wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
935 : wxEVT_SET_FOCUS,
936 m_windowId);
937 event.SetEventObject( this );
938 GetEventHandler()->ProcessEvent(event);
939 }
940 break;
ae29de83 941
789295bf
VZ
942 case EN_CHANGE:
943 {
944 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
bfbd6dc1
VZ
945 InitCommandEvent(event);
946 event.SetString(GetValue());
947 ProcessCommand(event);
789295bf
VZ
948 }
949 break;
2bda0e17 950
b12915c1 951 case EN_MAXTEXT:
789295bf
VZ
952 // the text size limit has been hit - increase it
953 AdjustSpaceLimit();
954 break;
955
956 // the other notification messages are not processed
957 case EN_UPDATE:
b12915c1 958 case EN_ERRSPACE:
789295bf
VZ
959 case EN_HSCROLL:
960 case EN_VSCROLL:
f6bcfd97 961 return FALSE;
789295bf
VZ
962 default:
963 return FALSE;
964 }
965
966 // processed
967 return TRUE;
2bda0e17
KB
968}
969
f6bcfd97
BP
970WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
971 WXUINT message,
972 WXWPARAM wParam,
973 WXLPARAM lParam)
974{
975#if wxUSE_CTL3D
976 if ( m_useCtl3D )
977 {
978 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
979 return (WXHBRUSH) hbrush;
980 }
981#endif // wxUSE_CTL3D
982
983 HDC hdc = (HDC)pDC;
984 if (GetParent()->GetTransparentBackground())
985 SetBkMode(hdc, TRANSPARENT);
986 else
987 SetBkMode(hdc, OPAQUE);
988
989 wxColour colBack = GetBackgroundColour();
990
991 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE) == 0)
992 colBack = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
993
994 ::SetBkColor(hdc, wxColourToRGB(colBack));
995 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
996
997 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
998
999 return (WXHBRUSH)brush->GetResourceHandle();
1000}
1001
1002// In WIN16, need to override normal erasing because
1003// Ctl3D doesn't use the wxWindows background colour.
1004#ifdef __WIN16__
1005void wxTextCtrl::OnEraseBackground(wxEraseEvent& event)
1006{
1007 wxColour col(m_backgroundColour);
1008
1009#if wxUSE_CTL3D
1010 if (m_useCtl3D)
1011 col = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW);
1012#endif
1013
1014 RECT rect;
1015 ::GetClientRect(GetHwnd(), &rect);
1016
1017 COLORREF ref = PALETTERGB(col.Red(),
1018 col.Green(),
1019 col.Blue());
1020 HBRUSH hBrush = ::CreateSolidBrush(ref);
1021 if ( !hBrush )
1022 wxLogLastError(wxT("CreateSolidBrush"));
1023
1024 HDC hdc = (HDC)event.GetDC()->GetHDC();
1025
1026 int mode = ::SetMapMode(hdc, MM_TEXT);
1027
1028 ::FillRect(hdc, &rect, hBrush);
1029 ::DeleteObject(hBrush);
1030 ::SetMapMode(hdc, mode);
1031
1032}
1033#endif
1034
789295bf
VZ
1035void wxTextCtrl::AdjustSpaceLimit()
1036{
25889d3c 1037#ifndef __WIN16__
789295bf
VZ
1038 unsigned int len = ::GetWindowTextLength(GetHwnd()),
1039 limit = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
17d8ee1c 1040 if ( len >= limit )
789295bf
VZ
1041 {
1042 limit = len + 0x8000; // 32Kb
1043
5ea105e0 1044#if wxUSE_RICHEDIT
b12915c1
VZ
1045 if ( m_isRich )
1046 {
1047 // as a nice side effect, this also allows passing limit > 64Kb
1048 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT, 0, limit);
1049 }
789295bf 1050 else
b12915c1
VZ
1051#endif // wxUSE_RICHEDIT
1052 {
1053 if ( limit > 0xffff )
1054 {
1055 // this will set it to a platform-dependent maximum (much more
1056 // than 64Kb under NT)
1057 limit = 0;
1058 }
1059
789295bf 1060 ::SendMessage(GetHwnd(), EM_LIMITTEXT, limit, 0);
b12915c1 1061 }
789295bf 1062 }
b12915c1 1063#endif // !Win16
789295bf 1064}
2bda0e17 1065
a1b82138 1066bool wxTextCtrl::AcceptsFocus() const
2bda0e17 1067{
a1b82138
VZ
1068 // we don't want focus if we can't be edited
1069 return IsEditable() && wxControl::AcceptsFocus();
1070}
c085e333 1071
f68586e5 1072wxSize wxTextCtrl::DoGetBestSize() const
a1b82138
VZ
1073{
1074 int cx, cy;
1075 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
1076
1077 int wText = DEFAULT_ITEM_WIDTH;
1078
1079 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
1080 if ( m_windowStyle & wxTE_MULTILINE )
1081 {
3988b155 1082 hText *= wxMax(GetNumberOfLines(), 5);
a1b82138
VZ
1083 }
1084 //else: for single line control everything is ok
1085
1086 return wxSize(wText, hText);
2bda0e17 1087}
a1b82138
VZ
1088
1089// ----------------------------------------------------------------------------
1090// standard handlers for standard edit menu events
1091// ----------------------------------------------------------------------------
2bda0e17 1092
bfbd6dc1 1093void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1094{
1095 Cut();
1096}
1097
bfbd6dc1 1098void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1099{
1100 Copy();
1101}
1102
bfbd6dc1 1103void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1104{
1105 Paste();
1106}
1107
bfbd6dc1 1108void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1109{
1110 Undo();
1111}
1112
bfbd6dc1 1113void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
e702ff0f
JS
1114{
1115 Redo();
1116}
1117
1118void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
1119{
1120 event.Enable( CanCut() );
1121}
1122
1123void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
1124{
1125 event.Enable( CanCopy() );
1126}
1127
1128void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
1129{
1130 event.Enable( CanPaste() );
1131}
1132
1133void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
1134{
1135 event.Enable( CanUndo() );
1136}
1137
1138void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
1139{
1140 event.Enable( CanRedo() );
1141}
1142
f6bcfd97
BP
1143// ----------------------------------------------------------------------------
1144// colour setting for the rich edit controls
1145// ----------------------------------------------------------------------------
1146
1147#if wxUSE_RICHEDIT
1148
1149// Watcom C++ doesn't define this
1150#ifndef SCF_ALL
1151#define SCF_ALL 0x0004
1152#endif
1153
1154bool wxTextCtrl::SetBackgroundColour(const wxColour& colour)
1155{
1156 if ( !wxTextCtrlBase::SetBackgroundColour(colour) )
1157 {
1158 // colour didn't really change
1159 return FALSE;
1160 }
1161
1162 if ( IsRich() )
1163 {
1164 // rich edit doesn't use WM_CTLCOLOR, hence we need to send
1165 // EM_SETBKGNDCOLOR additionally
1166 ::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR, 0, wxColourToRGB(colour));
1167 }
1168
1169 return TRUE;
1170}
1171
1172bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
1173{
1174 if ( !wxTextCtrlBase::SetForegroundColour(colour) )
1175 {
1176 // colour didn't really change
1177 return FALSE;
1178 }
1179
1180 if ( IsRich() )
1181 {
1182 // change the colour of everything
1183 CHARFORMAT cf;
1184 wxZeroMemory(cf);
1185 cf.cbSize = sizeof(cf);
1186 cf.dwMask = CFM_COLOR;
1187 cf.crTextColor = wxColourToRGB(colour);
1188 ::SendMessage(GetHwnd(), EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
1189 }
1190
1191 return TRUE;
1192}
1193
1194#endif // wxUSE_RICHEDIT
1195
b12915c1
VZ
1196// ----------------------------------------------------------------------------
1197// wxRichEditModule
1198// ----------------------------------------------------------------------------
1199
1200#if wxUSE_RICHEDIT
1201
1202bool wxRichEditModule::OnInit()
1203{
1204 // don't do anything - we will load it when needed
1205 return TRUE;
1206}
1207
1208void wxRichEditModule::OnExit()
1209{
1210 if ( ms_hRichEdit )
1211 {
1212 FreeLibrary(ms_hRichEdit);
1213 }
1214}
1215
1216/* static */
1217bool wxRichEditModule::Load(int version)
1218{
1219 wxCHECK_MSG( version >= 1 && version <= 3, FALSE,
1220 _T("incorrect richedit control version requested") );
1221
1222 if ( version <= ms_verRichEdit )
1223 {
1224 // we've already got this or better
1225 return TRUE;
1226 }
1227
1228 if ( ms_hRichEdit )
1229 {
1230 ::FreeLibrary(ms_hRichEdit);
1231 }
1232
1233 // always try load riched20.dll first - like this we won't have to reload
1234 // it later if we're first asked for RE 1 and then for RE 2 or 3
1235 wxString dllname = _T("riched20.dll");
1236 ms_hRichEdit = ::LoadLibrary(dllname);
1237 ms_verRichEdit = 2; // no way to tell if it's 2 or 3, assume 2
1238
1239 if ( !ms_hRichEdit && (version == 1) )
1240 {
1241 // fall back to RE 1
1242 dllname = _T("riched32.dll");
1243 ms_hRichEdit = ::LoadLibrary(dllname);
1244 ms_verRichEdit = 1;
1245 }
1246
1247 if ( !ms_hRichEdit )
1248 {
1249 wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname.c_str());
1250
1251 ms_verRichEdit = -1;
1252
1253 return FALSE;
1254 }
1255
1256 return TRUE;
1257}
1258
1259#endif // wxUSE_RICHEDIT
1260