1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/textctrl.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma implementation "textctrl.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_TEXTCTRL && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
34 #include "wx/textctrl.h"
35 #include "wx/settings.h"
45 #include "wx/module.h"
48 #include "wx/clipbrd.h"
51 #include "wx/textfile.h"
55 #include "wx/msw/private.h"
56 #include "wx/msw/winundef.h"
62 #include <sys/types.h>
67 // old mingw32 has richedit stuff directly in windows.h and doesn't have
69 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
73 #include "wx/msw/missing.h"
75 #endif // wxUSE_RICHEDIT
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
83 // this module initializes RichEdit DLL(s) if needed
84 class wxRichEditModule
: public wxModule
87 virtual bool OnInit();
88 virtual void OnExit();
90 // load the richedit DLL of at least of required version
91 static bool Load(int version
= 1);
94 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
95 static HINSTANCE ms_hRichEdit
[2];
97 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
100 HINSTANCE
wxRichEditModule::ms_hRichEdit
[2] = { NULL
, NULL
};
102 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
104 #endif // wxUSE_RICHEDIT
106 // a small class used to set m_updatesCount to 0 (to filter duplicate events if
107 // necessary) and to reset it back to -1 afterwards
108 class UpdatesCountFilter
111 UpdatesCountFilter(int& count
)
114 wxASSERT_MSG( m_count
== -1, _T("wrong initial m_updatesCount value") );
119 ~UpdatesCountFilter()
124 // return true if an event has been received
125 bool GotUpdate() const
133 DECLARE_NO_COPY_CLASS(UpdatesCountFilter
)
136 // ----------------------------------------------------------------------------
137 // event tables and other macros
138 // ----------------------------------------------------------------------------
140 #if wxUSE_EXTENDED_RTTI
141 WX_DEFINE_FLAGS( wxTextCtrlStyle
)
143 wxBEGIN_FLAGS( wxTextCtrlStyle
)
144 // new style border flags, we put them first to
145 // use them for streaming out
146 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
147 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
148 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
149 wxFLAGS_MEMBER(wxBORDER_RAISED
)
150 wxFLAGS_MEMBER(wxBORDER_STATIC
)
151 wxFLAGS_MEMBER(wxBORDER_NONE
)
153 // old style border flags
154 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
155 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
156 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
157 wxFLAGS_MEMBER(wxRAISED_BORDER
)
158 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
159 wxFLAGS_MEMBER(wxBORDER
)
161 // standard window styles
162 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
163 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
164 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
165 wxFLAGS_MEMBER(wxWANTS_CHARS
)
166 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
167 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
168 wxFLAGS_MEMBER(wxVSCROLL
)
169 wxFLAGS_MEMBER(wxHSCROLL
)
171 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER
)
172 wxFLAGS_MEMBER(wxTE_PROCESS_TAB
)
173 wxFLAGS_MEMBER(wxTE_MULTILINE
)
174 wxFLAGS_MEMBER(wxTE_PASSWORD
)
175 wxFLAGS_MEMBER(wxTE_READONLY
)
176 wxFLAGS_MEMBER(wxHSCROLL
)
177 wxFLAGS_MEMBER(wxTE_RICH
)
178 wxFLAGS_MEMBER(wxTE_RICH2
)
179 wxFLAGS_MEMBER(wxTE_AUTO_URL
)
180 wxFLAGS_MEMBER(wxTE_NOHIDESEL
)
181 wxFLAGS_MEMBER(wxTE_LEFT
)
182 wxFLAGS_MEMBER(wxTE_CENTRE
)
183 wxFLAGS_MEMBER(wxTE_RIGHT
)
184 wxFLAGS_MEMBER(wxTE_DONTWRAP
)
185 wxFLAGS_MEMBER(wxTE_LINEWRAP
)
186 wxFLAGS_MEMBER(wxTE_WORDWRAP
)
188 wxEND_FLAGS( wxTextCtrlStyle
)
190 IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl
, wxControl
,"wx/textctrl.h")
192 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl
)
193 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
194 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
196 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
197 wxPROPERTY( Value
, wxString
, SetValue
, GetValue
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
198 wxPROPERTY_FLAGS( WindowStyle
, wxTextCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
199 wxEND_PROPERTIES_TABLE()
201 wxBEGIN_HANDLERS_TABLE(wxTextCtrl
)
202 wxEND_HANDLERS_TABLE()
204 wxCONSTRUCTOR_6( wxTextCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
206 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
210 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
211 EVT_CHAR(wxTextCtrl::OnChar
)
212 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
215 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
218 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
219 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
220 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
221 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
222 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
223 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
224 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
226 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
227 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
228 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
229 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
230 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
231 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
232 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
234 EVT_SET_FOCUS(wxTextCtrl::OnSetFocus
)
237 // ============================================================================
239 // ============================================================================
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
245 void wxTextCtrl::Init()
249 #endif // wxUSE_RICHEDIT
251 m_privateContextMenu
= NULL
;
253 m_isNativeCaretShown
= true;
256 wxTextCtrl::~wxTextCtrl()
258 delete m_privateContextMenu
;
261 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
262 const wxString
& value
,
266 const wxValidator
& validator
,
267 const wxString
& name
)
270 if ((style
& wxBORDER_MASK
) == 0)
271 style
|= wxBORDER_SIMPLE
;
274 // base initialization
275 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
278 // translate wxWin style flags to MSW ones
279 WXDWORD msStyle
= MSWGetCreateWindowFlags();
281 // do create the control - either an EDIT or RICHEDIT
282 wxString windowClass
= wxT("EDIT");
284 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
285 // A control that capitalizes the first letter
286 if (style
& wxTE_CAPITALIZE
)
287 windowClass
= wxT("CAPEDIT");
291 if ( m_windowStyle
& wxTE_AUTO_URL
)
293 // automatic URL detection only works in RichEdit 2.0+
294 m_windowStyle
|= wxTE_RICH2
;
297 if ( m_windowStyle
& wxTE_RICH2
)
299 // using richedit 2.0 implies using wxTE_RICH
300 m_windowStyle
|= wxTE_RICH
;
303 // we need to load the richedit DLL before creating the rich edit control
304 if ( m_windowStyle
& wxTE_RICH
)
306 static bool s_errorGiven
= false;// MT-FIXME
308 // Which version do we need? Use 1.0 by default because it is much more
309 // like the the standard EDIT or 2.0 if explicitly requested, but use
310 // only 2.0 in Unicode mode as 1.0 doesn't support Unicode at all
312 // TODO: RichEdit 3.0 is apparently capable of emulating RichEdit 1.0
313 // (and thus EDIT) much better than RichEdit 2.0 so we probably
314 // should use 3.0 if available as it is the best of both worlds -
315 // but as I can't test it right now I don't do it (VZ)
317 const int verRichEdit
= 2;
318 #else // !wxUSE_UNICODE
319 int verRichEdit
= m_windowStyle
& wxTE_RICH2
? 2 : 1;
320 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
322 // only give the error msg once if the DLL can't be loaded
325 // try to load the RichEdit DLL (will do nothing if already done)
326 if ( !wxRichEditModule::Load(verRichEdit
) )
329 // try another version?
330 verRichEdit
= 3 - verRichEdit
; // 1 <-> 2
332 if ( !wxRichEditModule::Load(verRichEdit
) )
333 #endif // wxUSE_UNICODE
335 wxLogError(_("Impossible to create a rich edit control, using simple text control instead. Please reinstall riched32.dll"));
342 // have we managed to load any richedit version?
345 m_verRichEdit
= verRichEdit
;
346 if ( m_verRichEdit
== 1 )
348 windowClass
= wxT("RICHEDIT");
352 #ifndef RICHEDIT_CLASS
353 wxString RICHEDIT_CLASS
;
354 RICHEDIT_CLASS
.Printf(_T("RichEdit%d0"), m_verRichEdit
);
356 RICHEDIT_CLASS
+= _T('W');
358 RICHEDIT_CLASS
+= _T('A');
359 #endif // Unicode/ANSI
360 #endif // !RICHEDIT_CLASS
362 windowClass
= RICHEDIT_CLASS
;
366 #endif // wxUSE_RICHEDIT
368 // we need to turn '\n's into "\r\n"s for the multiline controls
370 if ( m_windowStyle
& wxTE_MULTILINE
)
372 valueWin
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
379 if ( !MSWCreateControl(windowClass
, msStyle
, pos
, size
, valueWin
) )
385 // enable the events we're interested in: we want to get EN_CHANGE as
386 // for the normal controls
387 LPARAM mask
= ENM_CHANGE
;
389 if ( GetRichVersion() == 1 )
391 // we also need EN_MSGFILTER for richedit 1.0 for the reasons
392 // explained in its handler
393 mask
|= ENM_MOUSEEVENTS
;
395 else if ( m_windowStyle
& wxTE_AUTO_URL
)
399 ::SendMessage(GetHwnd(), EM_AUTOURLDETECT
, TRUE
, 0);
402 ::SendMessage(GetHwnd(), EM_SETEVENTMASK
, 0, mask
);
404 #endif // wxUSE_RICHEDIT
409 // Make sure the window style (etc.) reflects the HWND style (roughly)
410 void wxTextCtrl::AdoptAttributesFromHWND()
412 wxWindow::AdoptAttributesFromHWND();
414 HWND hWnd
= GetHwnd();
415 long style
= ::GetWindowLong(hWnd
, GWL_STYLE
);
417 // retrieve the style to see whether this is an edit or richedit ctrl
419 wxString classname
= wxGetWindowClass(GetHWND());
421 if ( classname
.IsSameAs(_T("EDIT"), false /* no case */) )
428 if ( wxSscanf(classname
, _T("RichEdit%d0%c"), &m_verRichEdit
, &c
) != 2 )
430 wxLogDebug(_T("Unknown edit control '%s'."), classname
.c_str());
435 #endif // wxUSE_RICHEDIT
437 if (style
& ES_MULTILINE
)
438 m_windowStyle
|= wxTE_MULTILINE
;
439 if (style
& ES_PASSWORD
)
440 m_windowStyle
|= wxTE_PASSWORD
;
441 if (style
& ES_READONLY
)
442 m_windowStyle
|= wxTE_READONLY
;
443 if (style
& ES_WANTRETURN
)
444 m_windowStyle
|= wxTE_PROCESS_ENTER
;
445 if (style
& ES_CENTER
)
446 m_windowStyle
|= wxTE_CENTRE
;
447 if (style
& ES_RIGHT
)
448 m_windowStyle
|= wxTE_RIGHT
;
451 WXDWORD
wxTextCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
453 long msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
455 // styles which we alaways add by default
456 if ( style
& wxTE_MULTILINE
)
458 wxASSERT_MSG( !(style
& wxTE_PROCESS_ENTER
),
459 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
461 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
;
462 if ( !(style
& wxTE_NO_VSCROLL
) )
464 // always adjust the vertical scrollbar automatically if we have it
465 msStyle
|= WS_VSCROLL
| ES_AUTOVSCROLL
;
468 // we have to use this style for the rich edit controls because
469 // without it the vertical scrollbar never appears at all in
470 // richedit 3.0 because of our ECO_NOHIDESEL hack (search for it)
471 if ( style
& wxTE_RICH2
)
473 msStyle
|= ES_DISABLENOSCROLL
;
475 #endif // wxUSE_RICHEDIT
478 style
|= wxTE_PROCESS_ENTER
;
482 // there is really no reason to not have this style for single line
484 msStyle
|= ES_AUTOHSCROLL
;
487 // note that wxTE_DONTWRAP is the same as wxHSCROLL so if we have a horz
488 // scrollbar, there is no wrapping -- which makes sense
489 if ( style
& wxTE_DONTWRAP
)
491 // automatically scroll the control horizontally as necessary
493 // NB: ES_AUTOHSCROLL is needed for richedit controls or they don't
494 // show horz scrollbar at all, even in spite of WS_HSCROLL, and as
495 // it doesn't seem to do any harm for plain edit controls, add it
497 msStyle
|= WS_HSCROLL
| ES_AUTOHSCROLL
;
500 if ( style
& wxTE_READONLY
)
501 msStyle
|= ES_READONLY
;
503 if ( style
& wxTE_PASSWORD
)
504 msStyle
|= ES_PASSWORD
;
506 if ( style
& wxTE_NOHIDESEL
)
507 msStyle
|= ES_NOHIDESEL
;
509 // note that we can't do do "& wxTE_LEFT" as wxTE_LEFT == 0
510 if ( style
& wxTE_CENTRE
)
511 msStyle
|= ES_CENTER
;
512 else if ( style
& wxTE_RIGHT
)
515 msStyle
|= ES_LEFT
; // ES_LEFT is 0 as well but for consistency...
520 void wxTextCtrl::SetWindowStyleFlag(long style
)
523 // we have to deal with some styles separately because they can't be
524 // changed by simply calling SetWindowLong(GWL_STYLE) but can be changed
525 // using richedit-specific EM_SETOPTIONS
527 ((style
& wxTE_NOHIDESEL
) != (GetWindowStyle() & wxTE_NOHIDESEL
)) )
529 bool set
= (style
& wxTE_NOHIDESEL
) != 0;
531 ::SendMessage(GetHwnd(), EM_SETOPTIONS
, set
? ECOOP_OR
: ECOOP_AND
,
532 set
? ECO_NOHIDESEL
: ~ECO_NOHIDESEL
);
534 #endif // wxUSE_RICHEDIT
536 wxControl::SetWindowStyleFlag(style
);
539 // ----------------------------------------------------------------------------
540 // set/get the controls text
541 // ----------------------------------------------------------------------------
543 wxString
wxTextCtrl::GetValue() const
545 // range 0..-1 is special for GetRange() and means to retrieve all text
546 return GetRange(0, -1);
549 wxString
wxTextCtrl::GetRange(long from
, long to
) const
553 if ( from
>= to
&& to
!= -1 )
555 // nothing to retrieve
562 int len
= GetWindowTextLength(GetHwnd());
569 // we must use EM_STREAMOUT if we don't want to lose all characters
570 // not representable in the current character set (EM_GETTEXTRANGE
571 // simply replaces them with question marks...)
572 if ( GetRichVersion() > 1 )
574 // we must have some encoding, otherwise any 8bit chars in the
575 // control are simply *lost* (replaced by '?')
576 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
;
578 wxFont font
= m_defaultStyle
.GetFont();
584 encoding
= font
.GetEncoding();
587 if ( encoding
== wxFONTENCODING_SYSTEM
)
589 encoding
= wxLocale::GetSystemEncoding();
592 if ( encoding
== wxFONTENCODING_SYSTEM
)
594 encoding
= wxFONTENCODING_ISO8859_1
;
597 str
= StreamOut(encoding
);
601 // we have to manually extract the required part, luckily
602 // this is easy in this case as EOL characters in str are
603 // just LFs because we remove CRs in wxRichEditStreamOut
604 str
= str
.Mid(from
, to
- from
);
608 // StreamOut() wasn't used or failed, try to do it in normal way
610 #endif // !wxUSE_UNICODE
612 // alloc one extra WORD as needed by the control
613 wxStringBuffer
tmp(str
, ++len
);
617 textRange
.chrg
.cpMin
= from
;
618 textRange
.chrg
.cpMax
= to
;
619 textRange
.lpstrText
= p
;
621 (void)::SendMessage(GetHwnd(), EM_GETTEXTRANGE
,
622 0, (LPARAM
)&textRange
);
624 if ( m_verRichEdit
> 1 )
626 // RichEdit 2.0 uses just CR ('\r') for the
627 // newlines which is neither Unix nor Windows
628 // style - convert it to something reasonable
631 if ( *p
== _T('\r') )
637 if ( m_verRichEdit
== 1 )
639 // convert to the canonical form - see comment below
640 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
643 //else: no text at all, leave the string empty
646 #endif // wxUSE_RICHEDIT
649 str
= wxGetWindowText(GetHWND());
651 // need only a range?
654 str
= str
.Mid(from
, to
- from
);
657 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
658 // canonical one (same one as above) for consistency with the other kinds
659 // of controls and, more importantly, with the other ports
660 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
666 void wxTextCtrl::SetValue(const wxString
& value
)
668 // if the text is long enough, it's faster to just set it instead of first
669 // comparing it with the old one (chances are that it will be different
670 // anyhow, this comparison is there to avoid flicker for small single-line
671 // edit controls mostly)
672 if ( (value
.length() > 0x400) || (value
!= GetValue()) )
674 DoWriteText(value
, false /* not selection only */);
676 // for compatibility, don't move the cursor when doing SetValue()
677 SetInsertionPoint(0);
681 // still send an event for consistency
685 // we should reset the modified flag even if the value didn't really change
687 // mark the control as being not dirty - we changed its text, not the
692 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
694 // TODO: using memcpy() would improve performance a lot for big amounts of text
697 wxRichEditStreamIn(DWORD dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
701 const wchar_t ** const ppws
= (const wchar_t **)dwCookie
;
703 wchar_t *wbuf
= (wchar_t *)buf
;
704 const wchar_t *wpc
= *ppws
;
709 cb
-= sizeof(wchar_t);
710 (*pcb
) += sizeof(wchar_t);
718 // helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut
719 struct wxStreamOutData
726 wxRichEditStreamOut(DWORD_PTR dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
730 wxStreamOutData
*data
= (wxStreamOutData
*)dwCookie
;
732 const wchar_t *wbuf
= (const wchar_t *)buf
;
733 wchar_t *wpc
= data
->wpc
;
736 wchar_t wch
= *wbuf
++;
738 // turn "\r\n" into "\n" on the fly
744 cb
-= sizeof(wchar_t);
745 (*pcb
) += sizeof(wchar_t);
754 #if wxUSE_UNICODE_MSLU
755 #define UNUSED_IF_MSLU(param)
757 #define UNUSED_IF_MSLU(param) param
761 wxTextCtrl::StreamIn(const wxString
& value
,
762 wxFontEncoding
UNUSED_IF_MSLU(encoding
),
765 #if wxUSE_UNICODE_MSLU
766 const wchar_t *wpc
= value
.c_str();
767 #else // !wxUSE_UNICODE_MSLU
768 wxCSConv
conv(encoding
);
770 const size_t len
= conv
.MB2WC(NULL
, value
, value
.length());
773 wxWCharBuffer
wchBuf(len
);
774 wchar_t *wpc
= wchBuf
.data();
776 wchar_t *wchBuf
= (wchar_t *)malloc((len
+ 1)*sizeof(wchar_t));
777 wchar_t *wpc
= wchBuf
;
780 conv
.MB2WC(wpc
, value
, value
.length());
781 #endif // wxUSE_UNICODE_MSLU
783 // finally, stream it in the control
786 eds
.dwCookie
= (DWORD
)&wpc
;
787 // the cast below is needed for broken (very) old mingw32 headers
788 eds
.pfnCallback
= (EDITSTREAMCALLBACK
)wxRichEditStreamIn
;
790 // same problem as in DoWriteText(): we can get multiple events here
791 UpdatesCountFilter
ucf(m_updatesCount
);
793 ::SendMessage(GetHwnd(), EM_STREAMIN
,
796 (selectionOnly
? SFF_SELECTION
: 0),
799 wxASSERT_MSG( ucf
.GotUpdate(), _T("EM_STREAMIN didn't send EN_UPDATE?") );
803 wxLogLastError(_T("EM_STREAMIN"));
808 #endif // !wxUSE_WCHAR_T
813 #if !wxUSE_UNICODE_MSLU
816 wxTextCtrl::StreamOut(wxFontEncoding encoding
, bool selectionOnly
) const
820 const int len
= GetWindowTextLength(GetHwnd());
823 wxWCharBuffer
wchBuf(len
);
824 wchar_t *wpc
= wchBuf
.data();
826 wchar_t *wchBuf
= (wchar_t *)malloc((len
+ 1)*sizeof(wchar_t));
827 wchar_t *wpc
= wchBuf
;
830 wxStreamOutData data
;
836 eds
.dwCookie
= (DWORD
)&data
;
837 eds
.pfnCallback
= wxRichEditStreamOut
;
843 SF_TEXT
| SF_UNICODE
| (selectionOnly
? SFF_SELECTION
: 0),
849 wxLogLastError(_T("EM_STREAMOUT"));
851 else // streamed out ok
853 // NUL-terminate the string because its length could have been
854 // decreased by wxRichEditStreamOut
855 *(wchBuf
.data() + data
.len
) = L
'\0';
857 // now convert to the given encoding (this is a possibly lossful
858 // conversion but what else can we do)
859 wxCSConv
conv(encoding
);
860 size_t lenNeeded
= conv
.WC2MB(NULL
, wchBuf
, 0);
863 conv
.WC2MB(wxStringBuffer(out
, lenNeeded
), wchBuf
, lenNeeded
);
869 #endif // !wxUSE_WCHAR_T
874 #endif // !wxUSE_UNICODE_MSLU
876 #endif // wxUSE_RICHEDIT
878 void wxTextCtrl::WriteText(const wxString
& value
)
883 void wxTextCtrl::DoWriteText(const wxString
& value
, bool selectionOnly
)
886 if ( m_windowStyle
& wxTE_MULTILINE
)
887 valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
892 // there are several complications with the rich edit controls here
896 // first, ensure that the new text will be in the default style
897 if ( !m_defaultStyle
.IsDefault() )
900 GetSelection(&start
, &end
);
901 SetStyle(start
, end
, m_defaultStyle
);
904 #if wxUSE_UNICODE_MSLU
905 // RichEdit doesn't have Unicode version of EM_REPLACESEL on Win9x,
906 // but EM_STREAMIN works
907 if ( wxUsingUnicowsDll() && GetRichVersion() > 1 )
909 done
= StreamIn(valueDos
, wxFONTENCODING_SYSTEM
, selectionOnly
);
911 #endif // wxUSE_UNICODE_MSLU
914 // next check if the text we're inserting must be shown in a non
915 // default charset -- this only works for RichEdit > 1.0
916 if ( GetRichVersion() > 1 )
918 wxFont font
= m_defaultStyle
.GetFont();
924 wxFontEncoding encoding
= font
.GetEncoding();
925 if ( encoding
!= wxFONTENCODING_SYSTEM
)
927 // we have to use EM_STREAMIN to force richedit control 2.0+
928 // to show any text in the non default charset -- otherwise
929 // it thinks it knows better than we do and always shows it
930 // in the default one
931 done
= StreamIn(valueDos
, encoding
, selectionOnly
);
935 #endif // !wxUSE_UNICODE
939 #endif // wxUSE_RICHEDIT
941 // in some cases we get 2 EN_CHANGE notifications after the SendMessage
942 // call (this happens for plain EDITs with EM_REPLACESEL and under some
943 // -- undetermined -- conditions with rich edit) and sometimes we don't
944 // get any events at all (plain EDIT with WM_SETTEXT), so ensure that
945 // we generate exactly one of them by ignoring all but the first one in
946 // SendUpdateEvent() and generating one ourselves if we hadn't got any
947 // notifications from Windows
948 UpdatesCountFilter
ucf(m_updatesCount
);
950 ::SendMessage(GetHwnd(), selectionOnly
? EM_REPLACESEL
: WM_SETTEXT
,
951 0, (LPARAM
)valueDos
.c_str());
953 if ( !ucf
.GotUpdate() )
960 void wxTextCtrl::AppendText(const wxString
& text
)
962 SetInsertionPointEnd();
967 // don't do this if we're frozen, saves some time
968 if ( !IsFrozen() && IsMultiLine() && GetRichVersion() > 1 )
970 // setting the caret to the end and showing it simply doesn't work for
971 // RichEdit 2.0 -- force it to still do what we want
972 ::SendMessage(GetHwnd(), EM_LINESCROLL
, 0, GetNumberOfLines());
974 #endif // wxUSE_RICHEDIT
977 void wxTextCtrl::Clear()
979 ::SetWindowText(GetHwnd(), wxEmptyString
);
983 #endif // wxUSE_RICHEDIT
985 // rich edit controls send EN_UPDATE from WM_SETTEXT handler themselves
986 // but the normal ones don't -- make Clear() behaviour consistent by
987 // always sending this event
989 // Windows already sends an update event for single-line
991 if ( m_windowStyle
& wxTE_MULTILINE
)
998 bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
1002 size_t lenOld
= GetValue().length();
1004 wxUint32 code
= event
.GetRawKeyCode();
1005 ::keybd_event((BYTE
)code
, 0, 0 /* key press */, 0);
1006 ::keybd_event((BYTE
)code
, 0, KEYEVENTF_KEYUP
, 0);
1008 // assume that any alphanumeric key changes the total number of characters
1009 // in the control - this should work in 99% of cases
1010 return GetValue().length() != lenOld
;
1015 // ----------------------------------------------------------------------------
1016 // Clipboard operations
1017 // ----------------------------------------------------------------------------
1019 void wxTextCtrl::Copy()
1023 ::SendMessage(GetHwnd(), WM_COPY
, 0, 0L);
1027 void wxTextCtrl::Cut()
1031 ::SendMessage(GetHwnd(), WM_CUT
, 0, 0L);
1035 void wxTextCtrl::Paste()
1039 ::SendMessage(GetHwnd(), WM_PASTE
, 0, 0L);
1043 bool wxTextCtrl::HasSelection() const
1046 GetSelection(&from
, &to
);
1050 bool wxTextCtrl::CanCopy() const
1052 // Can copy if there's a selection
1053 return HasSelection();
1056 bool wxTextCtrl::CanCut() const
1058 return CanCopy() && IsEditable();
1061 bool wxTextCtrl::CanPaste() const
1063 if ( !IsEditable() )
1069 UINT cf
= 0; // 0 == any format
1071 return ::SendMessage(GetHwnd(), EM_CANPASTE
, cf
, 0) != 0;
1073 #endif // wxUSE_RICHEDIT
1075 // Standard edit control: check for straight text on clipboard
1076 if ( !::OpenClipboard(GetHwndOf(wxTheApp
->GetTopWindow())) )
1079 bool isTextAvailable
= ::IsClipboardFormatAvailable(CF_TEXT
) != 0;
1082 return isTextAvailable
;
1085 // ----------------------------------------------------------------------------
1087 // ----------------------------------------------------------------------------
1089 void wxTextCtrl::SetEditable(bool editable
)
1091 HWND hWnd
= GetHwnd();
1092 ::SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
1095 void wxTextCtrl::SetInsertionPoint(long pos
)
1097 DoSetSelection(pos
, pos
);
1100 void wxTextCtrl::SetInsertionPointEnd()
1102 // we must not do anything if the caret is already there because calling
1103 // SetInsertionPoint() thaws the controls if Freeze() had been called even
1104 // if it doesn't actually move the caret anywhere and so the simple fact of
1105 // doing it results in horrible flicker when appending big amounts of text
1106 // to the control in a few chunks (see DoAddText() test in the text sample)
1107 if ( GetInsertionPoint() == GetLastPosition() )
1115 if ( m_verRichEdit
== 1 )
1117 // we don't have to waste time calling GetLastPosition() in this case
1120 else // !RichEdit 1.0
1121 #endif // wxUSE_RICHEDIT
1123 pos
= GetLastPosition();
1126 SetInsertionPoint(pos
);
1129 long wxTextCtrl::GetInsertionPoint() const
1137 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
1140 #endif // wxUSE_RICHEDIT
1142 DWORD Pos
= (DWORD
)::SendMessage(GetHwnd(), EM_GETSEL
, 0, 0L);
1143 return Pos
& 0xFFFF;
1146 wxTextPos
wxTextCtrl::GetLastPosition() const
1148 int numLines
= GetNumberOfLines();
1149 long posStartLastLine
= XYToPosition(0, numLines
- 1);
1151 long lenLastLine
= GetLengthOfLineContainingPos(posStartLastLine
);
1153 return posStartLastLine
+ lenLastLine
;
1156 // If the return values from and to are the same, there is no
1158 void wxTextCtrl::GetSelection(long* from
, long* to
) const
1163 CHARRANGE charRange
;
1164 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &charRange
);
1166 *from
= charRange
.cpMin
;
1167 *to
= charRange
.cpMax
;
1170 #endif // !wxUSE_RICHEDIT
1172 DWORD dwStart
, dwEnd
;
1173 ::SendMessage(GetHwnd(), EM_GETSEL
, (WPARAM
)&dwStart
, (LPARAM
)&dwEnd
);
1180 bool wxTextCtrl::IsEditable() const
1182 // strangely enough, we may be called before the control is created: our
1183 // own Create() calls MSWGetStyle() which calls AcceptsFocus() which calls
1188 long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1190 return (style
& ES_READONLY
) == 0;
1193 // ----------------------------------------------------------------------------
1195 // ----------------------------------------------------------------------------
1197 void wxTextCtrl::SetSelection(long from
, long to
)
1199 // if from and to are both -1, it means (in wxWidgets) that all text should
1200 // be selected - translate into Windows convention
1201 if ( (from
== -1) && (to
== -1) )
1207 DoSetSelection(from
, to
);
1210 void wxTextCtrl::DoSetSelection(long from
, long to
, bool scrollCaret
)
1212 HWND hWnd
= GetHwnd();
1220 ::SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
1223 #endif // wxUSE_RICHEDIT
1225 ::SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)from
, (LPARAM
)to
);
1228 if ( scrollCaret
&& !IsFrozen() )
1231 // richedit 3.0 (i.e. the version living in riched20.dll distributed
1232 // with Windows 2000 and beyond) doesn't honour EM_SCROLLCARET when
1233 // emulating richedit 2.0 unless the control has focus or ECO_NOHIDESEL
1234 // option is set (but it does work ok in richedit 1.0 mode...)
1236 // so to make it work we either need to give focus to it here which
1237 // will probably create many problems (dummy focus events; window
1238 // containing the text control being brought to foreground
1239 // unexpectedly; ...) or to temporarily set ECO_NOHIDESEL which may
1240 // create other problems too -- and in fact it does because if we turn
1241 // on/off this style while appending the text to the control, the
1242 // vertical scrollbar never appears in it even if we append tons of
1243 // text and to work around this the only solution I found was to use
1244 // ES_DISABLENOSCROLL
1246 // this is very ugly but I don't see any other way to make this work
1247 if ( GetRichVersion() > 1 )
1249 if ( !HasFlag(wxTE_NOHIDESEL
) )
1251 ::SendMessage(GetHwnd(), EM_SETOPTIONS
,
1252 ECOOP_OR
, ECO_NOHIDESEL
);
1254 //else: everything is already ok
1256 #endif // wxUSE_RICHEDIT
1258 ::SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
1261 // restore ECO_NOHIDESEL if we changed it
1262 if ( GetRichVersion() > 1 && !HasFlag(wxTE_NOHIDESEL
) )
1264 ::SendMessage(GetHwnd(), EM_SETOPTIONS
,
1265 ECOOP_AND
, ~ECO_NOHIDESEL
);
1267 #endif // wxUSE_RICHEDIT
1271 // ----------------------------------------------------------------------------
1272 // Working with files
1273 // ----------------------------------------------------------------------------
1275 bool wxTextCtrl::LoadFile(const wxString
& file
)
1277 if ( wxTextCtrlBase::LoadFile(file
) )
1279 // update the size limit if needed
1288 // ----------------------------------------------------------------------------
1290 // ----------------------------------------------------------------------------
1292 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
1294 // Set selection and remove it
1295 DoSetSelection(from
, to
, false /* don't scroll caret into view */);
1297 DoWriteText(value
, true /* selection only */);
1300 void wxTextCtrl::Remove(long from
, long to
)
1302 Replace(from
, to
, wxEmptyString
);
1305 bool wxTextCtrl::IsModified() const
1307 return ::SendMessage(GetHwnd(), EM_GETMODIFY
, 0, 0) != 0;
1310 void wxTextCtrl::MarkDirty()
1312 ::SendMessage(GetHwnd(), EM_SETMODIFY
, TRUE
, 0L);
1315 void wxTextCtrl::DiscardEdits()
1317 ::SendMessage(GetHwnd(), EM_SETMODIFY
, FALSE
, 0L);
1320 int wxTextCtrl::GetNumberOfLines() const
1322 return (int)::SendMessage(GetHwnd(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
1325 // ----------------------------------------------------------------------------
1326 // Positions <-> coords
1327 // ----------------------------------------------------------------------------
1329 long wxTextCtrl::XYToPosition(long x
, long y
) const
1331 // This gets the char index for the _beginning_ of this line
1332 long charIndex
= ::SendMessage(GetHwnd(), EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
1334 return charIndex
+ x
;
1337 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
1339 HWND hWnd
= GetHwnd();
1341 // This gets the line number containing the character
1346 lineNo
= ::SendMessage(hWnd
, EM_EXLINEFROMCHAR
, 0, (LPARAM
)pos
);
1349 #endif // wxUSE_RICHEDIT
1351 lineNo
= ::SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, 0);
1360 // This gets the char index for the _beginning_ of this line
1361 long charIndex
= ::SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
1362 if ( charIndex
== -1 )
1367 // The X position must therefore be the different between pos and charIndex
1369 *x
= pos
- charIndex
;
1376 wxTextCtrlHitTestResult
1377 wxTextCtrl::HitTest(const wxPoint
& pt
, long *posOut
) const
1379 // first get the position from Windows
1386 // for rich edit controls the position is passed iva the struct fields
1389 lParam
= (LPARAM
)&ptl
;
1392 #endif // wxUSE_RICHEDIT
1394 // for the plain ones, we are limited to 16 bit positions which are
1395 // combined in a single 32 bit value
1396 lParam
= MAKELPARAM(pt
.x
, pt
.y
);
1399 LRESULT pos
= ::SendMessage(GetHwnd(), EM_CHARFROMPOS
, 0, lParam
);
1403 // this seems to indicate an error...
1404 return wxTE_HT_UNKNOWN
;
1409 #endif // wxUSE_RICHEDIT
1411 // for plain EDIT controls the higher word contains something else
1416 // next determine where it is relatively to our point: EM_CHARFROMPOS
1417 // always returns the closest character but we need to be more precise, so
1418 // double check that we really are where it pretends
1422 // FIXME: we need to distinguish between richedit 2 and 3 here somehow but
1423 // we don't know how to do it
1426 ::SendMessage(GetHwnd(), EM_POSFROMCHAR
, (WPARAM
)&ptReal
, pos
);
1429 #endif // wxUSE_RICHEDIT
1431 LRESULT lRc
= ::SendMessage(GetHwnd(), EM_POSFROMCHAR
, pos
, 0);
1435 // this is apparently returned when pos corresponds to the last
1442 ptReal
.x
= LOWORD(lRc
);
1443 ptReal
.y
= HIWORD(lRc
);
1447 wxTextCtrlHitTestResult rc
;
1449 if ( pt
.y
> ptReal
.y
+ GetCharHeight() )
1451 else if ( pt
.x
> ptReal
.x
+ GetCharWidth() )
1452 rc
= wxTE_HT_BEYOND
;
1454 rc
= wxTE_HT_ON_TEXT
;
1462 // ----------------------------------------------------------------------------
1464 // ----------------------------------------------------------------------------
1466 void wxTextCtrl::ShowPosition(long pos
)
1468 HWND hWnd
= GetHwnd();
1470 // To scroll to a position, we pass the number of lines and characters
1471 // to scroll *by*. This means that we need to:
1472 // (1) Find the line position of the current line.
1473 // (2) Find the line position of pos.
1474 // (3) Scroll by (pos - current).
1475 // For now, ignore the horizontal scrolling.
1477 // Is this where scrolling is relative to - the line containing the caret?
1478 // Or is the first visible line??? Try first visible line.
1479 // int currentLineLineNo1 = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
1481 int currentLineLineNo
= (int)::SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
1483 int specifiedLineLineNo
= (int)::SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
1485 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
1487 if (linesToScroll
!= 0)
1488 (void)::SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)linesToScroll
);
1491 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
1493 return ::SendMessage(GetHwnd(), EM_LINELENGTH
, (WPARAM
)pos
, 0);
1496 int wxTextCtrl::GetLineLength(long lineNo
) const
1498 long pos
= XYToPosition(0, lineNo
);
1500 return GetLengthOfLineContainingPos(pos
);
1503 wxString
wxTextCtrl::GetLineText(long lineNo
) const
1505 size_t len
= (size_t)GetLineLength(lineNo
) + 1;
1507 // there must be at least enough place for the length WORD in the
1509 len
+= sizeof(WORD
);
1513 wxStringBufferLength
tmp(str
, len
);
1516 *(WORD
*)buf
= (WORD
)len
;
1517 len
= (size_t)::SendMessage(GetHwnd(), EM_GETLINE
, lineNo
, (LPARAM
)buf
);
1522 // remove the '\r' returned by the rich edit control, the user code
1523 // should never see it
1524 if ( buf
[len
- 2] == _T('\r') && buf
[len
- 1] == _T('\n') )
1526 buf
[len
- 2] = _T('\n');
1530 #endif // wxUSE_RICHEDIT
1532 // remove the '\n' at the end, if any (this is how this function is
1533 // supposed to work according to the docs)
1534 if ( buf
[len
- 1] == _T('\n') )
1546 void wxTextCtrl::SetMaxLength(unsigned long len
)
1550 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT
, 0, (LPARAM
) (DWORD
) len
);
1553 ::SendMessage(GetHwnd(), EM_LIMITTEXT
, len
, 0);
1556 // ----------------------------------------------------------------------------
1558 // ----------------------------------------------------------------------------
1560 void wxTextCtrl::Undo()
1564 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
1568 void wxTextCtrl::Redo()
1573 if (GetRichVersion() > 1)
1574 ::SendMessage(GetHwnd(), EM_REDO
, 0, 0);
1577 // Same as Undo, since Undo undoes the undo, i.e. a redo.
1578 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
1582 bool wxTextCtrl::CanUndo() const
1584 return ::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0;
1587 bool wxTextCtrl::CanRedo() const
1590 if (GetRichVersion() > 1)
1591 return ::SendMessage(GetHwnd(), EM_CANREDO
, 0, 0) != 0;
1594 return ::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0;
1597 // ----------------------------------------------------------------------------
1598 // caret handling (Windows only)
1599 // ----------------------------------------------------------------------------
1601 bool wxTextCtrl::ShowNativeCaret(bool show
)
1603 if ( show
!= m_isNativeCaretShown
)
1605 if ( !(show
? ::ShowCaret(GetHwnd()) : ::HideCaret(GetHwnd())) )
1607 // not an error, may simply indicate that it's not shown/hidden
1608 // yet (i.e. it had been hidden/showh 2 times before)
1612 m_isNativeCaretShown
= show
;
1618 // ----------------------------------------------------------------------------
1619 // implemenation details
1620 // ----------------------------------------------------------------------------
1622 void wxTextCtrl::Command(wxCommandEvent
& event
)
1624 SetValue(event
.GetString());
1625 ProcessCommand (event
);
1628 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
1630 // By default, load the first file into the text window.
1631 if (event
.GetNumberOfFiles() > 0)
1633 LoadFile(event
.GetFiles()[0]);
1637 // ----------------------------------------------------------------------------
1638 // kbd input processing
1639 // ----------------------------------------------------------------------------
1641 bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG
* pMsg
)
1643 MSG
*msg
= (MSG
*)pMsg
;
1645 // check for our special keys here: if we don't do it and the parent frame
1646 // uses them as accelerators, they wouldn't work at all, so we disable
1647 // usual preprocessing for them
1648 if ( msg
->message
== WM_KEYDOWN
)
1650 WORD vkey
= (WORD
) msg
->wParam
;
1651 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1653 if ( vkey
== VK_BACK
)
1658 // we want to process some Ctrl-foo and Shift-bar but no key
1659 // combinations without either Ctrl or Shift nor with both of them
1661 const int ctrl
= wxIsCtrlDown(),
1662 shift
= wxIsShiftDown();
1663 switch ( ctrl
+ shift
)
1666 wxFAIL_MSG( _T("how many modifiers have we got?") );
1674 // either Ctrl or Shift pressed
1689 else // Shift is pressed
1691 if ( vkey
== VK_INSERT
|| vkey
== VK_DELETE
)
1698 return wxControl::MSWShouldPreProcessMessage(pMsg
);
1701 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
1703 switch ( event
.GetKeyCode() )
1706 if ( !HasFlag(wxTE_MULTILINE
) )
1708 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1709 InitCommandEvent(event
);
1710 event
.SetString(GetValue());
1711 if ( GetEventHandler()->ProcessEvent(event
) )
1714 //else: multiline controls need Enter for themselves
1719 // ok, so this is getting absolutely ridiculous but I don't see
1720 // any other way to fix this bug: when a multiline text control is
1721 // inside a wxFrame, we need to generate the navigation event as
1722 // otherwise nothing happens at all, but when the same control is
1723 // created inside a dialog, IsDialogMessage() *does* switch focus
1724 // all by itself and so if we do it here as well, it is advanced
1725 // twice and goes to the next control... to prevent this from
1726 // happening we're doing this ugly check, the logic being that if
1727 // we don't have focus then it had been already changed to the next
1730 // the right thing to do would, of course, be to understand what
1731 // the hell is IsDialogMessage() doing but this is beyond my feeble
1732 // forces at the moment unfortunately
1733 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
1735 if ( FindFocus() == this )
1738 if (!event
.ShiftDown())
1739 flags
|= wxNavigationKeyEvent::IsForward
;
1740 if (event
.ControlDown())
1741 flags
|= wxNavigationKeyEvent::WinChange
;
1742 if (Navigate(flags
))
1748 // Insert tab since calling the default Windows handler
1749 // doesn't seem to do it
1750 WriteText(wxT("\t"));
1755 // no, we didn't process it
1759 WXLRESULT
wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1761 WXLRESULT lRc
= wxTextCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
1763 if ( nMsg
== WM_GETDLGCODE
)
1765 // we always want the chars and the arrows: the arrows for navigation
1766 // and the chars because we want Ctrl-C to work even in a read only
1768 long lDlgCode
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
1772 // we may have several different cases:
1773 // 1. normal case: both TAB and ENTER are used for dlg navigation
1774 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the
1775 // next control in the dialog
1776 // 3. ctrl which wants ENTER for itself: TAB is used for dialog
1778 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to go
1779 // to the next control
1781 // the multiline edit control should always get <Return> for itself
1782 if ( HasFlag(wxTE_PROCESS_ENTER
) || HasFlag(wxTE_MULTILINE
) )
1783 lDlgCode
|= DLGC_WANTMESSAGE
;
1785 if ( HasFlag(wxTE_PROCESS_TAB
) )
1786 lDlgCode
|= DLGC_WANTTAB
;
1792 // NB: use "=", not "|=" as the base class version returns the
1793 // same flags is this state as usual (i.e. including
1794 // DLGC_WANTMESSAGE). This is strange (how does it work in the
1795 // native Win32 apps?) but for now live with it.
1803 // ----------------------------------------------------------------------------
1804 // text control event processing
1805 // ----------------------------------------------------------------------------
1807 bool wxTextCtrl::SendUpdateEvent()
1809 switch ( m_updatesCount
)
1812 // remember that we've got an update
1817 // we had already sent one event since the last control modification
1821 wxFAIL_MSG( _T("unexpected wxTextCtrl::m_updatesCount value") );
1825 // we hadn't updated the control ourselves, this event comes from
1826 // the user, don't need to ignore it nor update the count
1830 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, GetId());
1831 InitCommandEvent(event
);
1833 return ProcessCommand(event
);
1836 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1843 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1846 event
.SetEventObject(this);
1847 GetEventHandler()->ProcessEvent(event
);
1856 // the text size limit has been hit -- try to increase it
1857 if ( !AdjustSpaceLimit() )
1859 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, m_windowId
);
1860 InitCommandEvent(event
);
1861 event
.SetString(GetValue());
1862 ProcessCommand(event
);
1866 // the other edit notification messages are not processed
1875 WXHBRUSH
wxTextCtrl::MSWControlColor(WXHDC hDC
)
1877 if ( !IsEnabled() && !HasFlag(wxTE_MULTILINE
) )
1878 return MSWControlColorDisabled(hDC
);
1880 return wxTextCtrlBase::MSWControlColorSolid(hDC
);
1883 bool wxTextCtrl::AdjustSpaceLimit()
1885 unsigned int limit
= ::SendMessage(GetHwnd(), EM_GETLIMITTEXT
, 0, 0);
1887 // HACK: we try to automatically extend the limit for the amount of text
1888 // to allow (interactively) entering more than 64Kb of text under
1889 // Win9x but we shouldn't reset the text limit which was previously
1890 // set explicitly with SetMaxLength()
1892 // we could solve this by storing the limit we set in wxTextCtrl but
1893 // to save space we prefer to simply test here the actual limit
1894 // value: we consider that SetMaxLength() can only be called for
1896 if ( limit
< 0x8000 )
1898 // we've got more text than limit set by SetMaxLength()
1902 unsigned int len
= ::GetWindowTextLength(GetHwnd());
1905 limit
= len
+ 0x8000; // 32Kb
1910 // as a nice side effect, this also allows passing limit > 64Kb
1911 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT
, 0, limit
);
1914 #endif // wxUSE_RICHEDIT
1916 if ( limit
> 0xffff )
1918 // this will set it to a platform-dependent maximum (much more
1919 // than 64Kb under NT)
1923 ::SendMessage(GetHwnd(), EM_LIMITTEXT
, limit
, 0);
1927 // we changed the limit
1931 bool wxTextCtrl::AcceptsFocus() const
1933 // we don't want focus if we can't be edited unless we're a multiline
1934 // control because then it might be still nice to get focus from keyboard
1935 // to be able to scroll it without mouse
1936 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
1939 wxSize
wxTextCtrl::DoGetBestSize() const
1942 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
1944 int wText
= DEFAULT_ITEM_WIDTH
;
1947 if ( m_windowStyle
& wxTE_MULTILINE
)
1949 hText
*= wxMax(GetNumberOfLines(), 5);
1951 //else: for single line control everything is ok
1953 // we have to add the adjustments for the control height only once, not
1954 // once per line, so do it after multiplication above
1955 hText
+= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
) - cy
;
1957 return wxSize(wText
, hText
);
1960 // ----------------------------------------------------------------------------
1961 // standard handlers for standard edit menu events
1962 // ----------------------------------------------------------------------------
1964 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1969 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1974 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1979 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1984 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1989 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
1992 GetSelection(& from
, & to
);
1993 if (from
!= -1 && to
!= -1)
1997 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
1999 SetSelection(-1, -1);
2002 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
2004 event
.Enable( CanCut() );
2007 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
2009 event
.Enable( CanCopy() );
2012 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
2014 event
.Enable( CanPaste() );
2017 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
2019 event
.Enable( CanUndo() );
2022 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
2024 event
.Enable( CanRedo() );
2027 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
2030 GetSelection(& from
, & to
);
2031 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
2034 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
2036 event
.Enable(GetLastPosition() > 0);
2039 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
2044 if (!m_privateContextMenu
)
2046 m_privateContextMenu
= new wxMenu
;
2047 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
2048 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
2049 m_privateContextMenu
->AppendSeparator();
2050 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
2051 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
2052 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
2053 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
2054 m_privateContextMenu
->AppendSeparator();
2055 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
2057 PopupMenu(m_privateContextMenu
);
2065 void wxTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
2067 // be sure the caret remains invisible if the user had hidden it
2068 if ( !m_isNativeCaretShown
)
2070 ::HideCaret(GetHwnd());
2074 // ----------------------------------------------------------------------------
2075 // Default colors for MSW text control
2077 // Set default background color to the native white instead of
2078 // the default wxSYS_COLOUR_BTNFACE (is triggered with wxNullColour).
2079 // ----------------------------------------------------------------------------
2081 wxVisualAttributes
wxTextCtrl::GetDefaultAttributes() const
2083 wxVisualAttributes attrs
;
2084 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
2085 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
2086 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
); //white
2091 // the rest of the file only deals with the rich edit controls
2094 // ----------------------------------------------------------------------------
2095 // EN_LINK processing
2096 // ----------------------------------------------------------------------------
2098 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
2100 NMHDR
*hdr
= (NMHDR
* )lParam
;
2101 switch ( hdr
->code
)
2105 const MSGFILTER
*msgf
= (MSGFILTER
*)lParam
;
2106 UINT msg
= msgf
->msg
;
2108 // this is a bit crazy but richedit 1.0 sends us all mouse
2109 // events _except_ WM_LBUTTONUP (don't ask me why) so we have
2110 // generate the wxWin events for this message manually
2112 // NB: in fact, this is still not totally correct as it does
2113 // send us WM_LBUTTONUP if the selection was cleared by the
2114 // last click -- so currently we get 2 events in this case,
2115 // but as I don't see any obvious way to check for this I
2116 // leave this code in place because it's still better than
2117 // not getting left up events at all
2118 if ( msg
== WM_LBUTTONUP
)
2120 WXUINT flags
= msgf
->wParam
;
2121 int x
= GET_X_LPARAM(msgf
->lParam
),
2122 y
= GET_Y_LPARAM(msgf
->lParam
);
2124 HandleMouseEvent(msg
, x
, y
, flags
);
2128 // return true to process the event (and false to ignore it)
2133 const ENLINK
*enlink
= (ENLINK
*)hdr
;
2135 switch ( enlink
->msg
)
2138 // ok, so it is hardcoded - do we really nee to
2141 wxCursor
cur(wxCURSOR_HAND
);
2142 ::SetCursor(GetHcursorOf(cur
));
2148 case WM_LBUTTONDOWN
:
2150 case WM_LBUTTONDBLCLK
:
2151 case WM_RBUTTONDOWN
:
2153 case WM_RBUTTONDBLCLK
:
2154 // send a mouse event
2156 static const wxEventType eventsMouse
[] =
2167 // the event ids are consecutive
2169 evtMouse(eventsMouse
[enlink
->msg
- WM_MOUSEMOVE
]);
2171 InitMouseEvent(evtMouse
,
2172 GET_X_LPARAM(enlink
->lParam
),
2173 GET_Y_LPARAM(enlink
->lParam
),
2176 wxTextUrlEvent
event(m_windowId
, evtMouse
,
2178 enlink
->chrg
.cpMax
);
2180 InitCommandEvent(event
);
2182 *result
= ProcessCommand(event
);
2190 // not processed, leave it to the base class
2191 return wxTextCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
2194 // ----------------------------------------------------------------------------
2195 // colour setting for the rich edit controls
2196 // ----------------------------------------------------------------------------
2198 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
2200 if ( !wxTextCtrlBase::SetBackgroundColour(colour
) )
2202 // colour didn't really change
2208 // rich edit doesn't use WM_CTLCOLOR, hence we need to send
2209 // EM_SETBKGNDCOLOR additionally
2210 ::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR
, 0, wxColourToRGB(colour
));
2216 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
2218 if ( !wxTextCtrlBase::SetForegroundColour(colour
) )
2220 // colour didn't really change
2226 // change the colour of everything
2229 cf
.cbSize
= sizeof(cf
);
2230 cf
.dwMask
= CFM_COLOR
;
2231 cf
.crTextColor
= wxColourToRGB(colour
);
2232 ::SendMessage(GetHwnd(), EM_SETCHARFORMAT
, SCF_ALL
, (LPARAM
)&cf
);
2238 // ----------------------------------------------------------------------------
2239 // styling support for rich edit controls
2240 // ----------------------------------------------------------------------------
2244 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
2248 // can't do it with normal text control
2252 // the richedit 1.0 doesn't handle setting background colour, so don't
2253 // even try to do anything if it's the only thing we want to change
2254 if ( m_verRichEdit
== 1 && !style
.HasFont() && !style
.HasTextColour() &&
2255 !style
.HasLeftIndent() && !style
.HasRightIndent() && !style
.HasAlignment() &&
2258 // nothing to do: return true if there was really nothing to do and
2259 // false if we failed to set bg colour
2260 return !style
.HasBackgroundColour();
2263 // order the range if needed
2271 // we can only change the format of the selection, so select the range we
2272 // want and restore the old selection later
2273 long startOld
, endOld
;
2274 GetSelection(&startOld
, &endOld
);
2276 // but do we really have to change the selection?
2277 bool changeSel
= start
!= startOld
|| end
!= endOld
;
2281 DoSetSelection(start
, end
, false /* don't scroll caret into view */);
2284 // initialize CHARFORMAT struct
2293 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
2294 // CHARFORMAT in that case
2296 if ( m_verRichEdit
== 1 )
2298 // this is the only thing the control is going to grok
2299 cf
.cbSize
= sizeof(CHARFORMAT
);
2304 // CHARFORMAT or CHARFORMAT2
2305 cf
.cbSize
= sizeof(cf
);
2308 if ( style
.HasFont() )
2310 // VZ: CFM_CHARSET doesn't seem to do anything at all in RichEdit 2.0
2311 // but using it doesn't seem to hurt neither so leaving it for now
2313 cf
.dwMask
|= CFM_FACE
| CFM_SIZE
| CFM_CHARSET
|
2314 CFM_ITALIC
| CFM_BOLD
| CFM_UNDERLINE
;
2316 // fill in data from LOGFONT but recalculate lfHeight because we need
2317 // the real height in twips and not the negative number which
2318 // wxFillLogFont() returns (this is correct in general and works with
2319 // the Windows font mapper, but not here)
2321 wxFillLogFont(&lf
, &style
.GetFont());
2322 cf
.yHeight
= 20*style
.GetFont().GetPointSize(); // 1 pt = 20 twips
2323 cf
.bCharSet
= lf
.lfCharSet
;
2324 cf
.bPitchAndFamily
= lf
.lfPitchAndFamily
;
2325 wxStrncpy( cf
.szFaceName
, lf
.lfFaceName
, WXSIZEOF(cf
.szFaceName
) );
2327 // also deal with underline/italic/bold attributes: note that we must
2328 // always set CFM_ITALIC &c bits in dwMask, even if we don't set the
2329 // style to allow clearing it
2332 cf
.dwEffects
|= CFE_ITALIC
;
2335 if ( lf
.lfWeight
== FW_BOLD
)
2337 cf
.dwEffects
|= CFE_BOLD
;
2340 if ( lf
.lfUnderline
)
2342 cf
.dwEffects
|= CFE_UNDERLINE
;
2345 // strikeout fonts are not supported by wxWidgets
2348 if ( style
.HasTextColour() )
2350 cf
.dwMask
|= CFM_COLOR
;
2351 cf
.crTextColor
= wxColourToRGB(style
.GetTextColour());
2355 if ( m_verRichEdit
!= 1 && style
.HasBackgroundColour() )
2357 cf
.dwMask
|= CFM_BACKCOLOR
;
2358 cf
.crBackColor
= wxColourToRGB(style
.GetBackgroundColour());
2360 #endif // wxUSE_RICHEDIT2
2362 // do format the selection
2363 bool ok
= ::SendMessage(GetHwnd(), EM_SETCHARFORMAT
,
2364 SCF_SELECTION
, (LPARAM
)&cf
) != 0;
2367 wxLogDebug(_T("SendMessage(EM_SETCHARFORMAT, SCF_SELECTION) failed"));
2370 // now do the paragraph formatting
2373 // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
2374 // PARAFORMAT in that case
2376 if ( m_verRichEdit
== 1 )
2378 // this is the only thing the control is going to grok
2379 pf
.cbSize
= sizeof(PARAFORMAT
);
2384 // PARAFORMAT or PARAFORMAT2
2385 pf
.cbSize
= sizeof(pf
);
2388 if (style
.HasAlignment())
2390 pf
.dwMask
|= PFM_ALIGNMENT
;
2391 if (style
.GetAlignment() == wxTEXT_ALIGNMENT_RIGHT
)
2392 pf
.wAlignment
= PFA_RIGHT
;
2393 else if (style
.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE
)
2394 pf
.wAlignment
= PFA_CENTER
;
2395 else if (style
.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED
)
2396 pf
.wAlignment
= PFA_JUSTIFY
;
2398 pf
.wAlignment
= PFA_LEFT
;
2401 if (style
.HasLeftIndent())
2403 pf
.dwMask
|= PFM_STARTINDENT
| PFM_OFFSET
;
2405 // Convert from 1/10 mm to TWIPS
2406 pf
.dxStartIndent
= (int) (((double) style
.GetLeftIndent()) * mm2twips
/ 10.0) ;
2407 pf
.dxOffset
= (int) (((double) style
.GetLeftSubIndent()) * mm2twips
/ 10.0) ;
2410 if (style
.HasRightIndent())
2412 pf
.dwMask
|= PFM_RIGHTINDENT
;
2414 // Convert from 1/10 mm to TWIPS
2415 pf
.dxRightIndent
= (int) (((double) style
.GetRightIndent()) * mm2twips
/ 10.0) ;
2418 if (style
.HasTabs())
2420 pf
.dwMask
|= PFM_TABSTOPS
;
2422 const wxArrayInt
& tabs
= style
.GetTabs();
2424 pf
.cTabCount
= (SHORT
)wxMin(tabs
.GetCount(), MAX_TAB_STOPS
);
2426 for (i
= 0; i
< (size_t) pf
.cTabCount
; i
++)
2428 // Convert from 1/10 mm to TWIPS
2429 pf
.rgxTabs
[i
] = (int) (((double) tabs
[i
]) * mm2twips
/ 10.0) ;
2435 // do format the selection
2436 bool ok
= ::SendMessage(GetHwnd(), EM_SETPARAFORMAT
,
2437 0, (LPARAM
) &pf
) != 0;
2440 wxLogDebug(_T("SendMessage(EM_SETPARAFORMAT, 0) failed"));
2446 // restore the original selection
2447 DoSetSelection(startOld
, endOld
, false);
2453 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
2455 if ( !wxTextCtrlBase::SetDefaultStyle(style
) )
2460 // we have to do this or the style wouldn't apply for the text typed by
2462 wxTextPos posLast
= GetLastPosition();
2463 SetStyle(posLast
, posLast
, m_defaultStyle
);
2469 bool wxTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
2473 // can't do it with normal text control
2477 // initialize CHARFORMAT struct
2486 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
2487 // CHARFORMAT in that case
2489 if ( m_verRichEdit
== 1 )
2491 // this is the only thing the control is going to grok
2492 cf
.cbSize
= sizeof(CHARFORMAT
);
2497 // CHARFORMAT or CHARFORMAT2
2498 cf
.cbSize
= sizeof(cf
);
2500 // we can only change the format of the selection, so select the range we
2501 // want and restore the old selection later
2502 long startOld
, endOld
;
2503 GetSelection(&startOld
, &endOld
);
2505 // but do we really have to change the selection?
2506 bool changeSel
= position
!= startOld
|| position
!= endOld
;
2510 DoSetSelection(position
, position
, false /* don't scroll caret into view */);
2513 // get the selection formatting
2514 (void) ::SendMessage(GetHwnd(), EM_GETCHARFORMAT
,
2515 SCF_SELECTION
, (LPARAM
)&cf
) ;
2519 lf
.lfHeight
= cf
.yHeight
;
2521 lf
.lfCharSet
= ANSI_CHARSET
; // FIXME: how to get correct charset?
2522 lf
.lfClipPrecision
= 0;
2523 lf
.lfEscapement
= 0;
2524 wxStrcpy(lf
.lfFaceName
, cf
.szFaceName
);
2526 //NOTE: we _MUST_ set each of these values to _something_ since we
2527 //do not call wxZeroMemory on the LOGFONT lf
2528 if (cf
.dwEffects
& CFE_ITALIC
)
2531 lf
.lfItalic
= FALSE
;
2533 lf
.lfOrientation
= 0;
2534 lf
.lfPitchAndFamily
= cf
.bPitchAndFamily
;
2537 if (cf
.dwEffects
& CFE_STRIKEOUT
)
2538 lf
.lfStrikeOut
= TRUE
;
2540 lf
.lfStrikeOut
= FALSE
;
2542 if (cf
.dwEffects
& CFE_UNDERLINE
)
2543 lf
.lfUnderline
= TRUE
;
2545 lf
.lfUnderline
= FALSE
;
2547 if (cf
.dwEffects
& CFE_BOLD
)
2548 lf
.lfWeight
= FW_BOLD
;
2550 lf
.lfWeight
= FW_NORMAL
;
2552 wxFont font
= wxCreateFontFromLogFont(& lf
);
2555 style
.SetFont(font
);
2557 style
.SetTextColour(wxColour(cf
.crTextColor
));
2560 if ( m_verRichEdit
!= 1 )
2562 // cf.dwMask |= CFM_BACKCOLOR;
2563 style
.SetBackgroundColour(wxColour(cf
.crBackColor
));
2565 #endif // wxUSE_RICHEDIT2
2567 // now get the paragraph formatting
2570 // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
2571 // PARAFORMAT in that case
2573 if ( m_verRichEdit
== 1 )
2575 // this is the only thing the control is going to grok
2576 pf
.cbSize
= sizeof(PARAFORMAT
);
2581 // PARAFORMAT or PARAFORMAT2
2582 pf
.cbSize
= sizeof(pf
);
2585 // do format the selection
2586 (void) ::SendMessage(GetHwnd(), EM_GETPARAFORMAT
, 0, (LPARAM
) &pf
) ;
2588 style
.SetLeftIndent( (int) ((double) pf
.dxStartIndent
* twips2mm
* 10.0), (int) ((double) pf
.dxOffset
* twips2mm
* 10.0) );
2589 style
.SetRightIndent( (int) ((double) pf
.dxRightIndent
* twips2mm
* 10.0) );
2591 if (pf
.wAlignment
== PFA_CENTER
)
2592 style
.SetAlignment(wxTEXT_ALIGNMENT_CENTRE
);
2593 else if (pf
.wAlignment
== PFA_RIGHT
)
2594 style
.SetAlignment(wxTEXT_ALIGNMENT_RIGHT
);
2595 else if (pf
.wAlignment
== PFA_JUSTIFY
)
2596 style
.SetAlignment(wxTEXT_ALIGNMENT_JUSTIFIED
);
2598 style
.SetAlignment(wxTEXT_ALIGNMENT_LEFT
);
2600 wxArrayInt tabStops
;
2602 for (i
= 0; i
< (size_t) pf
.cTabCount
; i
++)
2604 tabStops
.Add( (int) ((double) (pf
.rgxTabs
[i
] & 0xFFFF) * twips2mm
* 10.0) );
2609 // restore the original selection
2610 DoSetSelection(startOld
, endOld
, false);
2618 // ----------------------------------------------------------------------------
2620 // ----------------------------------------------------------------------------
2622 bool wxRichEditModule::OnInit()
2624 // don't do anything - we will load it when needed
2628 void wxRichEditModule::OnExit()
2630 for ( size_t i
= 0; i
< WXSIZEOF(ms_hRichEdit
); i
++ )
2632 if ( ms_hRichEdit
[i
] )
2634 ::FreeLibrary(ms_hRichEdit
[i
]);
2635 ms_hRichEdit
[i
] = NULL
;
2641 bool wxRichEditModule::Load(int version
)
2643 // we don't support loading richedit 3.0 as I don't know how to distinguish
2644 // it from 2.0 anyhow
2645 wxCHECK_MSG( version
== 1 || version
== 2, false,
2646 _T("incorrect richedit control version requested") );
2648 // make it the index in the array
2651 if ( ms_hRichEdit
[version
] == (HINSTANCE
)-1 )
2653 // we had already tried to load it and failed
2657 if ( ms_hRichEdit
[version
] )
2659 // we've already got this one
2663 wxString dllname
= version
? _T("riched20") : _T("riched32");
2664 dllname
+= _T(".dll");
2666 ms_hRichEdit
[version
] = ::LoadLibrary(dllname
);
2668 if ( !ms_hRichEdit
[version
] )
2670 wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname
.c_str());
2672 ms_hRichEdit
[version
] = (HINSTANCE
)-1;
2680 #endif // wxUSE_RICHEDIT
2682 #endif // wxUSE_TEXTCTRL && !(__SMARTPHONE__ && __WXWINCE__)