1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/textctrl.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_TEXTCTRL && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
30 #include "wx/textctrl.h"
31 #include "wx/settings.h"
41 #include "wx/module.h"
44 #include "wx/clipbrd.h"
47 #include "wx/textfile.h"
51 #include "wx/msw/private.h"
52 #include "wx/msw/winundef.h"
58 #include <sys/types.h>
63 // old mingw32 has richedit stuff directly in windows.h and doesn't have
65 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
69 #include "wx/msw/missing.h"
71 #endif // wxUSE_RICHEDIT
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
79 // this module initializes RichEdit DLL(s) if needed
80 class wxRichEditModule
: public wxModule
85 Version_1
, // riched32.dll
86 Version_2or3
, // both use riched20.dll
87 Version_41
, // msftedit.dll (XP SP1 and Windows 2003)
91 virtual bool OnInit();
92 virtual void OnExit();
94 // load the richedit DLL for the specified version of rich edit
95 static bool Load(Version version
);
98 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
99 static HINSTANCE ms_hRichEdit
[Version_Max
];
101 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
104 HINSTANCE
wxRichEditModule::ms_hRichEdit
[Version_Max
] = { NULL
, NULL
, NULL
};
106 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
108 #endif // wxUSE_RICHEDIT
110 // a small class used to set m_updatesCount to 0 (to filter duplicate events if
111 // necessary) and to reset it back to -1 afterwards
112 class UpdatesCountFilter
115 UpdatesCountFilter(int& count
)
118 wxASSERT_MSG( m_count
== -1, _T("wrong initial m_updatesCount value") );
123 ~UpdatesCountFilter()
128 // return true if an event has been received
129 bool GotUpdate() const
137 DECLARE_NO_COPY_CLASS(UpdatesCountFilter
)
140 // ----------------------------------------------------------------------------
141 // event tables and other macros
142 // ----------------------------------------------------------------------------
144 #if wxUSE_EXTENDED_RTTI
145 WX_DEFINE_FLAGS( wxTextCtrlStyle
)
147 wxBEGIN_FLAGS( wxTextCtrlStyle
)
148 // new style border flags, we put them first to
149 // use them for streaming out
150 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
151 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
152 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
153 wxFLAGS_MEMBER(wxBORDER_RAISED
)
154 wxFLAGS_MEMBER(wxBORDER_STATIC
)
155 wxFLAGS_MEMBER(wxBORDER_NONE
)
157 // old style border flags
158 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
159 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
160 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
161 wxFLAGS_MEMBER(wxRAISED_BORDER
)
162 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
163 wxFLAGS_MEMBER(wxBORDER
)
165 // standard window styles
166 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
167 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
168 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
169 wxFLAGS_MEMBER(wxWANTS_CHARS
)
170 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
171 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
172 wxFLAGS_MEMBER(wxVSCROLL
)
173 wxFLAGS_MEMBER(wxHSCROLL
)
175 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER
)
176 wxFLAGS_MEMBER(wxTE_PROCESS_TAB
)
177 wxFLAGS_MEMBER(wxTE_MULTILINE
)
178 wxFLAGS_MEMBER(wxTE_PASSWORD
)
179 wxFLAGS_MEMBER(wxTE_READONLY
)
180 wxFLAGS_MEMBER(wxHSCROLL
)
181 wxFLAGS_MEMBER(wxTE_RICH
)
182 wxFLAGS_MEMBER(wxTE_RICH2
)
183 wxFLAGS_MEMBER(wxTE_AUTO_URL
)
184 wxFLAGS_MEMBER(wxTE_NOHIDESEL
)
185 wxFLAGS_MEMBER(wxTE_LEFT
)
186 wxFLAGS_MEMBER(wxTE_CENTRE
)
187 wxFLAGS_MEMBER(wxTE_RIGHT
)
188 wxFLAGS_MEMBER(wxTE_DONTWRAP
)
189 wxFLAGS_MEMBER(wxTE_LINEWRAP
)
190 wxFLAGS_MEMBER(wxTE_WORDWRAP
)
192 wxEND_FLAGS( wxTextCtrlStyle
)
194 IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl
, wxControl
,"wx/textctrl.h")
196 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl
)
197 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
198 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
200 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
201 wxPROPERTY( Value
, wxString
, SetValue
, GetValue
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
202 wxPROPERTY_FLAGS( WindowStyle
, wxTextCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
203 wxEND_PROPERTIES_TABLE()
205 wxBEGIN_HANDLERS_TABLE(wxTextCtrl
)
206 wxEND_HANDLERS_TABLE()
208 wxCONSTRUCTOR_6( wxTextCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
210 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
214 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
215 EVT_CHAR(wxTextCtrl::OnChar
)
216 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
219 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
222 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
223 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
224 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
225 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
226 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
227 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
228 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
230 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
231 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
232 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
233 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
234 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
235 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
236 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
238 EVT_SET_FOCUS(wxTextCtrl::OnSetFocus
)
241 // ============================================================================
243 // ============================================================================
245 // ----------------------------------------------------------------------------
247 // ----------------------------------------------------------------------------
249 void wxTextCtrl::Init()
253 #endif // wxUSE_RICHEDIT
255 m_privateContextMenu
= NULL
;
257 m_isNativeCaretShown
= true;
260 wxTextCtrl::~wxTextCtrl()
262 delete m_privateContextMenu
;
265 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
266 const wxString
& value
,
270 const wxValidator
& validator
,
271 const wxString
& name
)
274 if ((style
& wxBORDER_MASK
) == 0)
275 style
|= wxBORDER_SIMPLE
;
278 // base initialization
279 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
282 // translate wxWin style flags to MSW ones
283 WXDWORD msStyle
= MSWGetCreateWindowFlags();
285 // do create the control - either an EDIT or RICHEDIT
286 wxString windowClass
= wxT("EDIT");
288 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
289 // A control that capitalizes the first letter
290 if (style
& wxTE_CAPITALIZE
)
291 windowClass
= wxT("CAPEDIT");
295 if ( m_windowStyle
& wxTE_AUTO_URL
)
297 // automatic URL detection only works in RichEdit 2.0+
298 m_windowStyle
|= wxTE_RICH2
;
301 if ( m_windowStyle
& wxTE_RICH2
)
303 // using richedit 2.0 implies using wxTE_RICH
304 m_windowStyle
|= wxTE_RICH
;
307 // we need to load the richedit DLL before creating the rich edit control
308 if ( m_windowStyle
& wxTE_RICH
)
310 // versions 2.0, 3.0 and 4.1 of rich edit are mostly compatible with
311 // each other but not with version 1.0, so we have separate flags for
312 // the version 1.0 and the others (and so m_verRichEdit may be 0 (plain
313 // EDIT control), 1 for version 1.0 or 2 for any higher version)
315 // notice that 1.0 has no Unicode support at all so in Unicode build we
316 // must use another version
320 #else // !wxUSE_UNICODE
321 m_verRichEdit
= m_windowStyle
& wxTE_RICH2
? 2 : 1;
322 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
324 if ( m_verRichEdit
== 2 )
326 if ( wxRichEditModule::Load(wxRichEditModule::Version_41
) )
328 // yes, class name for version 4.1 really is 5.0
329 windowClass
= _T("RICHEDIT50W");
331 else if ( wxRichEditModule::Load(wxRichEditModule::Version_2or3
) )
333 windowClass
= _T("RichEdit20")
338 #endif // Unicode/ANSI
340 else // failed to load msftedit.dll and riched20.dll
346 if ( m_verRichEdit
== 1 )
348 if ( wxRichEditModule::Load(wxRichEditModule::Version_1
) )
350 windowClass
= _T("RICHEDIT");
352 else // failed to load any richedit control DLL
354 // only give the error msg once if the DLL can't be loaded
355 static bool s_errorGiven
= false; // MT ok as only used by GUI
359 wxLogError(_("Impossible to create a rich edit control, using simple text control instead. Please reinstall riched32.dll"));
368 #endif // wxUSE_RICHEDIT
370 // we need to turn '\n's into "\r\n"s for the multiline controls
372 if ( m_windowStyle
& wxTE_MULTILINE
)
374 valueWin
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
381 if ( !MSWCreateControl(windowClass
, msStyle
, pos
, size
, valueWin
) )
387 // enable the events we're interested in: we want to get EN_CHANGE as
388 // for the normal controls
389 LPARAM mask
= ENM_CHANGE
;
391 if ( GetRichVersion() == 1 )
393 // we also need EN_MSGFILTER for richedit 1.0 for the reasons
394 // explained in its handler
395 mask
|= ENM_MOUSEEVENTS
;
397 // we also need to force the appearance of the vertical scrollbar
398 // initially as otherwise the control doesn't refresh correctly
399 // after resize: but once the vertical scrollbar had been shown
400 // (even if it's subsequently hidden) it does
402 // this is clearly a bug and for now it has been only noticed under
403 // Windows XP, so if we're sure it works correctly under other
404 // systems we could do this only for XP
405 SetSize(-1, 1); // 1 is small enough to force vert scrollbar
408 else if ( m_windowStyle
& wxTE_AUTO_URL
)
412 ::SendMessage(GetHwnd(), EM_AUTOURLDETECT
, TRUE
, 0);
415 ::SendMessage(GetHwnd(), EM_SETEVENTMASK
, 0, mask
);
417 #endif // wxUSE_RICHEDIT
422 // Make sure the window style (etc.) reflects the HWND style (roughly)
423 void wxTextCtrl::AdoptAttributesFromHWND()
425 wxWindow::AdoptAttributesFromHWND();
427 HWND hWnd
= GetHwnd();
428 long style
= ::GetWindowLong(hWnd
, GWL_STYLE
);
430 // retrieve the style to see whether this is an edit or richedit ctrl
432 wxString classname
= wxGetWindowClass(GetHWND());
434 if ( classname
.IsSameAs(_T("EDIT"), false /* no case */) )
441 if ( wxSscanf(classname
, _T("RichEdit%d0%c"), &m_verRichEdit
, &c
) != 2 )
443 wxLogDebug(_T("Unknown edit control '%s'."), classname
.c_str());
448 #endif // wxUSE_RICHEDIT
450 if (style
& ES_MULTILINE
)
451 m_windowStyle
|= wxTE_MULTILINE
;
452 if (style
& ES_PASSWORD
)
453 m_windowStyle
|= wxTE_PASSWORD
;
454 if (style
& ES_READONLY
)
455 m_windowStyle
|= wxTE_READONLY
;
456 if (style
& ES_WANTRETURN
)
457 m_windowStyle
|= wxTE_PROCESS_ENTER
;
458 if (style
& ES_CENTER
)
459 m_windowStyle
|= wxTE_CENTRE
;
460 if (style
& ES_RIGHT
)
461 m_windowStyle
|= wxTE_RIGHT
;
464 WXDWORD
wxTextCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
466 long msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
468 // styles which we alaways add by default
469 if ( style
& wxTE_MULTILINE
)
471 wxASSERT_MSG( !(style
& wxTE_PROCESS_ENTER
),
472 wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
474 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
;
475 if ( !(style
& wxTE_NO_VSCROLL
) )
477 // always adjust the vertical scrollbar automatically if we have it
478 msStyle
|= WS_VSCROLL
| ES_AUTOVSCROLL
;
481 // we have to use this style for the rich edit controls because
482 // without it the vertical scrollbar never appears at all in
483 // richedit 3.0 because of our ECO_NOHIDESEL hack (search for it)
484 if ( style
& wxTE_RICH2
)
486 msStyle
|= ES_DISABLENOSCROLL
;
488 #endif // wxUSE_RICHEDIT
491 style
|= wxTE_PROCESS_ENTER
;
495 // there is really no reason to not have this style for single line
497 msStyle
|= ES_AUTOHSCROLL
;
500 // note that wxTE_DONTWRAP is the same as wxHSCROLL so if we have a horz
501 // scrollbar, there is no wrapping -- which makes sense
502 if ( style
& wxTE_DONTWRAP
)
504 // automatically scroll the control horizontally as necessary
506 // NB: ES_AUTOHSCROLL is needed for richedit controls or they don't
507 // show horz scrollbar at all, even in spite of WS_HSCROLL, and as
508 // it doesn't seem to do any harm for plain edit controls, add it
510 msStyle
|= WS_HSCROLL
| ES_AUTOHSCROLL
;
513 if ( style
& wxTE_READONLY
)
514 msStyle
|= ES_READONLY
;
516 if ( style
& wxTE_PASSWORD
)
517 msStyle
|= ES_PASSWORD
;
519 if ( style
& wxTE_NOHIDESEL
)
520 msStyle
|= ES_NOHIDESEL
;
522 // note that we can't do do "& wxTE_LEFT" as wxTE_LEFT == 0
523 if ( style
& wxTE_CENTRE
)
524 msStyle
|= ES_CENTER
;
525 else if ( style
& wxTE_RIGHT
)
528 msStyle
|= ES_LEFT
; // ES_LEFT is 0 as well but for consistency...
533 void wxTextCtrl::SetWindowStyleFlag(long style
)
536 // we have to deal with some styles separately because they can't be
537 // changed by simply calling SetWindowLong(GWL_STYLE) but can be changed
538 // using richedit-specific EM_SETOPTIONS
540 ((style
& wxTE_NOHIDESEL
) != (GetWindowStyle() & wxTE_NOHIDESEL
)) )
542 bool set
= (style
& wxTE_NOHIDESEL
) != 0;
544 ::SendMessage(GetHwnd(), EM_SETOPTIONS
, set
? ECOOP_OR
: ECOOP_AND
,
545 set
? ECO_NOHIDESEL
: ~ECO_NOHIDESEL
);
547 #endif // wxUSE_RICHEDIT
549 wxControl::SetWindowStyleFlag(style
);
552 // ----------------------------------------------------------------------------
553 // set/get the controls text
554 // ----------------------------------------------------------------------------
556 wxString
wxTextCtrl::GetValue() const
558 // range 0..-1 is special for GetRange() and means to retrieve all text
559 return GetRange(0, -1);
562 wxString
wxTextCtrl::GetRange(long from
, long to
) const
566 if ( from
>= to
&& to
!= -1 )
568 // nothing to retrieve
575 int len
= GetWindowTextLength(GetHwnd());
582 // we must use EM_STREAMOUT if we don't want to lose all characters
583 // not representable in the current character set (EM_GETTEXTRANGE
584 // simply replaces them with question marks...)
585 if ( GetRichVersion() > 1 )
587 // we must have some encoding, otherwise any 8bit chars in the
588 // control are simply *lost* (replaced by '?')
589 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
;
591 wxFont font
= m_defaultStyle
.GetFont();
597 encoding
= font
.GetEncoding();
600 if ( encoding
== wxFONTENCODING_SYSTEM
)
602 encoding
= wxLocale::GetSystemEncoding();
605 if ( encoding
== wxFONTENCODING_SYSTEM
)
607 encoding
= wxFONTENCODING_ISO8859_1
;
610 str
= StreamOut(encoding
);
614 // we have to manually extract the required part, luckily
615 // this is easy in this case as EOL characters in str are
616 // just LFs because we remove CRs in wxRichEditStreamOut
617 str
= str
.Mid(from
, to
- from
);
621 // StreamOut() wasn't used or failed, try to do it in normal way
623 #endif // !wxUSE_UNICODE
625 // alloc one extra WORD as needed by the control
626 wxStringBuffer
tmp(str
, ++len
);
630 textRange
.chrg
.cpMin
= from
;
631 textRange
.chrg
.cpMax
= to
;
632 textRange
.lpstrText
= p
;
634 (void)::SendMessage(GetHwnd(), EM_GETTEXTRANGE
,
635 0, (LPARAM
)&textRange
);
637 if ( m_verRichEdit
> 1 )
639 // RichEdit 2.0 uses just CR ('\r') for the
640 // newlines which is neither Unix nor Windows
641 // style - convert it to something reasonable
644 if ( *p
== _T('\r') )
650 if ( m_verRichEdit
== 1 )
652 // convert to the canonical form - see comment below
653 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
656 //else: no text at all, leave the string empty
659 #endif // wxUSE_RICHEDIT
662 str
= wxGetWindowText(GetHWND());
664 // need only a range?
667 str
= str
.Mid(from
, to
- from
);
670 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
671 // canonical one (same one as above) for consistency with the other kinds
672 // of controls and, more importantly, with the other ports
673 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
679 void wxTextCtrl::SetValue(const wxString
& value
)
681 // if the text is long enough, it's faster to just set it instead of first
682 // comparing it with the old one (chances are that it will be different
683 // anyhow, this comparison is there to avoid flicker for small single-line
684 // edit controls mostly)
685 if ( (value
.length() > 0x400) || (value
!= GetValue()) )
687 DoWriteText(value
, false /* not selection only */);
689 // for compatibility, don't move the cursor when doing SetValue()
690 SetInsertionPoint(0);
694 // still send an event for consistency
698 // we should reset the modified flag even if the value didn't really change
700 // mark the control as being not dirty - we changed its text, not the
705 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
707 // TODO: using memcpy() would improve performance a lot for big amounts of text
710 wxRichEditStreamIn(DWORD dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
714 const wchar_t ** const ppws
= (const wchar_t **)dwCookie
;
716 wchar_t *wbuf
= (wchar_t *)buf
;
717 const wchar_t *wpc
= *ppws
;
722 cb
-= sizeof(wchar_t);
723 (*pcb
) += sizeof(wchar_t);
731 // helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut
732 struct wxStreamOutData
739 wxRichEditStreamOut(DWORD_PTR dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
743 wxStreamOutData
*data
= (wxStreamOutData
*)dwCookie
;
745 const wchar_t *wbuf
= (const wchar_t *)buf
;
746 wchar_t *wpc
= data
->wpc
;
749 wchar_t wch
= *wbuf
++;
751 // turn "\r\n" into "\n" on the fly
757 cb
-= sizeof(wchar_t);
758 (*pcb
) += sizeof(wchar_t);
767 #if wxUSE_UNICODE_MSLU
768 #define UNUSED_IF_MSLU(param)
770 #define UNUSED_IF_MSLU(param) param
774 wxTextCtrl::StreamIn(const wxString
& value
,
775 wxFontEncoding
UNUSED_IF_MSLU(encoding
),
778 #if wxUSE_UNICODE_MSLU
779 const wchar_t *wpc
= value
.c_str();
780 #else // !wxUSE_UNICODE_MSLU
781 wxCSConv
conv(encoding
);
783 const size_t len
= conv
.MB2WC(NULL
, value
, value
.length());
786 wxWCharBuffer
wchBuf(len
);
787 wchar_t *wpc
= wchBuf
.data();
789 wchar_t *wchBuf
= (wchar_t *)malloc((len
+ 1)*sizeof(wchar_t));
790 wchar_t *wpc
= wchBuf
;
793 conv
.MB2WC(wpc
, value
, value
.length());
794 #endif // wxUSE_UNICODE_MSLU
796 // finally, stream it in the control
799 eds
.dwCookie
= (DWORD
)&wpc
;
800 // the cast below is needed for broken (very) old mingw32 headers
801 eds
.pfnCallback
= (EDITSTREAMCALLBACK
)wxRichEditStreamIn
;
803 // same problem as in DoWriteText(): we can get multiple events here
804 UpdatesCountFilter
ucf(m_updatesCount
);
806 ::SendMessage(GetHwnd(), EM_STREAMIN
,
809 (selectionOnly
? SFF_SELECTION
: 0),
812 // It's okay for EN_UPDATE to not be sent if the selection is empty and
813 // the text is empty, otherwise warn the programmer about it.
814 wxASSERT_MSG( ucf
.GotUpdate() || ( !HasSelection() && value
.empty() ),
815 _T("EM_STREAMIN didn't send EN_UPDATE?") );
819 wxLogLastError(_T("EM_STREAMIN"));
824 #endif // !wxUSE_WCHAR_T
829 #if !wxUSE_UNICODE_MSLU
832 wxTextCtrl::StreamOut(wxFontEncoding encoding
, bool selectionOnly
) const
836 const int len
= GetWindowTextLength(GetHwnd());
839 wxWCharBuffer
wchBuf(len
);
840 wchar_t *wpc
= wchBuf
.data();
842 wchar_t *wchBuf
= (wchar_t *)malloc((len
+ 1)*sizeof(wchar_t));
843 wchar_t *wpc
= wchBuf
;
846 wxStreamOutData data
;
852 eds
.dwCookie
= (DWORD
)&data
;
853 eds
.pfnCallback
= wxRichEditStreamOut
;
859 SF_TEXT
| SF_UNICODE
| (selectionOnly
? SFF_SELECTION
: 0),
865 wxLogLastError(_T("EM_STREAMOUT"));
867 else // streamed out ok
869 // NUL-terminate the string because its length could have been
870 // decreased by wxRichEditStreamOut
871 *(wchBuf
.data() + data
.len
) = L
'\0';
873 // now convert to the given encoding (this is a possibly lossful
874 // conversion but what else can we do)
875 wxCSConv
conv(encoding
);
876 size_t lenNeeded
= conv
.WC2MB(NULL
, wchBuf
, 0);
879 conv
.WC2MB(wxStringBuffer(out
, lenNeeded
), wchBuf
, lenNeeded
);
885 #endif // !wxUSE_WCHAR_T
890 #endif // !wxUSE_UNICODE_MSLU
892 #endif // wxUSE_RICHEDIT
894 void wxTextCtrl::WriteText(const wxString
& value
)
899 void wxTextCtrl::DoWriteText(const wxString
& value
, bool selectionOnly
)
902 if ( m_windowStyle
& wxTE_MULTILINE
)
903 valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
908 // there are several complications with the rich edit controls here
912 // first, ensure that the new text will be in the default style
913 if ( !m_defaultStyle
.IsDefault() )
916 GetSelection(&start
, &end
);
917 SetStyle(start
, end
, m_defaultStyle
);
920 #if wxUSE_UNICODE_MSLU
921 // RichEdit doesn't have Unicode version of EM_REPLACESEL on Win9x,
922 // but EM_STREAMIN works
923 if ( wxUsingUnicowsDll() && GetRichVersion() > 1 )
925 done
= StreamIn(valueDos
, wxFONTENCODING_SYSTEM
, selectionOnly
);
927 #endif // wxUSE_UNICODE_MSLU
930 // next check if the text we're inserting must be shown in a non
931 // default charset -- this only works for RichEdit > 1.0
932 if ( GetRichVersion() > 1 )
934 wxFont font
= m_defaultStyle
.GetFont();
940 wxFontEncoding encoding
= font
.GetEncoding();
941 if ( encoding
!= wxFONTENCODING_SYSTEM
)
943 // we have to use EM_STREAMIN to force richedit control 2.0+
944 // to show any text in the non default charset -- otherwise
945 // it thinks it knows better than we do and always shows it
946 // in the default one
947 done
= StreamIn(valueDos
, encoding
, selectionOnly
);
951 #endif // !wxUSE_UNICODE
955 #endif // wxUSE_RICHEDIT
957 // in some cases we get 2 EN_CHANGE notifications after the SendMessage
958 // call (this happens for plain EDITs with EM_REPLACESEL and under some
959 // -- undetermined -- conditions with rich edit) and sometimes we don't
960 // get any events at all (plain EDIT with WM_SETTEXT), so ensure that
961 // we generate exactly one of them by ignoring all but the first one in
962 // SendUpdateEvent() and generating one ourselves if we hadn't got any
963 // notifications from Windows
964 UpdatesCountFilter
ucf(m_updatesCount
);
966 ::SendMessage(GetHwnd(), selectionOnly
? EM_REPLACESEL
: WM_SETTEXT
,
967 // EM_REPLACESEL takes 1 to indicate the operation should be redoable
968 selectionOnly
? 1 : 0, (LPARAM
)valueDos
.c_str());
970 if ( !ucf
.GotUpdate() )
977 void wxTextCtrl::AppendText(const wxString
& text
)
979 SetInsertionPointEnd();
984 // don't do this if we're frozen, saves some time
985 if ( !IsFrozen() && IsMultiLine() && GetRichVersion() > 1 )
987 // setting the caret to the end and showing it simply doesn't work for
988 // RichEdit 2.0 -- force it to still do what we want
989 ::SendMessage(GetHwnd(), EM_LINESCROLL
, 0, GetNumberOfLines());
991 #endif // wxUSE_RICHEDIT
994 void wxTextCtrl::Clear()
996 ::SetWindowText(GetHwnd(), wxEmptyString
);
1000 #endif // wxUSE_RICHEDIT
1002 // rich edit controls send EN_UPDATE from WM_SETTEXT handler themselves
1003 // but the normal ones don't -- make Clear() behaviour consistent by
1004 // always sending this event
1006 // Windows already sends an update event for single-line
1008 if ( m_windowStyle
& wxTE_MULTILINE
)
1015 bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
1019 size_t lenOld
= GetValue().length();
1021 wxUint32 code
= event
.GetRawKeyCode();
1022 ::keybd_event((BYTE
)code
, 0, 0 /* key press */, 0);
1023 ::keybd_event((BYTE
)code
, 0, KEYEVENTF_KEYUP
, 0);
1025 // assume that any alphanumeric key changes the total number of characters
1026 // in the control - this should work in 99% of cases
1027 return GetValue().length() != lenOld
;
1032 // ----------------------------------------------------------------------------
1033 // Clipboard operations
1034 // ----------------------------------------------------------------------------
1036 void wxTextCtrl::Copy()
1040 ::SendMessage(GetHwnd(), WM_COPY
, 0, 0L);
1044 void wxTextCtrl::Cut()
1048 ::SendMessage(GetHwnd(), WM_CUT
, 0, 0L);
1052 void wxTextCtrl::Paste()
1056 ::SendMessage(GetHwnd(), WM_PASTE
, 0, 0L);
1060 bool wxTextCtrl::HasSelection() const
1063 GetSelection(&from
, &to
);
1067 bool wxTextCtrl::CanCopy() const
1069 // Can copy if there's a selection
1070 return HasSelection();
1073 bool wxTextCtrl::CanCut() const
1075 return CanCopy() && IsEditable();
1078 bool wxTextCtrl::CanPaste() const
1080 if ( !IsEditable() )
1086 UINT cf
= 0; // 0 == any format
1088 return ::SendMessage(GetHwnd(), EM_CANPASTE
, cf
, 0) != 0;
1090 #endif // wxUSE_RICHEDIT
1092 // Standard edit control: check for straight text on clipboard
1093 if ( !::OpenClipboard(GetHwndOf(wxTheApp
->GetTopWindow())) )
1096 bool isTextAvailable
= ::IsClipboardFormatAvailable(CF_TEXT
) != 0;
1099 return isTextAvailable
;
1102 // ----------------------------------------------------------------------------
1104 // ----------------------------------------------------------------------------
1106 void wxTextCtrl::SetEditable(bool editable
)
1108 HWND hWnd
= GetHwnd();
1109 ::SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
1112 void wxTextCtrl::SetInsertionPoint(long pos
)
1114 DoSetSelection(pos
, pos
);
1117 void wxTextCtrl::SetInsertionPointEnd()
1119 // we must not do anything if the caret is already there because calling
1120 // SetInsertionPoint() thaws the controls if Freeze() had been called even
1121 // if it doesn't actually move the caret anywhere and so the simple fact of
1122 // doing it results in horrible flicker when appending big amounts of text
1123 // to the control in a few chunks (see DoAddText() test in the text sample)
1124 if ( GetInsertionPoint() == GetLastPosition() )
1132 if ( m_verRichEdit
== 1 )
1134 // we don't have to waste time calling GetLastPosition() in this case
1137 else // !RichEdit 1.0
1138 #endif // wxUSE_RICHEDIT
1140 pos
= GetLastPosition();
1143 SetInsertionPoint(pos
);
1146 long wxTextCtrl::GetInsertionPoint() const
1154 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
1157 #endif // wxUSE_RICHEDIT
1159 DWORD Pos
= (DWORD
)::SendMessage(GetHwnd(), EM_GETSEL
, 0, 0L);
1160 return Pos
& 0xFFFF;
1163 wxTextPos
wxTextCtrl::GetLastPosition() const
1165 int numLines
= GetNumberOfLines();
1166 long posStartLastLine
= XYToPosition(0, numLines
- 1);
1168 long lenLastLine
= GetLengthOfLineContainingPos(posStartLastLine
);
1170 return posStartLastLine
+ lenLastLine
;
1173 // If the return values from and to are the same, there is no
1175 void wxTextCtrl::GetSelection(long* from
, long* to
) const
1180 CHARRANGE charRange
;
1181 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &charRange
);
1183 *from
= charRange
.cpMin
;
1184 *to
= charRange
.cpMax
;
1187 #endif // !wxUSE_RICHEDIT
1189 DWORD dwStart
, dwEnd
;
1190 ::SendMessage(GetHwnd(), EM_GETSEL
, (WPARAM
)&dwStart
, (LPARAM
)&dwEnd
);
1197 bool wxTextCtrl::IsEditable() const
1199 // strangely enough, we may be called before the control is created: our
1200 // own Create() calls MSWGetStyle() which calls AcceptsFocus() which calls
1205 long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1207 return (style
& ES_READONLY
) == 0;
1210 // ----------------------------------------------------------------------------
1212 // ----------------------------------------------------------------------------
1214 void wxTextCtrl::SetSelection(long from
, long to
)
1216 // if from and to are both -1, it means (in wxWidgets) that all text should
1217 // be selected - translate into Windows convention
1218 if ( (from
== -1) && (to
== -1) )
1224 DoSetSelection(from
, to
);
1227 void wxTextCtrl::DoSetSelection(long from
, long to
, bool scrollCaret
)
1229 HWND hWnd
= GetHwnd();
1237 ::SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
1240 #endif // wxUSE_RICHEDIT
1242 ::SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)from
, (LPARAM
)to
);
1245 if ( scrollCaret
&& !IsFrozen() )
1248 // richedit 3.0 (i.e. the version living in riched20.dll distributed
1249 // with Windows 2000 and beyond) doesn't honour EM_SCROLLCARET when
1250 // emulating richedit 2.0 unless the control has focus or ECO_NOHIDESEL
1251 // option is set (but it does work ok in richedit 1.0 mode...)
1253 // so to make it work we either need to give focus to it here which
1254 // will probably create many problems (dummy focus events; window
1255 // containing the text control being brought to foreground
1256 // unexpectedly; ...) or to temporarily set ECO_NOHIDESEL which may
1257 // create other problems too -- and in fact it does because if we turn
1258 // on/off this style while appending the text to the control, the
1259 // vertical scrollbar never appears in it even if we append tons of
1260 // text and to work around this the only solution I found was to use
1261 // ES_DISABLENOSCROLL
1263 // this is very ugly but I don't see any other way to make this work
1265 if ( GetRichVersion() > 1 )
1267 if ( !HasFlag(wxTE_NOHIDESEL
) )
1269 // setting ECO_NOHIDESEL also sets WS_VISIBLE and possibly
1270 // others, remember the style so we can reset it later if needed
1271 style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1272 ::SendMessage(GetHwnd(), EM_SETOPTIONS
,
1273 ECOOP_OR
, ECO_NOHIDESEL
);
1275 //else: everything is already ok
1277 #endif // wxUSE_RICHEDIT
1279 ::SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
1282 // restore ECO_NOHIDESEL if we changed it
1283 if ( GetRichVersion() > 1 && !HasFlag(wxTE_NOHIDESEL
) )
1285 ::SendMessage(GetHwnd(), EM_SETOPTIONS
,
1286 ECOOP_AND
, ~ECO_NOHIDESEL
);
1287 if ( style
!= ::GetWindowLong(GetHwnd(), GWL_STYLE
) )
1288 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
);
1290 #endif // wxUSE_RICHEDIT
1294 // ----------------------------------------------------------------------------
1295 // Working with files
1296 // ----------------------------------------------------------------------------
1298 bool wxTextCtrl::LoadFile(const wxString
& file
)
1300 if ( wxTextCtrlBase::LoadFile(file
) )
1302 // update the size limit if needed
1311 // ----------------------------------------------------------------------------
1313 // ----------------------------------------------------------------------------
1315 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
1317 // Set selection and remove it
1318 DoSetSelection(from
, to
, false /* don't scroll caret into view */);
1320 DoWriteText(value
, true /* selection only */);
1323 void wxTextCtrl::Remove(long from
, long to
)
1325 Replace(from
, to
, wxEmptyString
);
1328 bool wxTextCtrl::IsModified() const
1330 return ::SendMessage(GetHwnd(), EM_GETMODIFY
, 0, 0) != 0;
1333 void wxTextCtrl::MarkDirty()
1335 ::SendMessage(GetHwnd(), EM_SETMODIFY
, TRUE
, 0L);
1338 void wxTextCtrl::DiscardEdits()
1340 ::SendMessage(GetHwnd(), EM_SETMODIFY
, FALSE
, 0L);
1343 int wxTextCtrl::GetNumberOfLines() const
1345 return (int)::SendMessage(GetHwnd(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
1348 // ----------------------------------------------------------------------------
1349 // Positions <-> coords
1350 // ----------------------------------------------------------------------------
1352 long wxTextCtrl::XYToPosition(long x
, long y
) const
1354 // This gets the char index for the _beginning_ of this line
1355 long charIndex
= ::SendMessage(GetHwnd(), EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
1357 return charIndex
+ x
;
1360 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
1362 HWND hWnd
= GetHwnd();
1364 // This gets the line number containing the character
1369 lineNo
= ::SendMessage(hWnd
, EM_EXLINEFROMCHAR
, 0, (LPARAM
)pos
);
1372 #endif // wxUSE_RICHEDIT
1374 lineNo
= ::SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, 0);
1383 // This gets the char index for the _beginning_ of this line
1384 long charIndex
= ::SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
1385 if ( charIndex
== -1 )
1390 // The X position must therefore be the different between pos and charIndex
1392 *x
= pos
- charIndex
;
1399 wxTextCtrlHitTestResult
1400 wxTextCtrl::HitTest(const wxPoint
& pt
, long *posOut
) const
1402 // first get the position from Windows
1409 // for rich edit controls the position is passed iva the struct fields
1412 lParam
= (LPARAM
)&ptl
;
1415 #endif // wxUSE_RICHEDIT
1417 // for the plain ones, we are limited to 16 bit positions which are
1418 // combined in a single 32 bit value
1419 lParam
= MAKELPARAM(pt
.x
, pt
.y
);
1422 LRESULT pos
= ::SendMessage(GetHwnd(), EM_CHARFROMPOS
, 0, lParam
);
1426 // this seems to indicate an error...
1427 return wxTE_HT_UNKNOWN
;
1432 #endif // wxUSE_RICHEDIT
1434 // for plain EDIT controls the higher word contains something else
1439 // next determine where it is relatively to our point: EM_CHARFROMPOS
1440 // always returns the closest character but we need to be more precise, so
1441 // double check that we really are where it pretends
1445 // FIXME: we need to distinguish between richedit 2 and 3 here somehow but
1446 // we don't know how to do it
1449 ::SendMessage(GetHwnd(), EM_POSFROMCHAR
, (WPARAM
)&ptReal
, pos
);
1452 #endif // wxUSE_RICHEDIT
1454 LRESULT lRc
= ::SendMessage(GetHwnd(), EM_POSFROMCHAR
, pos
, 0);
1458 // this is apparently returned when pos corresponds to the last
1465 ptReal
.x
= LOWORD(lRc
);
1466 ptReal
.y
= HIWORD(lRc
);
1470 wxTextCtrlHitTestResult rc
;
1472 if ( pt
.y
> ptReal
.y
+ GetCharHeight() )
1474 else if ( pt
.x
> ptReal
.x
+ GetCharWidth() )
1475 rc
= wxTE_HT_BEYOND
;
1477 rc
= wxTE_HT_ON_TEXT
;
1485 // ----------------------------------------------------------------------------
1487 // ----------------------------------------------------------------------------
1489 void wxTextCtrl::ShowPosition(long pos
)
1491 HWND hWnd
= GetHwnd();
1493 // To scroll to a position, we pass the number of lines and characters
1494 // to scroll *by*. This means that we need to:
1495 // (1) Find the line position of the current line.
1496 // (2) Find the line position of pos.
1497 // (3) Scroll by (pos - current).
1498 // For now, ignore the horizontal scrolling.
1500 // Is this where scrolling is relative to - the line containing the caret?
1501 // Or is the first visible line??? Try first visible line.
1502 // int currentLineLineNo1 = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
1504 int currentLineLineNo
= (int)::SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
1506 int specifiedLineLineNo
= (int)::SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
1508 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
1510 if (linesToScroll
!= 0)
1511 (void)::SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)linesToScroll
);
1514 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
1516 return ::SendMessage(GetHwnd(), EM_LINELENGTH
, (WPARAM
)pos
, 0);
1519 int wxTextCtrl::GetLineLength(long lineNo
) const
1521 long pos
= XYToPosition(0, lineNo
);
1523 return GetLengthOfLineContainingPos(pos
);
1526 wxString
wxTextCtrl::GetLineText(long lineNo
) const
1528 size_t len
= (size_t)GetLineLength(lineNo
) + 1;
1530 // there must be at least enough place for the length WORD in the
1532 len
+= sizeof(WORD
);
1536 wxStringBufferLength
tmp(str
, len
);
1539 *(WORD
*)buf
= (WORD
)len
;
1540 len
= (size_t)::SendMessage(GetHwnd(), EM_GETLINE
, lineNo
, (LPARAM
)buf
);
1545 // remove the '\r' returned by the rich edit control, the user code
1546 // should never see it
1547 if ( buf
[len
- 2] == _T('\r') && buf
[len
- 1] == _T('\n') )
1549 buf
[len
- 2] = _T('\n');
1553 #endif // wxUSE_RICHEDIT
1555 // remove the '\n' at the end, if any (this is how this function is
1556 // supposed to work according to the docs)
1557 if ( buf
[len
- 1] == _T('\n') )
1569 void wxTextCtrl::SetMaxLength(unsigned long len
)
1574 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT
, 0, len
? len
: 0x7fffffff);
1577 #endif // wxUSE_RICHEDIT
1579 if ( len
>= 0xffff )
1581 // this will set it to a platform-dependent maximum (much more
1582 // than 64Kb under NT)
1586 ::SendMessage(GetHwnd(), EM_LIMITTEXT
, len
, 0);
1590 // ----------------------------------------------------------------------------
1592 // ----------------------------------------------------------------------------
1594 void wxTextCtrl::Undo()
1598 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
1602 void wxTextCtrl::Redo()
1607 if (GetRichVersion() > 1)
1608 ::SendMessage(GetHwnd(), EM_REDO
, 0, 0);
1611 // Same as Undo, since Undo undoes the undo, i.e. a redo.
1612 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
1616 bool wxTextCtrl::CanUndo() const
1618 return ::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0;
1621 bool wxTextCtrl::CanRedo() const
1624 if (GetRichVersion() > 1)
1625 return ::SendMessage(GetHwnd(), EM_CANREDO
, 0, 0) != 0;
1628 return ::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0;
1631 // ----------------------------------------------------------------------------
1632 // caret handling (Windows only)
1633 // ----------------------------------------------------------------------------
1635 bool wxTextCtrl::ShowNativeCaret(bool show
)
1637 if ( show
!= m_isNativeCaretShown
)
1639 if ( !(show
? ::ShowCaret(GetHwnd()) : ::HideCaret(GetHwnd())) )
1641 // not an error, may simply indicate that it's not shown/hidden
1642 // yet (i.e. it had been hidden/showh 2 times before)
1646 m_isNativeCaretShown
= show
;
1652 // ----------------------------------------------------------------------------
1653 // implemenation details
1654 // ----------------------------------------------------------------------------
1656 void wxTextCtrl::Command(wxCommandEvent
& event
)
1658 SetValue(event
.GetString());
1659 ProcessCommand (event
);
1662 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
1664 // By default, load the first file into the text window.
1665 if (event
.GetNumberOfFiles() > 0)
1667 LoadFile(event
.GetFiles()[0]);
1671 // ----------------------------------------------------------------------------
1672 // kbd input processing
1673 // ----------------------------------------------------------------------------
1675 bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG
* pMsg
)
1677 MSG
*msg
= (MSG
*)pMsg
;
1679 // check for our special keys here: if we don't do it and the parent frame
1680 // uses them as accelerators, they wouldn't work at all, so we disable
1681 // usual preprocessing for them
1682 if ( msg
->message
== WM_KEYDOWN
)
1684 WORD vkey
= (WORD
) msg
->wParam
;
1685 if ( (HIWORD(msg
->lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
1687 if ( vkey
== VK_BACK
)
1692 // we want to process some Ctrl-foo and Shift-bar but no key
1693 // combinations without either Ctrl or Shift nor with both of them
1695 const int ctrl
= wxIsCtrlDown(),
1696 shift
= wxIsShiftDown();
1697 switch ( ctrl
+ shift
)
1700 wxFAIL_MSG( _T("how many modifiers have we got?") );
1708 // either Ctrl or Shift pressed
1723 else // Shift is pressed
1725 if ( vkey
== VK_INSERT
|| vkey
== VK_DELETE
)
1732 return wxControl::MSWShouldPreProcessMessage(pMsg
);
1735 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
1737 switch ( event
.GetKeyCode() )
1740 if ( !HasFlag(wxTE_MULTILINE
) )
1742 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1743 InitCommandEvent(event
);
1744 event
.SetString(GetValue());
1745 if ( GetEventHandler()->ProcessEvent(event
) )
1748 //else: multiline controls need Enter for themselves
1753 // ok, so this is getting absolutely ridiculous but I don't see
1754 // any other way to fix this bug: when a multiline text control is
1755 // inside a wxFrame, we need to generate the navigation event as
1756 // otherwise nothing happens at all, but when the same control is
1757 // created inside a dialog, IsDialogMessage() *does* switch focus
1758 // all by itself and so if we do it here as well, it is advanced
1759 // twice and goes to the next control... to prevent this from
1760 // happening we're doing this ugly check, the logic being that if
1761 // we don't have focus then it had been already changed to the next
1764 // the right thing to do would, of course, be to understand what
1765 // the hell is IsDialogMessage() doing but this is beyond my feeble
1766 // forces at the moment unfortunately
1767 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
1769 if ( FindFocus() == this )
1772 if (!event
.ShiftDown())
1773 flags
|= wxNavigationKeyEvent::IsForward
;
1774 if (event
.ControlDown())
1775 flags
|= wxNavigationKeyEvent::WinChange
;
1776 if (Navigate(flags
))
1782 // Insert tab since calling the default Windows handler
1783 // doesn't seem to do it
1784 WriteText(wxT("\t"));
1790 // no, we didn't process it
1794 WXLRESULT
wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1796 WXLRESULT lRc
= wxTextCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
1798 if ( nMsg
== WM_GETDLGCODE
)
1800 // we always want the chars and the arrows: the arrows for navigation
1801 // and the chars because we want Ctrl-C to work even in a read only
1803 long lDlgCode
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
1807 // we may have several different cases:
1808 // 1. normal case: both TAB and ENTER are used for dlg navigation
1809 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the
1810 // next control in the dialog
1811 // 3. ctrl which wants ENTER for itself: TAB is used for dialog
1813 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to go
1814 // to the next control
1816 // the multiline edit control should always get <Return> for itself
1817 if ( HasFlag(wxTE_PROCESS_ENTER
) || HasFlag(wxTE_MULTILINE
) )
1818 lDlgCode
|= DLGC_WANTMESSAGE
;
1820 if ( HasFlag(wxTE_PROCESS_TAB
) )
1821 lDlgCode
|= DLGC_WANTTAB
;
1827 // NB: use "=", not "|=" as the base class version returns the
1828 // same flags is this state as usual (i.e. including
1829 // DLGC_WANTMESSAGE). This is strange (how does it work in the
1830 // native Win32 apps?) but for now live with it.
1838 // ----------------------------------------------------------------------------
1839 // text control event processing
1840 // ----------------------------------------------------------------------------
1842 bool wxTextCtrl::SendUpdateEvent()
1844 switch ( m_updatesCount
)
1847 // remember that we've got an update
1852 // we had already sent one event since the last control modification
1856 wxFAIL_MSG( _T("unexpected wxTextCtrl::m_updatesCount value") );
1860 // we hadn't updated the control ourselves, this event comes from
1861 // the user, don't need to ignore it nor update the count
1865 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, GetId());
1866 InitCommandEvent(event
);
1868 return ProcessCommand(event
);
1871 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1878 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1881 event
.SetEventObject(this);
1882 GetEventHandler()->ProcessEvent(event
);
1891 // the text size limit has been hit -- try to increase it
1892 if ( !AdjustSpaceLimit() )
1894 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, m_windowId
);
1895 InitCommandEvent(event
);
1896 event
.SetString(GetValue());
1897 ProcessCommand(event
);
1901 // the other edit notification messages are not processed
1910 WXHBRUSH
wxTextCtrl::MSWControlColor(WXHDC hDC
, WXHWND hWnd
)
1912 if ( !IsEnabled() && !HasFlag(wxTE_MULTILINE
) )
1913 return MSWControlColorDisabled(hDC
);
1915 return wxTextCtrlBase::MSWControlColor(hDC
, hWnd
);
1918 bool wxTextCtrl::HasSpaceLimit(unsigned int *len
) const
1920 // HACK: we try to automatically extend the limit for the amount of text
1921 // to allow (interactively) entering more than 64Kb of text under
1922 // Win9x but we shouldn't reset the text limit which was previously
1923 // set explicitly with SetMaxLength()
1925 // Unfortunately there is no EM_GETLIMITTEXTSETBYUSER and so we don't
1926 // know the limit we set (if any). We could solve this by storing the
1927 // limit we set in wxTextCtrl but to save space we prefer to simply
1928 // test here the actual limit value: we consider that SetMaxLength()
1929 // can only be called for small values while EN_MAXTEXT is only sent
1930 // for large values (in practice the default limit seems to be 30000
1931 // but make it smaller just to be on the safe side)
1932 *len
= ::SendMessage(GetHwnd(), EM_GETLIMITTEXT
, 0, 0);
1933 return *len
< 10001;
1937 bool wxTextCtrl::AdjustSpaceLimit()
1940 if ( HasSpaceLimit(&limit
) )
1943 unsigned int len
= ::GetWindowTextLength(GetHwnd());
1946 // increment in 32Kb chunks
1947 SetMaxLength(len
+ 0x8000);
1950 // we changed the limit
1954 bool wxTextCtrl::AcceptsFocus() const
1956 // we don't want focus if we can't be edited unless we're a multiline
1957 // control because then it might be still nice to get focus from keyboard
1958 // to be able to scroll it without mouse
1959 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
1962 wxSize
wxTextCtrl::DoGetBestSize() const
1965 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
1967 int wText
= DEFAULT_ITEM_WIDTH
;
1970 if ( m_windowStyle
& wxTE_MULTILINE
)
1972 hText
*= wxMax(wxMin(GetNumberOfLines(), 10), 2);
1974 //else: for single line control everything is ok
1976 // we have to add the adjustments for the control height only once, not
1977 // once per line, so do it after multiplication above
1978 hText
+= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
) - cy
;
1980 return wxSize(wText
, hText
);
1983 // ----------------------------------------------------------------------------
1984 // standard handlers for standard edit menu events
1985 // ----------------------------------------------------------------------------
1987 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1992 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1997 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
2002 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
2007 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
2012 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
2015 GetSelection(& from
, & to
);
2016 if (from
!= -1 && to
!= -1)
2020 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
2022 SetSelection(-1, -1);
2025 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
2027 event
.Enable( CanCut() );
2030 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
2032 event
.Enable( CanCopy() );
2035 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
2037 event
.Enable( CanPaste() );
2040 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
2042 event
.Enable( CanUndo() );
2045 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
2047 event
.Enable( CanRedo() );
2050 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
2053 GetSelection(& from
, & to
);
2054 event
.Enable(from
!= -1 && to
!= -1 && from
!= to
&& IsEditable()) ;
2057 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
2059 event
.Enable(GetLastPosition() > 0);
2062 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
2067 if (!m_privateContextMenu
)
2069 m_privateContextMenu
= new wxMenu
;
2070 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
2071 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
2072 m_privateContextMenu
->AppendSeparator();
2073 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
2074 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
2075 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
2076 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
2077 m_privateContextMenu
->AppendSeparator();
2078 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
2080 PopupMenu(m_privateContextMenu
);
2088 void wxTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
2090 // be sure the caret remains invisible if the user had hidden it
2091 if ( !m_isNativeCaretShown
)
2093 ::HideCaret(GetHwnd());
2097 // ----------------------------------------------------------------------------
2098 // Default colors for MSW text control
2100 // Set default background color to the native white instead of
2101 // the default wxSYS_COLOUR_BTNFACE (is triggered with wxNullColour).
2102 // ----------------------------------------------------------------------------
2104 wxVisualAttributes
wxTextCtrl::GetDefaultAttributes() const
2106 wxVisualAttributes attrs
;
2107 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
2108 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
2109 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
); //white
2114 // the rest of the file only deals with the rich edit controls
2117 // ----------------------------------------------------------------------------
2118 // EN_LINK processing
2119 // ----------------------------------------------------------------------------
2121 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
2123 NMHDR
*hdr
= (NMHDR
* )lParam
;
2124 switch ( hdr
->code
)
2128 const MSGFILTER
*msgf
= (MSGFILTER
*)lParam
;
2129 UINT msg
= msgf
->msg
;
2131 // this is a bit crazy but richedit 1.0 sends us all mouse
2132 // events _except_ WM_LBUTTONUP (don't ask me why) so we have
2133 // generate the wxWin events for this message manually
2135 // NB: in fact, this is still not totally correct as it does
2136 // send us WM_LBUTTONUP if the selection was cleared by the
2137 // last click -- so currently we get 2 events in this case,
2138 // but as I don't see any obvious way to check for this I
2139 // leave this code in place because it's still better than
2140 // not getting left up events at all
2141 if ( msg
== WM_LBUTTONUP
)
2143 WXUINT flags
= msgf
->wParam
;
2144 int x
= GET_X_LPARAM(msgf
->lParam
),
2145 y
= GET_Y_LPARAM(msgf
->lParam
);
2147 HandleMouseEvent(msg
, x
, y
, flags
);
2151 // return true to process the event (and false to ignore it)
2156 const ENLINK
*enlink
= (ENLINK
*)hdr
;
2158 switch ( enlink
->msg
)
2161 // ok, so it is hardcoded - do we really nee to
2164 wxCursor
cur(wxCURSOR_HAND
);
2165 ::SetCursor(GetHcursorOf(cur
));
2171 case WM_LBUTTONDOWN
:
2173 case WM_LBUTTONDBLCLK
:
2174 case WM_RBUTTONDOWN
:
2176 case WM_RBUTTONDBLCLK
:
2177 // send a mouse event
2179 static const wxEventType eventsMouse
[] =
2190 // the event ids are consecutive
2192 evtMouse(eventsMouse
[enlink
->msg
- WM_MOUSEMOVE
]);
2194 InitMouseEvent(evtMouse
,
2195 GET_X_LPARAM(enlink
->lParam
),
2196 GET_Y_LPARAM(enlink
->lParam
),
2199 wxTextUrlEvent
event(m_windowId
, evtMouse
,
2201 enlink
->chrg
.cpMax
);
2203 InitCommandEvent(event
);
2205 *result
= ProcessCommand(event
);
2213 // not processed, leave it to the base class
2214 return wxTextCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
2217 // ----------------------------------------------------------------------------
2218 // colour setting for the rich edit controls
2219 // ----------------------------------------------------------------------------
2221 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
2223 if ( !wxTextCtrlBase::SetBackgroundColour(colour
) )
2225 // colour didn't really change
2231 // rich edit doesn't use WM_CTLCOLOR, hence we need to send
2232 // EM_SETBKGNDCOLOR additionally
2233 ::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR
, 0, wxColourToRGB(colour
));
2239 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
2241 if ( !wxTextCtrlBase::SetForegroundColour(colour
) )
2243 // colour didn't really change
2249 // change the colour of everything
2252 cf
.cbSize
= sizeof(cf
);
2253 cf
.dwMask
= CFM_COLOR
;
2254 cf
.crTextColor
= wxColourToRGB(colour
);
2255 ::SendMessage(GetHwnd(), EM_SETCHARFORMAT
, SCF_ALL
, (LPARAM
)&cf
);
2261 // ----------------------------------------------------------------------------
2262 // styling support for rich edit controls
2263 // ----------------------------------------------------------------------------
2267 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
2271 // can't do it with normal text control
2275 // the richedit 1.0 doesn't handle setting background colour, so don't
2276 // even try to do anything if it's the only thing we want to change
2277 if ( m_verRichEdit
== 1 && !style
.HasFont() && !style
.HasTextColour() &&
2278 !style
.HasLeftIndent() && !style
.HasRightIndent() && !style
.HasAlignment() &&
2281 // nothing to do: return true if there was really nothing to do and
2282 // false if we failed to set bg colour
2283 return !style
.HasBackgroundColour();
2286 // order the range if needed
2294 // we can only change the format of the selection, so select the range we
2295 // want and restore the old selection later
2296 long startOld
, endOld
;
2297 GetSelection(&startOld
, &endOld
);
2299 // but do we really have to change the selection?
2300 bool changeSel
= start
!= startOld
|| end
!= endOld
;
2304 DoSetSelection(start
, end
, false /* don't scroll caret into view */);
2307 // initialize CHARFORMAT struct
2316 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
2317 // CHARFORMAT in that case
2319 if ( m_verRichEdit
== 1 )
2321 // this is the only thing the control is going to grok
2322 cf
.cbSize
= sizeof(CHARFORMAT
);
2327 // CHARFORMAT or CHARFORMAT2
2328 cf
.cbSize
= sizeof(cf
);
2331 if ( style
.HasFont() )
2333 // VZ: CFM_CHARSET doesn't seem to do anything at all in RichEdit 2.0
2334 // but using it doesn't seem to hurt neither so leaving it for now
2336 cf
.dwMask
|= CFM_FACE
| CFM_SIZE
| CFM_CHARSET
|
2337 CFM_ITALIC
| CFM_BOLD
| CFM_UNDERLINE
;
2339 // fill in data from LOGFONT but recalculate lfHeight because we need
2340 // the real height in twips and not the negative number which
2341 // wxFillLogFont() returns (this is correct in general and works with
2342 // the Windows font mapper, but not here)
2344 wxFillLogFont(&lf
, &style
.GetFont());
2345 cf
.yHeight
= 20*style
.GetFont().GetPointSize(); // 1 pt = 20 twips
2346 cf
.bCharSet
= lf
.lfCharSet
;
2347 cf
.bPitchAndFamily
= lf
.lfPitchAndFamily
;
2348 wxStrncpy( cf
.szFaceName
, lf
.lfFaceName
, WXSIZEOF(cf
.szFaceName
) );
2350 // also deal with underline/italic/bold attributes: note that we must
2351 // always set CFM_ITALIC &c bits in dwMask, even if we don't set the
2352 // style to allow clearing it
2355 cf
.dwEffects
|= CFE_ITALIC
;
2358 if ( lf
.lfWeight
== FW_BOLD
)
2360 cf
.dwEffects
|= CFE_BOLD
;
2363 if ( lf
.lfUnderline
)
2365 cf
.dwEffects
|= CFE_UNDERLINE
;
2368 // strikeout fonts are not supported by wxWidgets
2371 if ( style
.HasTextColour() )
2373 cf
.dwMask
|= CFM_COLOR
;
2374 cf
.crTextColor
= wxColourToRGB(style
.GetTextColour());
2378 if ( m_verRichEdit
!= 1 && style
.HasBackgroundColour() )
2380 cf
.dwMask
|= CFM_BACKCOLOR
;
2381 cf
.crBackColor
= wxColourToRGB(style
.GetBackgroundColour());
2383 #endif // wxUSE_RICHEDIT2
2385 // do format the selection
2386 bool ok
= ::SendMessage(GetHwnd(), EM_SETCHARFORMAT
,
2387 SCF_SELECTION
, (LPARAM
)&cf
) != 0;
2390 wxLogDebug(_T("SendMessage(EM_SETCHARFORMAT, SCF_SELECTION) failed"));
2393 // now do the paragraph formatting
2396 // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
2397 // PARAFORMAT in that case
2399 if ( m_verRichEdit
== 1 )
2401 // this is the only thing the control is going to grok
2402 pf
.cbSize
= sizeof(PARAFORMAT
);
2407 // PARAFORMAT or PARAFORMAT2
2408 pf
.cbSize
= sizeof(pf
);
2411 if (style
.HasAlignment())
2413 pf
.dwMask
|= PFM_ALIGNMENT
;
2414 if (style
.GetAlignment() == wxTEXT_ALIGNMENT_RIGHT
)
2415 pf
.wAlignment
= PFA_RIGHT
;
2416 else if (style
.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE
)
2417 pf
.wAlignment
= PFA_CENTER
;
2418 else if (style
.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED
)
2419 pf
.wAlignment
= PFA_JUSTIFY
;
2421 pf
.wAlignment
= PFA_LEFT
;
2424 if (style
.HasLeftIndent())
2426 pf
.dwMask
|= PFM_STARTINDENT
| PFM_OFFSET
;
2428 // Convert from 1/10 mm to TWIPS
2429 pf
.dxStartIndent
= (int) (((double) style
.GetLeftIndent()) * mm2twips
/ 10.0) ;
2430 pf
.dxOffset
= (int) (((double) style
.GetLeftSubIndent()) * mm2twips
/ 10.0) ;
2433 if (style
.HasRightIndent())
2435 pf
.dwMask
|= PFM_RIGHTINDENT
;
2437 // Convert from 1/10 mm to TWIPS
2438 pf
.dxRightIndent
= (int) (((double) style
.GetRightIndent()) * mm2twips
/ 10.0) ;
2441 if (style
.HasTabs())
2443 pf
.dwMask
|= PFM_TABSTOPS
;
2445 const wxArrayInt
& tabs
= style
.GetTabs();
2447 pf
.cTabCount
= (SHORT
)wxMin(tabs
.GetCount(), MAX_TAB_STOPS
);
2449 for (i
= 0; i
< (size_t) pf
.cTabCount
; i
++)
2451 // Convert from 1/10 mm to TWIPS
2452 pf
.rgxTabs
[i
] = (int) (((double) tabs
[i
]) * mm2twips
/ 10.0) ;
2458 // do format the selection
2459 bool ok
= ::SendMessage(GetHwnd(), EM_SETPARAFORMAT
,
2460 0, (LPARAM
) &pf
) != 0;
2463 wxLogDebug(_T("SendMessage(EM_SETPARAFORMAT, 0) failed"));
2469 // restore the original selection
2470 DoSetSelection(startOld
, endOld
, false);
2476 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
2478 if ( !wxTextCtrlBase::SetDefaultStyle(style
) )
2483 // we have to do this or the style wouldn't apply for the text typed by
2485 wxTextPos posLast
= GetLastPosition();
2486 SetStyle(posLast
, posLast
, m_defaultStyle
);
2492 bool wxTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
2496 // can't do it with normal text control
2500 // initialize CHARFORMAT struct
2509 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
2510 // CHARFORMAT in that case
2512 if ( m_verRichEdit
== 1 )
2514 // this is the only thing the control is going to grok
2515 cf
.cbSize
= sizeof(CHARFORMAT
);
2520 // CHARFORMAT or CHARFORMAT2
2521 cf
.cbSize
= sizeof(cf
);
2523 // we can only change the format of the selection, so select the range we
2524 // want and restore the old selection later
2525 long startOld
, endOld
;
2526 GetSelection(&startOld
, &endOld
);
2528 // but do we really have to change the selection?
2529 bool changeSel
= position
!= startOld
|| position
!= endOld
;
2533 DoSetSelection(position
, position
+1, false /* don't scroll caret into view */);
2536 // get the selection formatting
2537 (void) ::SendMessage(GetHwnd(), EM_GETCHARFORMAT
,
2538 SCF_SELECTION
, (LPARAM
)&cf
) ;
2542 lf
.lfHeight
= cf
.yHeight
;
2544 lf
.lfCharSet
= ANSI_CHARSET
; // FIXME: how to get correct charset?
2545 lf
.lfClipPrecision
= 0;
2546 lf
.lfEscapement
= 0;
2547 wxStrcpy(lf
.lfFaceName
, cf
.szFaceName
);
2549 //NOTE: we _MUST_ set each of these values to _something_ since we
2550 //do not call wxZeroMemory on the LOGFONT lf
2551 if (cf
.dwEffects
& CFE_ITALIC
)
2554 lf
.lfItalic
= FALSE
;
2556 lf
.lfOrientation
= 0;
2557 lf
.lfPitchAndFamily
= cf
.bPitchAndFamily
;
2560 if (cf
.dwEffects
& CFE_STRIKEOUT
)
2561 lf
.lfStrikeOut
= TRUE
;
2563 lf
.lfStrikeOut
= FALSE
;
2565 if (cf
.dwEffects
& CFE_UNDERLINE
)
2566 lf
.lfUnderline
= TRUE
;
2568 lf
.lfUnderline
= FALSE
;
2570 if (cf
.dwEffects
& CFE_BOLD
)
2571 lf
.lfWeight
= FW_BOLD
;
2573 lf
.lfWeight
= FW_NORMAL
;
2575 wxFont font
= wxCreateFontFromLogFont(& lf
);
2578 style
.SetFont(font
);
2580 style
.SetTextColour(wxColour(cf
.crTextColor
));
2583 if ( m_verRichEdit
!= 1 )
2585 // cf.dwMask |= CFM_BACKCOLOR;
2586 style
.SetBackgroundColour(wxColour(cf
.crBackColor
));
2588 #endif // wxUSE_RICHEDIT2
2590 // now get the paragraph formatting
2593 // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
2594 // PARAFORMAT in that case
2596 if ( m_verRichEdit
== 1 )
2598 // this is the only thing the control is going to grok
2599 pf
.cbSize
= sizeof(PARAFORMAT
);
2604 // PARAFORMAT or PARAFORMAT2
2605 pf
.cbSize
= sizeof(pf
);
2608 // do format the selection
2609 (void) ::SendMessage(GetHwnd(), EM_GETPARAFORMAT
, 0, (LPARAM
) &pf
) ;
2611 style
.SetLeftIndent( (int) ((double) pf
.dxStartIndent
* twips2mm
* 10.0), (int) ((double) pf
.dxOffset
* twips2mm
* 10.0) );
2612 style
.SetRightIndent( (int) ((double) pf
.dxRightIndent
* twips2mm
* 10.0) );
2614 if (pf
.wAlignment
== PFA_CENTER
)
2615 style
.SetAlignment(wxTEXT_ALIGNMENT_CENTRE
);
2616 else if (pf
.wAlignment
== PFA_RIGHT
)
2617 style
.SetAlignment(wxTEXT_ALIGNMENT_RIGHT
);
2618 else if (pf
.wAlignment
== PFA_JUSTIFY
)
2619 style
.SetAlignment(wxTEXT_ALIGNMENT_JUSTIFIED
);
2621 style
.SetAlignment(wxTEXT_ALIGNMENT_LEFT
);
2623 wxArrayInt tabStops
;
2625 for (i
= 0; i
< (size_t) pf
.cTabCount
; i
++)
2627 tabStops
.Add( (int) ((double) (pf
.rgxTabs
[i
] & 0xFFFF) * twips2mm
* 10.0) );
2632 // restore the original selection
2633 DoSetSelection(startOld
, endOld
, false);
2641 // ----------------------------------------------------------------------------
2643 // ----------------------------------------------------------------------------
2645 static const HINSTANCE INVALID_HINSTANCE
= (HINSTANCE
)-1;
2647 bool wxRichEditModule::OnInit()
2649 // don't do anything - we will load it when needed
2653 void wxRichEditModule::OnExit()
2655 for ( size_t i
= 0; i
< WXSIZEOF(ms_hRichEdit
); i
++ )
2657 if ( ms_hRichEdit
[i
] && ms_hRichEdit
[i
] != INVALID_HINSTANCE
)
2659 ::FreeLibrary(ms_hRichEdit
[i
]);
2660 ms_hRichEdit
[i
] = NULL
;
2666 bool wxRichEditModule::Load(Version version
)
2668 if ( ms_hRichEdit
[version
] == INVALID_HINSTANCE
)
2670 // we had already tried to load it and failed
2674 if ( ms_hRichEdit
[version
] )
2676 // we've already got this one
2680 static const wxChar
*dllnames
[] =
2687 wxCOMPILE_TIME_ASSERT( WXSIZEOF(dllnames
) == Version_Max
,
2688 RichEditDllNamesVersionsMismatch
);
2690 ms_hRichEdit
[version
] = ::LoadLibrary(dllnames
[version
]);
2692 if ( !ms_hRichEdit
[version
] )
2694 ms_hRichEdit
[version
] = INVALID_HINSTANCE
;
2702 #endif // wxUSE_RICHEDIT
2704 #endif // wxUSE_TEXTCTRL && !(__SMARTPHONE__ && __WXWINCE__)