1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/textctrl.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "textctrl.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/textctrl.h"
35 #include "wx/settings.h"
43 #include "wx/module.h"
46 #include "wx/clipbrd.h"
49 #include "wx/textfile.h"
53 #include "wx/msw/private.h"
57 #include <sys/types.h>
59 #if wxUSE_RICHEDIT && (!defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__))
63 // old mingw32 doesn't define this
65 #define CFM_CHARSET 0x08000000
69 #define CFM_BACKCOLOR 0x04000000
72 // cygwin does not have these defined for richedit
74 #define ENM_LINK 0x04000000
77 #ifndef EM_AUTOURLDETECT
78 #define EM_AUTOURLDETECT (WM_USER + 91)
82 #define EN_LINK 0x070b
84 typedef struct _enlink
95 #define SF_UNICODE 0x0010
98 // Watcom C++ doesn't define this
100 #define SCF_ALL 0x0004
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
109 DWORD CALLBACK
wxRichEditStreamIn(DWORD dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
);
111 #endif // wxUSE_RICHEDIT
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
119 // this module initializes RichEdit DLL(s) if needed
120 class wxRichEditModule
: public wxModule
123 virtual bool OnInit();
124 virtual void OnExit();
126 // load the richedit DLL of at least of required version
127 static bool Load(int version
= 1);
130 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
131 static HINSTANCE ms_hRichEdit
[2];
133 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
136 HINSTANCE
wxRichEditModule::ms_hRichEdit
[2] = { NULL
, NULL
};
138 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
140 #endif // wxUSE_RICHEDIT
142 // ----------------------------------------------------------------------------
143 // event tables and other macros
144 // ----------------------------------------------------------------------------
146 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
148 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
149 EVT_CHAR(wxTextCtrl::OnChar
)
150 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
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
)
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
)
164 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
168 // ============================================================================
170 // ============================================================================
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 void wxTextCtrl::Init()
181 m_suppressNextUpdate
= FALSE
;
182 #endif // wxUSE_RICHEDIT
185 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
186 const wxString
& value
,
190 const wxValidator
& validator
,
191 const wxString
& name
)
193 // base initialization
194 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
198 parent
->AddChild(this);
200 // translate wxWin style flags to MSW ones
201 WXDWORD msStyle
= MSWGetCreateWindowFlags();
203 // do create the control - either an EDIT or RICHEDIT
204 wxString windowClass
= wxT("EDIT");
207 if ( m_windowStyle
& wxTE_AUTO_URL
)
209 // automatic URL detection only works in RichEdit 2.0+
210 m_windowStyle
|= wxTE_RICH2
;
213 if ( m_windowStyle
& wxTE_RICH2
)
215 // using richedit 2.0 implies using wxTE_RICH
216 m_windowStyle
|= wxTE_RICH
;
219 // we need to load the richedit DLL before creating the rich edit control
220 if ( m_windowStyle
& wxTE_RICH
)
222 static bool s_errorGiven
= FALSE
;// MT-FIXME
224 // Which version do we need? Use 1.0 by default because it is much more
225 // like the the standard EDIT or 2.0 if explicitly requested, but use
226 // only 2.0 in Unicode mode as 1.0 doesn't support Unicode at all
228 // TODO: RichEdit 3.0 is apparently capable of emulating RichEdit 1.0
229 // (and thus EDIT) much better than RichEdit 2.0 so we probably
230 // should use 3.0 if available as it is the best of both worlds -
231 // but as I can't test it right now I don't do it (VZ)
233 const int verRichEdit
= 2;
234 #else // !wxUSE_UNICODE
235 int verRichEdit
= m_windowStyle
& wxTE_RICH2
? 2 : 1;
236 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
238 // only give the error msg once if the DLL can't be loaded
241 // try to load the RichEdit DLL (will do nothing if already done)
242 if ( !wxRichEditModule::Load(verRichEdit
) )
245 // try another version?
246 verRichEdit
= 3 - verRichEdit
; // 1 <-> 2
248 if ( !wxRichEditModule::Load(verRichEdit
) )
249 #endif // wxUSE_UNICODE
251 wxLogError(_("Impossible to create a rich edit control, using simple text control instead. Please reinstall riched32.dll"));
258 // have we managed to load any richedit version?
261 msStyle
|= ES_AUTOVSCROLL
;
263 m_verRichEdit
= verRichEdit
;
264 if ( m_verRichEdit
== 1 )
266 windowClass
= wxT("RICHEDIT");
270 #ifndef RICHEDIT_CLASS
271 wxString RICHEDIT_CLASS
;
272 RICHEDIT_CLASS
.Printf(_T("RichEdit%d0"), m_verRichEdit
);
274 RICHEDIT_CLASS
+= _T('W');
276 RICHEDIT_CLASS
+= _T('A');
277 #endif // Unicode/ANSI
278 #endif // !RICHEDIT_CLASS
280 windowClass
= RICHEDIT_CLASS
;
284 #endif // wxUSE_RICHEDIT
286 // we need to turn '\n's into "\r\n"s for the multiline controls
288 if ( m_windowStyle
& wxTE_MULTILINE
)
290 valueWin
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
297 if ( !MSWCreateControl(windowClass
, msStyle
, pos
, size
, valueWin
) )
300 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
305 // enable the events we're interested in: we want to get EN_CHANGE as
306 // for the normal controls
307 LPARAM mask
= ENM_CHANGE
;
309 if ( GetRichVersion() == 1 )
311 // we also need EN_MSGFILTER for richedit 1.0 for the reasons
312 // explained in its handler
313 mask
|= ENM_MOUSEEVENTS
;
315 else if ( m_windowStyle
& wxTE_AUTO_URL
)
319 ::SendMessage(GetHwnd(), EM_AUTOURLDETECT
, TRUE
, 0);
322 ::SendMessage(GetHwnd(), EM_SETEVENTMASK
, 0, mask
);
324 #endif // wxUSE_RICHEDIT
329 // Make sure the window style (etc.) reflects the HWND style (roughly)
330 void wxTextCtrl::AdoptAttributesFromHWND()
332 wxWindow::AdoptAttributesFromHWND();
334 HWND hWnd
= GetHwnd();
335 long style
= ::GetWindowLong(hWnd
, GWL_STYLE
);
337 // retrieve the style to see whether this is an edit or richedit ctrl
339 wxString classname
= wxGetWindowClass(GetHWND());
341 if ( classname
.IsSameAs(_T("EDIT"), FALSE
/* no case */) )
348 if ( wxSscanf(classname
, _T("RichEdit%d0%c"), &m_verRichEdit
, &c
) != 2 )
350 wxLogDebug(_T("Unknown edit control '%s'."), classname
.c_str());
355 #endif // wxUSE_RICHEDIT
357 if (style
& ES_MULTILINE
)
358 m_windowStyle
|= wxTE_MULTILINE
;
359 if (style
& ES_PASSWORD
)
360 m_windowStyle
|= wxTE_PASSWORD
;
361 if (style
& ES_READONLY
)
362 m_windowStyle
|= wxTE_READONLY
;
363 if (style
& ES_WANTRETURN
)
364 m_windowStyle
|= wxTE_PROCESS_ENTER
;
365 if (style
& ES_CENTER
)
366 m_windowStyle
|= wxTE_CENTRE
;
367 if (style
& ES_RIGHT
)
368 m_windowStyle
|= wxTE_RIGHT
;
371 WXDWORD
wxTextCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
373 // default border for the text controls is the sunken one
374 if ( (style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
376 style
|= wxBORDER_SUNKEN
;
379 long msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
384 if ( style
& wxTE_MULTILINE
)
386 wxASSERT_MSG( !(style
& wxTE_PROCESS_ENTER
),
387 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
389 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
;
390 if ( !(style
& wxTE_NO_VSCROLL
) )
391 msStyle
|= WS_VSCROLL
;
393 style
|= wxTE_PROCESS_ENTER
;
397 // there is really no reason to not have this style for single line
399 msStyle
|= ES_AUTOHSCROLL
;
402 if ( style
& wxHSCROLL
)
403 msStyle
|= WS_HSCROLL
| ES_AUTOHSCROLL
;
405 if ( style
& wxTE_READONLY
)
406 msStyle
|= ES_READONLY
;
408 if ( style
& wxTE_PASSWORD
)
409 msStyle
|= ES_PASSWORD
;
411 if ( style
& wxTE_AUTO_SCROLL
)
412 msStyle
|= ES_AUTOHSCROLL
;
414 if ( style
& wxTE_NOHIDESEL
)
415 msStyle
|= ES_NOHIDESEL
;
417 if ( style
& wxTE_CENTRE
)
418 msStyle
|= ES_CENTER
;
420 if ( style
& wxTE_RIGHT
)
426 void wxTextCtrl::SetWindowStyleFlag(long style
)
429 // we have to deal with some styles separately because they can't be
430 // changed by simply calling SetWindowLong(GWL_STYLE) but can be changed
431 // using richedit-specific EM_SETOPTIONS
433 ((style
& wxTE_NOHIDESEL
) != (GetWindowStyle() & wxTE_NOHIDESEL
)) )
435 bool set
= (style
& wxTE_NOHIDESEL
) != 0;
437 ::SendMessage(GetHwnd(), EM_SETOPTIONS
, set
? ECOOP_OR
: ECOOP_AND
,
438 set
? ECO_NOHIDESEL
: ~ECO_NOHIDESEL
);
440 #endif // wxUSE_RICHEDIT
442 wxControl::SetWindowStyleFlag(style
);
445 // ----------------------------------------------------------------------------
446 // set/get the controls text
447 // ----------------------------------------------------------------------------
449 wxString
wxTextCtrl::GetValue() const
451 // range 0..-1 is special for GetRange() and means to retrieve all text
452 return GetRange(0, -1);
455 wxString
wxTextCtrl::GetRange(long from
, long to
) const
459 if ( from
>= to
&& to
!= -1 )
461 // nothing to retrieve
468 int len
= GetWindowTextLength(GetHwnd());
471 // alloc one extra WORD as needed by the control
472 wxChar
*p
= str
.GetWriteBuf(++len
);
475 textRange
.chrg
.cpMin
= from
;
476 textRange
.chrg
.cpMax
= to
== -1 ? len
: to
;
477 textRange
.lpstrText
= p
;
479 (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
481 if ( m_verRichEdit
> 1 )
483 // RichEdit 2.0 uses just CR ('\r') for the newlines which is
484 // neither Unix nor Windows style - convert it to something
488 if ( *p
== _T('\r') )
495 if ( m_verRichEdit
== 1 )
497 // convert to the canonical form - see comment below
498 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
501 //else: no text at all, leave the string empty
504 #endif // wxUSE_RICHEDIT
507 str
= wxGetWindowText(GetHWND());
509 // need only a range?
512 str
= str
.Mid(from
, to
- from
);
515 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
516 // canonical one (same one as above) for consistency with the other kinds
517 // of controls and, more importantly, with the other ports
518 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
524 void wxTextCtrl::SetValue(const wxString
& value
)
526 // if the text is long enough, it's faster to just set it instead of first
527 // comparing it with the old one (chances are that it will be different
528 // anyhow, this comparison is there to avoid flicker for small single-line
529 // edit controls mostly)
530 if ( (value
.length() > 0x400) || (value
!= GetValue()) )
532 DoWriteText(value
, FALSE
/* not selection only */);
534 // mark the control as being not dirty - we changed its text, not the
538 // for compatibility, don't move the cursor when doing SetValue()
539 SetInsertionPoint(0);
543 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
545 DWORD CALLBACK
wxRichEditStreamIn(DWORD dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
549 wchar_t *wbuf
= (wchar_t *)buf
;
550 const wchar_t *wpc
= *(const wchar_t **)dwCookie
;
555 cb
-= sizeof(wchar_t);
556 (*pcb
) += sizeof(wchar_t);
559 *(const wchar_t **)dwCookie
= wpc
;
564 extern long wxEncodingToCodepage(wxFontEncoding encoding
); // from utils.cpp
567 bool wxTextCtrl::StreamIn(const wxString
& value
,
568 wxFontEncoding
WXUNUSED(encoding
),
575 #if wxUSE_UNICODE_MSLU
576 bool wxTextCtrl::StreamIn(const wxString
& value
,
577 wxFontEncoding
WXUNUSED(encoding
),
580 const wchar_t *wpc
= value
.c_str();
581 #else // !wxUSE_UNICODE_MSLU
582 bool wxTextCtrl::StreamIn(const wxString
& value
,
583 wxFontEncoding encoding
,
586 // we have to use EM_STREAMIN to force richedit control 2.0+ to show any
587 // text in the non default charset - otherwise it thinks it knows better
588 // than we do and always shows it in the default one
590 // first get the Windows code page for this encoding
591 long codepage
= wxEncodingToCodepage(encoding
);
592 if ( codepage
== -1 )
598 // next translate to Unicode using this code page
599 int len
= ::MultiByteToWideChar(codepage
, 0, value
, -1, NULL
, 0);
602 wxWCharBuffer
wchBuf(len
);
604 wchar_t *wchBuf
= (wchar_t *)malloc((len
+ 1)*sizeof(wchar_t));
607 if ( !::MultiByteToWideChar(codepage
, 0, value
, -1,
608 (wchar_t *)(const wchar_t *)wchBuf
, len
) )
610 wxLogLastError(_T("MultiByteToWideChar"));
613 // finally, stream it in the control
614 const wchar_t *wpc
= wchBuf
;
615 #endif // wxUSE_UNICODE_MSLU
619 eds
.dwCookie
= (DWORD
)&wpc
;
620 // the cast below is needed for broken (very) old mingw32 headers
621 eds
.pfnCallback
= (EDITSTREAMCALLBACK
)wxRichEditStreamIn
;
623 if ( !::SendMessage(GetHwnd(), EM_STREAMIN
,
626 (selectionOnly
? SFF_SELECTION
: 0),
627 (LPARAM
)&eds
) || eds
.dwError
)
629 wxLogLastError(_T("EM_STREAMIN"));
634 #endif // !wxUSE_WCHAR_T
642 #endif // wxUSE_RICHEDIT
644 void wxTextCtrl::WriteText(const wxString
& value
)
649 void wxTextCtrl::DoWriteText(const wxString
& value
, bool selectionOnly
)
652 if ( m_windowStyle
& wxTE_MULTILINE
)
653 valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
658 // there are several complications with the rich edit controls here
662 // first, ensure that the new text will be in the default style
663 if ( !m_defaultStyle
.IsDefault() )
666 GetSelection(&start
, &end
);
667 SetStyle(start
, end
, m_defaultStyle
);
670 #if wxUSE_UNICODE_MSLU
671 // RichEdit doesn't have Unicode version of EM_REPLACESEL on Win9x,
672 // but EM_STREAMIN works
673 if ( wxUsingUnicowsDll() && GetRichVersion() > 1 )
675 done
= StreamIn(valueDos
, wxFONTENCODING_SYSTEM
, selectionOnly
);
677 #endif // wxUSE_UNICODE_MSLU
679 #if !wxUSE_UNICODE && !defined(__WXWINE__)
680 // next check if the text we're inserting must be shown in a non
681 // default charset -- this only works for RichEdit > 1.0
682 if ( GetRichVersion() > 1 )
684 wxFont font
= m_defaultStyle
.GetFont();
690 wxFontEncoding encoding
= font
.GetEncoding();
691 if ( encoding
!= wxFONTENCODING_SYSTEM
)
693 done
= StreamIn(valueDos
, encoding
, selectionOnly
);
697 #endif // !wxUSE_UNICODE
701 #endif // wxUSE_RICHEDIT
704 // rich edit text control sends us 2 EN_CHANGE events when we send
705 // WM_SETTEXT to it, we have to suppress one of them to make wxTextCtrl
706 // behaviour consistent
709 m_suppressNextUpdate
= TRUE
;
711 #endif // wxUSE_RICHEDIT
713 ::SendMessage(GetHwnd(), selectionOnly
? EM_REPLACESEL
: WM_SETTEXT
,
714 0, (LPARAM
)valueDos
.c_str());
720 void wxTextCtrl::AppendText(const wxString
& text
)
722 SetInsertionPointEnd();
727 void wxTextCtrl::Clear()
729 ::SetWindowText(GetHwnd(), wxT(""));
733 #endif // wxUSE_RICHEDIT
735 // rich edit controls send EN_UPDATE from WM_SETTEXT handler themselves
736 // but the normal ones don't -- make Clear() behaviour consistent by
737 // always sending this event
744 bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
748 size_t lenOld
= GetValue().length();
750 wxUint32 code
= event
.GetRawKeyCode();
751 ::keybd_event(code
, 0, 0 /* key press */, 0);
752 ::keybd_event(code
, 0, KEYEVENTF_KEYUP
, 0);
754 // assume that any alphanumeric key changes the total number of characters
755 // in the control - this should work in 99% of cases
756 return GetValue().length() != lenOld
;
761 // ----------------------------------------------------------------------------
762 // Clipboard operations
763 // ----------------------------------------------------------------------------
765 void wxTextCtrl::Copy()
769 ::SendMessage(GetHwnd(), WM_COPY
, 0, 0L);
773 void wxTextCtrl::Cut()
777 ::SendMessage(GetHwnd(), WM_CUT
, 0, 0L);
781 void wxTextCtrl::Paste()
785 ::SendMessage(GetHwnd(), WM_PASTE
, 0, 0L);
789 bool wxTextCtrl::CanCopy() const
791 // Can copy if there's a selection
793 GetSelection(&from
, &to
);
797 bool wxTextCtrl::CanCut() const
799 return CanCopy() && IsEditable();
802 bool wxTextCtrl::CanPaste() const
810 UINT cf
= 0; // 0 == any format
812 return ::SendMessage(GetHwnd(), EM_CANPASTE
, cf
, 0) != 0;
814 #endif // wxUSE_RICHEDIT
816 // Standard edit control: check for straight text on clipboard
817 if ( !::OpenClipboard(GetHwndOf(wxTheApp
->GetTopWindow())) )
820 bool isTextAvailable
= ::IsClipboardFormatAvailable(CF_TEXT
) != 0;
823 return isTextAvailable
;
826 // ----------------------------------------------------------------------------
828 // ----------------------------------------------------------------------------
830 void wxTextCtrl::SetEditable(bool editable
)
832 HWND hWnd
= GetHwnd();
833 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
836 void wxTextCtrl::SetInsertionPoint(long pos
)
838 DoSetSelection(pos
, pos
);
841 void wxTextCtrl::SetInsertionPointEnd()
846 if ( m_verRichEdit
== 1 )
848 // we don't have to waste time calling GetLastPosition() in this case
851 else // !RichEdit 1.0
852 #endif // wxUSE_RICHEDIT
854 pos
= GetLastPosition();
857 SetInsertionPoint(pos
);
860 long wxTextCtrl::GetInsertionPoint() const
868 SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
871 #endif // wxUSE_RICHEDIT
873 DWORD Pos
= (DWORD
)SendMessage(GetHwnd(), EM_GETSEL
, 0, 0L);
877 long wxTextCtrl::GetLastPosition() const
879 int numLines
= GetNumberOfLines();
880 long posStartLastLine
= XYToPosition(0, numLines
- 1);
882 long lenLastLine
= GetLengthOfLineContainingPos(posStartLastLine
);
884 return posStartLastLine
+ lenLastLine
;
887 // If the return values from and to are the same, there is no
889 void wxTextCtrl::GetSelection(long* from
, long* to
) const
895 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &charRange
);
897 *from
= charRange
.cpMin
;
898 *to
= charRange
.cpMax
;
901 #endif // !wxUSE_RICHEDIT
903 DWORD dwStart
, dwEnd
;
904 ::SendMessage(GetHwnd(), EM_GETSEL
, (WPARAM
)&dwStart
, (LPARAM
)&dwEnd
);
911 bool wxTextCtrl::IsEditable() const
913 // strangely enough, we may be called before the control is created: our
914 // own Create() calls MSWGetStyle() which calls AcceptsFocus() which calls
919 long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
921 return (style
& ES_READONLY
) == 0;
924 // ----------------------------------------------------------------------------
926 // ----------------------------------------------------------------------------
928 void wxTextCtrl::SetSelection(long from
, long to
)
930 // if from and to are both -1, it means (in wxWindows) that all text should
931 // be selected - translate into Windows convention
932 if ( (from
== -1) && (to
== -1) )
938 DoSetSelection(from
, to
);
941 void wxTextCtrl::DoSetSelection(long from
, long to
, bool scrollCaret
)
943 HWND hWnd
= GetHwnd();
952 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
955 #endif // wxUSE_RICHEDIT
957 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)from
, (LPARAM
)to
);
962 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
965 // WPARAM is 0: selection is scrolled into view
966 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(from
, to
));
970 // ----------------------------------------------------------------------------
972 // ----------------------------------------------------------------------------
974 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
976 // Set selection and remove it
977 DoSetSelection(from
, to
, FALSE
/* don't scroll caret into view */);
979 SendMessage(GetHwnd(), EM_REPLACESEL
,
985 (LPARAM
)value
.c_str());
988 void wxTextCtrl::Remove(long from
, long to
)
990 Replace(from
, to
, _T(""));
993 bool wxTextCtrl::LoadFile(const wxString
& file
)
995 if ( wxTextCtrlBase::LoadFile(file
) )
997 // update the size limit if needed
1006 bool wxTextCtrl::IsModified() const
1008 return SendMessage(GetHwnd(), EM_GETMODIFY
, 0, 0) != 0;
1011 // Makes 'unmodified'
1012 void wxTextCtrl::DiscardEdits()
1014 SendMessage(GetHwnd(), EM_SETMODIFY
, FALSE
, 0L);
1017 int wxTextCtrl::GetNumberOfLines() const
1019 return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
1022 long wxTextCtrl::XYToPosition(long x
, long y
) const
1024 // This gets the char index for the _beginning_ of this line
1025 long charIndex
= SendMessage(GetHwnd(), EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
1027 return charIndex
+ x
;
1030 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
1032 HWND hWnd
= GetHwnd();
1034 // This gets the line number containing the character
1039 lineNo
= SendMessage(hWnd
, EM_EXLINEFROMCHAR
, 0, (LPARAM
)pos
);
1042 #endif // wxUSE_RICHEDIT
1044 lineNo
= SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, 0);
1053 // This gets the char index for the _beginning_ of this line
1054 long charIndex
= SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
1055 if ( charIndex
== -1 )
1060 // The X position must therefore be the different between pos and charIndex
1062 *x
= pos
- charIndex
;
1069 void wxTextCtrl::ShowPosition(long pos
)
1071 HWND hWnd
= GetHwnd();
1073 // To scroll to a position, we pass the number of lines and characters
1074 // to scroll *by*. This means that we need to:
1075 // (1) Find the line position of the current line.
1076 // (2) Find the line position of pos.
1077 // (3) Scroll by (pos - current).
1078 // For now, ignore the horizontal scrolling.
1080 // Is this where scrolling is relative to - the line containing the caret?
1081 // Or is the first visible line??? Try first visible line.
1082 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
1084 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
1086 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
1088 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
1090 if (linesToScroll
!= 0)
1091 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)linesToScroll
);
1094 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
1096 return ::SendMessage(GetHwnd(), EM_LINELENGTH
, (WPARAM
)pos
, 0);
1099 int wxTextCtrl::GetLineLength(long lineNo
) const
1101 long pos
= XYToPosition(0, lineNo
);
1103 return GetLengthOfLineContainingPos(pos
);
1106 wxString
wxTextCtrl::GetLineText(long lineNo
) const
1108 size_t len
= (size_t)GetLineLength(lineNo
) + 1;
1110 // there must be at least enough place for the length WORD in the
1112 len
+= sizeof(WORD
);
1115 wxChar
*buf
= str
.GetWriteBuf(len
);
1117 *(WORD
*)buf
= (WORD
)len
;
1118 len
= (size_t)::SendMessage(GetHwnd(), EM_GETLINE
, lineNo
, (LPARAM
)buf
);
1121 str
.UngetWriteBuf(len
);
1126 void wxTextCtrl::SetMaxLength(unsigned long len
)
1128 ::SendMessage(GetHwnd(), EM_LIMITTEXT
, len
, 0);
1131 // ----------------------------------------------------------------------------
1133 // ----------------------------------------------------------------------------
1135 void wxTextCtrl::Undo()
1139 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
1143 void wxTextCtrl::Redo()
1147 // Same as Undo, since Undo undoes the undo, i.e. a redo.
1148 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
1152 bool wxTextCtrl::CanUndo() const
1154 return ::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0;
1157 bool wxTextCtrl::CanRedo() const
1159 return ::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0;
1162 // ----------------------------------------------------------------------------
1163 // implemenation details
1164 // ----------------------------------------------------------------------------
1166 void wxTextCtrl::Command(wxCommandEvent
& event
)
1168 SetValue(event
.GetString());
1169 ProcessCommand (event
);
1172 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
1174 // By default, load the first file into the text window.
1175 if (event
.GetNumberOfFiles() > 0)
1177 LoadFile(event
.GetFiles()[0]);
1181 // ----------------------------------------------------------------------------
1182 // kbd input processing
1183 // ----------------------------------------------------------------------------
1185 bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG
* pMsg
)
1187 MSG
*msg
= (MSG
*)pMsg
;
1189 // check for our special keys here: if we don't do it and the parent frame
1190 // uses them as accelerators, they wouldn't work at all, so we disable
1191 // usual preprocessing for them
1192 if ( msg
->message
== WM_KEYDOWN
)
1194 WORD vkey
= (WORD
) msg
->wParam
;
1195 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1197 if ( vkey
== VK_BACK
)
1202 // we want to process some Ctrl-foo and Shift-bar but no key
1203 // combinations without either Ctrl or Shift nor with both of them
1205 const int ctrl
= wxIsCtrlDown(),
1206 shift
= wxIsShiftDown();
1207 switch ( ctrl
+ shift
)
1210 wxFAIL_MSG( _T("how many modifiers have we got?") );
1218 // either Ctrl or Shift pressed
1233 else // Shift is pressed
1235 if ( vkey
== VK_INSERT
|| vkey
== VK_DELETE
)
1242 return wxControl::MSWShouldPreProcessMessage(pMsg
);
1245 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
1247 switch ( event
.KeyCode() )
1250 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1252 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1253 InitCommandEvent(event
);
1254 event
.SetString(GetValue());
1255 if ( GetEventHandler()->ProcessEvent(event
) )
1258 //else: multiline controls need Enter for themselves
1263 // always produce navigation event - even if we process TAB
1264 // ourselves the fact that we got here means that the user code
1265 // decided to skip processing of this TAB - probably to let it
1266 // do its default job.
1268 wxNavigationKeyEvent eventNav
;
1269 eventNav
.SetDirection(!event
.ShiftDown());
1270 eventNav
.SetWindowChange(event
.ControlDown());
1271 eventNav
.SetEventObject(this);
1273 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
1279 // no, we didn't process it
1283 long wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1285 long lRc
= wxTextCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
1287 if ( nMsg
== WM_GETDLGCODE
)
1291 // we always want the chars and the arrows
1292 long lDlgCode
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
1294 // we may have several different cases:
1295 // 1. normal case: both TAB and ENTER are used for dlg navigation
1296 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the
1297 // next control in the dialog
1298 // 3. ctrl which wants ENTER for itself: TAB is used for dialog
1300 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to go
1301 // to the next control
1303 // the multiline edit control should always get <Return> for itself
1304 if ( HasFlag(wxTE_PROCESS_ENTER
) || HasFlag(wxTE_MULTILINE
) )
1305 lDlgCode
|= DLGC_WANTMESSAGE
;
1307 if ( HasFlag(wxTE_PROCESS_TAB
) )
1308 lDlgCode
|= DLGC_WANTTAB
;
1314 // when the control can't be edited by user, it doesn't need any
1315 // extra keys at all
1323 // ----------------------------------------------------------------------------
1324 // text control event processing
1325 // ----------------------------------------------------------------------------
1327 bool wxTextCtrl::SendUpdateEvent()
1329 // is event reporting suspended?
1330 if ( m_suppressNextUpdate
)
1332 // do process the next one
1333 m_suppressNextUpdate
= FALSE
;
1338 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, GetId());
1339 InitCommandEvent(event
);
1340 event
.SetString(GetValue());
1342 return ProcessCommand(event
);
1345 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1352 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1355 event
.SetEventObject(this);
1356 GetEventHandler()->ProcessEvent(event
);
1365 // the text size limit has been hit -- try to increase it
1366 if ( !AdjustSpaceLimit() )
1368 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, m_windowId
);
1369 InitCommandEvent(event
);
1370 event
.SetString(GetValue());
1371 ProcessCommand(event
);
1375 // the other edit notification messages are not processed
1384 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
1390 WXUINT
WXUNUSED(message
),
1391 WXWPARAM
WXUNUSED(wParam
),
1392 WXLPARAM
WXUNUSED(lParam
)
1399 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
1400 return (WXHBRUSH
) hbrush
;
1402 #endif // wxUSE_CTL3D
1405 if (GetParent()->GetTransparentBackground())
1406 SetBkMode(hdc
, TRANSPARENT
);
1408 SetBkMode(hdc
, OPAQUE
);
1410 wxColour colBack
= GetBackgroundColour();
1412 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1413 colBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1415 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
1416 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
1418 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
1420 return (WXHBRUSH
)brush
->GetResourceHandle();
1423 // In WIN16, need to override normal erasing because
1424 // Ctl3D doesn't use the wxWindows background colour.
1426 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
1428 wxColour
col(m_backgroundColour
);
1432 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1436 ::GetClientRect(GetHwnd(), &rect
);
1438 COLORREF ref
= wxColourToRGB(col
);
1439 HBRUSH hBrush
= ::CreateSolidBrush(ref
);
1441 wxLogLastError(wxT("CreateSolidBrush"));
1443 HDC hdc
= (HDC
)event
.GetDC()->GetHDC();
1445 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
1447 ::FillRect(hdc
, &rect
, hBrush
);
1448 ::DeleteObject(hBrush
);
1449 ::SetMapMode(hdc
, mode
);
1454 bool wxTextCtrl::AdjustSpaceLimit()
1457 unsigned int limit
= ::SendMessage(GetHwnd(), EM_GETLIMITTEXT
, 0, 0);
1459 // HACK: we try to automatically extend the limit for the amount of text
1460 // to allow (interactively) entering more than 64Kb of text under
1461 // Win9x but we shouldn't reset the text limit which was previously
1462 // set explicitly with SetMaxLength()
1464 // we could solve this by storing the limit we set in wxTextCtrl but
1465 // to save space we prefer to simply test here the actual limit
1466 // value: we consider that SetMaxLength() can only be called for
1468 if ( limit
< 0x8000 )
1470 // we've got more text than limit set by SetMaxLength()
1474 unsigned int len
= ::GetWindowTextLength(GetHwnd());
1477 limit
= len
+ 0x8000; // 32Kb
1482 // as a nice side effect, this also allows passing limit > 64Kb
1483 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT
, 0, limit
);
1486 #endif // wxUSE_RICHEDIT
1488 if ( limit
> 0xffff )
1490 // this will set it to a platform-dependent maximum (much more
1491 // than 64Kb under NT)
1495 ::SendMessage(GetHwnd(), EM_LIMITTEXT
, limit
, 0);
1500 // we changed the limit
1504 bool wxTextCtrl::AcceptsFocus() const
1506 // we don't want focus if we can't be edited
1507 return IsEditable() && wxControl::AcceptsFocus();
1510 wxSize
wxTextCtrl::DoGetBestSize() const
1513 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
1515 int wText
= DEFAULT_ITEM_WIDTH
;
1517 int hText
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
1518 if ( m_windowStyle
& wxTE_MULTILINE
)
1520 hText
*= wxMax(GetNumberOfLines(), 5);
1522 //else: for single line control everything is ok
1524 return wxSize(wText
, hText
);
1527 // ----------------------------------------------------------------------------
1528 // standard handlers for standard edit menu events
1529 // ----------------------------------------------------------------------------
1531 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1536 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1541 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1546 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1551 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1556 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1558 event
.Enable( CanCut() );
1561 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1563 event
.Enable( CanCopy() );
1566 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1568 event
.Enable( CanPaste() );
1571 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1573 event
.Enable( CanUndo() );
1576 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1578 event
.Enable( CanRedo() );
1581 // the rest of the file only deals with the rich edit controls
1584 // ----------------------------------------------------------------------------
1585 // EN_LINK processing
1586 // ----------------------------------------------------------------------------
1588 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1591 NMHDR
*hdr
= (NMHDR
* )lParam
;
1592 switch ( hdr
->code
)
1596 const MSGFILTER
*msgf
= (MSGFILTER
*)lParam
;
1597 UINT msg
= msgf
->msg
;
1599 // this is a bit crazy but richedit 1.0 sends us all mouse
1600 // events _except_ WM_LBUTTONUP (don't ask me why) so we have
1601 // generate the wxWin events for this message manually
1603 // NB: in fact, this is still not totally correct as it does
1604 // send us WM_LBUTTONUP if the selection was cleared by the
1605 // last click -- so currently we get 2 events in this case,
1606 // but as I don't see any obvious way to check for this I
1607 // leave this code in place because it's still better than
1608 // not getting left up events at all
1609 if ( msg
== WM_LBUTTONUP
)
1611 WXUINT flags
= msgf
->wParam
;
1612 int x
= GET_X_LPARAM(msgf
->lParam
),
1613 y
= GET_Y_LPARAM(msgf
->lParam
);
1615 HandleMouseEvent(msg
, x
, y
, flags
);
1619 // return TRUE to process the event (and FALSE to ignore it)
1624 const ENLINK
*enlink
= (ENLINK
*)hdr
;
1626 switch ( enlink
->msg
)
1629 // ok, so it is hardcoded - do we really nee to
1631 ::SetCursor(GetHcursorOf(wxCursor(wxCURSOR_HAND
)));
1636 case WM_LBUTTONDOWN
:
1638 case WM_LBUTTONDBLCLK
:
1639 case WM_RBUTTONDOWN
:
1641 case WM_RBUTTONDBLCLK
:
1642 // send a mouse event
1644 static const wxEventType eventsMouse
[] =
1655 // the event ids are consecutive
1657 evtMouse(eventsMouse
[enlink
->msg
- WM_MOUSEMOVE
]);
1659 InitMouseEvent(evtMouse
,
1660 GET_X_LPARAM(enlink
->lParam
),
1661 GET_Y_LPARAM(enlink
->lParam
),
1664 wxTextUrlEvent
event(m_windowId
, evtMouse
,
1666 enlink
->chrg
.cpMax
);
1668 InitCommandEvent(event
);
1670 *result
= ProcessCommand(event
);
1679 // not processed, leave it to the base class
1680 return wxTextCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
1683 // ----------------------------------------------------------------------------
1684 // colour setting for the rich edit controls
1685 // ----------------------------------------------------------------------------
1687 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
1689 if ( !wxTextCtrlBase::SetBackgroundColour(colour
) )
1691 // colour didn't really change
1697 // rich edit doesn't use WM_CTLCOLOR, hence we need to send
1698 // EM_SETBKGNDCOLOR additionally
1699 ::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR
, 0, wxColourToRGB(colour
));
1705 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
1707 if ( !wxTextCtrlBase::SetForegroundColour(colour
) )
1709 // colour didn't really change
1715 // change the colour of everything
1718 cf
.cbSize
= sizeof(cf
);
1719 cf
.dwMask
= CFM_COLOR
;
1720 cf
.crTextColor
= wxColourToRGB(colour
);
1721 ::SendMessage(GetHwnd(), EM_SETCHARFORMAT
, SCF_ALL
, (LPARAM
)&cf
);
1727 // ----------------------------------------------------------------------------
1728 // styling support for rich edit controls
1729 // ----------------------------------------------------------------------------
1733 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
1740 // can't do it with normal text control
1744 // the richedit 1.0 doesn't handle setting background colour, so don't
1745 // even try to do anything if it's the only thing we want to change
1746 if ( m_verRichEdit
== 1 && !style
.HasFont() && !style
.HasTextColour() )
1748 // nothing to do: return TRUE if there was really nothing to do and
1749 // FALSE if we failed to set bg colour
1750 return !style
.HasBackgroundColour();
1753 // order the range if needed
1761 // we can only change the format of the selection, so select the range we
1762 // want and restore the old selection later
1763 long startOld
, endOld
;
1764 GetSelection(&startOld
, &endOld
);
1766 // but do we really have to change the selection?
1767 bool changeSel
= start
!= startOld
|| end
!= endOld
;
1771 DoSetSelection(start
, end
, FALSE
/* don't scroll caret into view */);
1774 // initialize CHARFORMAT struct
1783 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
1784 // CHARFORMAT in that case
1786 if ( m_verRichEdit
== 1 )
1788 // this is the only thing the control is going to grok
1789 cf
.cbSize
= sizeof(CHARFORMAT
);
1794 // CHARFORMAT or CHARFORMAT2
1795 cf
.cbSize
= sizeof(cf
);
1798 if ( style
.HasFont() )
1800 // VZ: CFM_CHARSET doesn't seem to do anything at all in RichEdit 2.0
1801 // but using it doesn't seem to hurt neither so leaving it for now
1803 cf
.dwMask
|= CFM_FACE
| CFM_SIZE
| CFM_CHARSET
|
1804 CFM_ITALIC
| CFM_BOLD
| CFM_UNDERLINE
;
1806 // fill in data from LOGFONT but recalculate lfHeight because we need
1807 // the real height in twips and not the negative number which
1808 // wxFillLogFont() returns (this is correct in general and works with
1809 // the Windows font mapper, but not here)
1811 wxFillLogFont(&lf
, &style
.GetFont());
1812 cf
.yHeight
= 20*style
.GetFont().GetPointSize(); // 1 pt = 20 twips
1813 cf
.bCharSet
= lf
.lfCharSet
;
1814 cf
.bPitchAndFamily
= lf
.lfPitchAndFamily
;
1815 wxStrncpy( cf
.szFaceName
, lf
.lfFaceName
, WXSIZEOF(cf
.szFaceName
) );
1817 // also deal with underline/italic/bold attributes: note that we must
1818 // always set CFM_ITALIC &c bits in dwMask, even if we don't set the
1819 // style to allow clearing it
1822 cf
.dwEffects
|= CFE_ITALIC
;
1825 if ( lf
.lfWeight
== FW_BOLD
)
1827 cf
.dwEffects
|= CFE_BOLD
;
1830 if ( lf
.lfUnderline
)
1832 cf
.dwEffects
|= CFE_UNDERLINE
;
1835 // strikeout fonts are not supported by wxWindows
1838 if ( style
.HasTextColour() )
1840 cf
.dwMask
|= CFM_COLOR
;
1841 cf
.crTextColor
= wxColourToRGB(style
.GetTextColour());
1845 if ( m_verRichEdit
!= 1 && style
.HasBackgroundColour() )
1847 cf
.dwMask
|= CFM_BACKCOLOR
;
1848 cf
.crBackColor
= wxColourToRGB(style
.GetBackgroundColour());
1850 #endif // wxUSE_RICHEDIT2
1852 // do format the selection
1853 bool ok
= ::SendMessage(GetHwnd(), EM_SETCHARFORMAT
,
1854 SCF_SELECTION
, (LPARAM
)&cf
) != 0;
1857 wxLogDebug(_T("SendMessage(EM_SETCHARFORMAT, SCF_SELECTION) failed"));
1862 // restore the original selection
1863 DoSetSelection(startOld
, endOld
, FALSE
);
1870 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
1872 if ( !wxTextCtrlBase::SetDefaultStyle(style
) )
1875 // we have to do this or the style wouldn't apply for the text typed by the
1877 long posLast
= GetLastPosition();
1878 SetStyle(posLast
, posLast
, m_defaultStyle
);
1885 // ----------------------------------------------------------------------------
1887 // ----------------------------------------------------------------------------
1889 bool wxRichEditModule::OnInit()
1891 // don't do anything - we will load it when needed
1895 void wxRichEditModule::OnExit()
1897 for ( size_t i
= 0; i
< WXSIZEOF(ms_hRichEdit
); i
++ )
1899 if ( ms_hRichEdit
[i
] )
1901 ::FreeLibrary(ms_hRichEdit
[i
]);
1907 bool wxRichEditModule::Load(int version
)
1909 // we don't support loading richedit 3.0 as I don't know how to distinguish
1910 // it from 2.0 anyhow
1911 wxCHECK_MSG( version
== 1 || version
== 2, FALSE
,
1912 _T("incorrect richedit control version requested") );
1914 // make it the index in the array
1917 if ( ms_hRichEdit
[version
] == (HINSTANCE
)-1 )
1919 // we had already tried to load it and failed
1923 if ( ms_hRichEdit
[version
] )
1925 // we've already got this one
1929 wxString dllname
= version
? _T("riched20") : _T("riched32");
1930 dllname
+= _T(".dll");
1932 ms_hRichEdit
[version
] = ::LoadLibrary(dllname
);
1934 if ( !ms_hRichEdit
[version
] )
1936 wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname
.c_str());
1938 ms_hRichEdit
[version
] = (HINSTANCE
)-1;
1946 #endif // wxUSE_RICHEDIT
1948 #endif // wxUSE_TEXTCTRL