1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
39 #include "wx/module.h"
40 #include "wx/wxcrtvararg.h"
43 #include "wx/sysopt.h"
46 #include "wx/clipbrd.h"
49 #include "wx/textfile.h"
53 #include "wx/msw/private.h"
54 #include "wx/msw/winundef.h"
55 #include "wx/msw/mslu.h"
61 #include <sys/types.h>
67 #include "wx/dynlib.h"
70 // old mingw32 has richedit stuff directly in windows.h and doesn't have
72 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
76 #endif // wxUSE_RICHEDIT
78 #include "wx/msw/missing.h"
80 #if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
82 // dummy value used for m_dropTarget, different from any valid pointer value
83 // (which are all even under Windows) and NULL
85 wxRICHTEXT_DEFAULT_DROPTARGET
= reinterpret_cast<wxDropTarget
*>(1);
87 #endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
95 // this module initializes RichEdit DLL(s) if needed
96 class wxRichEditModule
: public wxModule
101 Version_1
, // riched32.dll
102 Version_2or3
, // both use riched20.dll
103 Version_41
, // msftedit.dll (XP SP1 and Windows 2003)
107 virtual bool OnInit();
108 virtual void OnExit();
110 // load the richedit DLL for the specified version of rich edit
111 static bool Load(Version version
);
114 // load the InkEdit library
115 static bool LoadInkEdit();
119 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
120 static HINSTANCE ms_hRichEdit
[Version_Max
];
123 static wxDynamicLibrary ms_inkEditLib
;
124 static bool ms_inkEditLibLoadAttemped
;
127 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
130 HINSTANCE
wxRichEditModule::ms_hRichEdit
[Version_Max
] = { NULL
, NULL
, NULL
};
133 wxDynamicLibrary
wxRichEditModule::ms_inkEditLib
;
134 bool wxRichEditModule::ms_inkEditLibLoadAttemped
= false;
137 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
139 #endif // wxUSE_RICHEDIT
141 // a small class used to set m_updatesCount to 0 (to filter duplicate events if
142 // necessary) and to reset it back to -1 afterwards
143 class UpdatesCountFilter
146 UpdatesCountFilter(int& count
)
149 wxASSERT_MSG( m_count
== -1 || m_count
== -2,
150 wxT("wrong initial m_updatesCount value") );
154 //else: we don't want to count how many update events we get as we're going
155 // to ignore all of them
158 ~UpdatesCountFilter()
163 // return true if an event has been received
164 bool GotUpdate() const
172 wxDECLARE_NO_COPY_CLASS(UpdatesCountFilter
);
175 // ----------------------------------------------------------------------------
176 // event tables and other macros
177 // ----------------------------------------------------------------------------
179 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
180 EVT_CHAR(wxTextCtrl::OnChar
)
181 EVT_KEY_DOWN(wxTextCtrl::OnKeyDown
)
182 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
185 EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu
)
188 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
189 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
190 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
191 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
192 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
193 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
194 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
196 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
197 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
198 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
199 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
200 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
201 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
202 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
204 EVT_SET_FOCUS(wxTextCtrl::OnSetFocus
)
207 // ============================================================================
209 // ============================================================================
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 void wxTextCtrl::Init()
219 #endif // wxUSE_RICHEDIT
221 #if wxUSE_INKEDIT && wxUSE_RICHEDIT
225 m_privateContextMenu
= NULL
;
227 m_isNativeCaretShown
= true;
230 wxTextCtrl::~wxTextCtrl()
232 #if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
233 if ( m_dropTarget
== wxRICHTEXT_DEFAULT_DROPTARGET
)
235 // don't try to destroy this dummy pointer in the base class dtor
238 #endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
240 delete m_privateContextMenu
;
243 bool wxTextCtrl::Create(wxWindow
*parent
,
245 const wxString
& value
,
249 const wxValidator
& validator
,
250 const wxString
& name
)
252 // base initialization
253 if ( !CreateControl(parent
, id
, pos
, size
, style
, validator
, name
) )
256 if ( !MSWCreateText(value
, pos
, size
) )
259 #if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
262 // rich text controls have a default associated drop target which
263 // allows them to receive (rich) text dropped on them, which is nice,
264 // but prevents us from associating a user-defined drop target with
265 // them as we need to unregister the old one first
267 // to make it work, we set m_dropTarget to this special value initially
268 // and check for it in our SetDropTarget()
269 m_dropTarget
= wxRICHTEXT_DEFAULT_DROPTARGET
;
271 #endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT
276 // returns true if the platform should explicitly apply a theme border
277 bool wxTextCtrl::CanApplyThemeBorder() const
282 // Standard text control already handles theming
283 return ((GetWindowStyle() & (wxTE_RICH
|wxTE_RICH2
)) != 0);
287 bool wxTextCtrl::MSWCreateText(const wxString
& value
,
291 // translate wxWin style flags to MSW ones
292 WXDWORD msStyle
= MSWGetCreateWindowFlags();
294 // do create the control - either an EDIT or RICHEDIT
295 wxString windowClass
= wxT("EDIT");
297 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
298 // A control that capitalizes the first letter
299 if ( HasFlag(wxTE_CAPITALIZE
) )
300 windowClass
= wxT("CAPEDIT");
304 if ( m_windowStyle
& wxTE_AUTO_URL
)
306 // automatic URL detection only works in RichEdit 2.0+
307 m_windowStyle
|= wxTE_RICH2
;
310 if ( m_windowStyle
& wxTE_RICH2
)
312 // using richedit 2.0 implies using wxTE_RICH
313 m_windowStyle
|= wxTE_RICH
;
316 // we need to load the richedit DLL before creating the rich edit control
317 if ( m_windowStyle
& wxTE_RICH
)
319 // versions 2.0, 3.0 and 4.1 of rich edit are mostly compatible with
320 // each other but not with version 1.0, so we have separate flags for
321 // the version 1.0 and the others (and so m_verRichEdit may be 0 (plain
322 // EDIT control), 1 for version 1.0 or 2 for any higher version)
324 // notice that 1.0 has no Unicode support at all so in Unicode build we
325 // must use another version
329 #else // !wxUSE_UNICODE
330 m_verRichEdit
= m_windowStyle
& wxTE_RICH2
? 2 : 1;
331 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
334 // First test if we can load an ink edit control. Normally, all edit
335 // controls will be made ink edit controls if a tablet environment is
336 // found (or if msw.inkedit != 0 and the InkEd.dll is present).
337 // However, an application can veto ink edit controls by either specifying
338 // msw.inkedit = 0 or by removing wxTE_RICH[2] from the style.
340 if ((wxSystemSettings::HasFeature(wxSYS_TABLET_PRESENT
) || wxSystemOptions::GetOptionInt(wxT("msw.inkedit")) != 0) &&
341 !(wxSystemOptions::HasOption(wxT("msw.inkedit")) && wxSystemOptions::GetOptionInt(wxT("msw.inkedit")) == 0))
343 if (wxRichEditModule::LoadInkEdit())
345 windowClass
= INKEDIT_CLASS
;
347 #if wxUSE_INKEDIT && wxUSE_RICHEDIT
351 // Fake rich text version for other calls
359 #endif // wxUSE_INKEDIT
361 if ( m_verRichEdit
== 2 )
363 if ( wxRichEditModule::Load(wxRichEditModule::Version_41
) )
365 // yes, class name for version 4.1 really is 5.0
366 windowClass
= wxT("RICHEDIT50W");
370 else if ( wxRichEditModule::Load(wxRichEditModule::Version_2or3
) )
372 windowClass
= wxT("RichEdit20")
377 #endif // Unicode/ANSI
379 else // failed to load msftedit.dll and riched20.dll
385 if ( m_verRichEdit
== 1 )
387 if ( wxRichEditModule::Load(wxRichEditModule::Version_1
) )
389 windowClass
= wxT("RICHEDIT");
391 else // failed to load any richedit control DLL
393 // only give the error msg once if the DLL can't be loaded
394 static bool s_errorGiven
= false; // MT ok as only used by GUI
398 wxLogError(_("Impossible to create a rich edit control, using simple text control instead. Please reinstall riched32.dll"));
408 #endif // wxUSE_RICHEDIT
410 // we need to turn '\n's into "\r\n"s for the multiline controls
412 if ( m_windowStyle
& wxTE_MULTILINE
)
414 valueWin
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
421 // suppress events sent during control creation: we're called either from
422 // the ctor and then we shouldn't generate any events for compatibility
423 // with the other ports, or from SetWindowStyleFlag() and then we shouldn't
424 // generate the events because our text doesn't really change, the fact
425 // that we (sometimes) need to recreate the control is just an
426 // implementation detail
429 if ( !MSWCreateControl(windowClass
.wx_str(), msStyle
, pos
, size
, valueWin
) )
440 // Pass IEM_InsertText (0) as wParam, in order to have the ink always
441 // converted to text.
442 ::SendMessage(GetHwnd(), EM_SETINKINSERTMODE
, 0, 0);
444 // Make sure the mouse can be used for input
445 ::SendMessage(GetHwnd(), EM_SETUSEMOUSEFORINPUT
, 1, 0);
449 // enable the events we're interested in: we want to get EN_CHANGE as
450 // for the normal controls
451 LPARAM mask
= ENM_CHANGE
;
453 if (GetRichVersion() == 1 && !IsInkEdit())
455 // we also need EN_MSGFILTER for richedit 1.0 for the reasons
456 // explained in its handler
457 mask
|= ENM_MOUSEEVENTS
;
459 // we also need to force the appearance of the vertical scrollbar
460 // initially as otherwise the control doesn't refresh correctly
461 // after resize: but once the vertical scrollbar had been shown
462 // (even if it's subsequently hidden) it does
464 // this is clearly a bug and for now it has been only noticed under
465 // Windows XP, so if we're sure it works correctly under other
466 // systems we could do this only for XP
467 SetSize(-1, 1); // 1 is small enough to force vert scrollbar
468 SetInitialSize(size
);
470 else if ( m_windowStyle
& wxTE_AUTO_URL
)
474 ::SendMessage(GetHwnd(), EM_AUTOURLDETECT
, TRUE
, 0);
477 ::SendMessage(GetHwnd(), EM_SETEVENTMASK
, 0, mask
);
480 #endif // wxUSE_RICHEDIT
481 if ( HasFlag(wxTE_MULTILINE
) && HasFlag(wxTE_READONLY
) )
483 // non-rich read-only multiline controls have grey background by
484 // default under MSW but this is not always appropriate, so forcefully
485 // reset the background colour to normal default
487 // this is not ideal but, after a long discussion on wx-dev (see
488 // http://thread.gmane.org/gmane.comp.lib.wxwidgets.devel/116360/) it
489 // was finally deemed to be the best behaviour by default (and ideally
490 // we'd have a way to change this, see #11521)
491 SetBackgroundColour(GetClassDefaultAttributes().colBg
);
495 // Without this, if we pass the size in the constructor and then don't change it,
496 // the themed borders will be drawn incorrectly.
497 SetWindowPos(GetHwnd(), NULL
, 0, 0, 0, 0,
498 SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|
505 // Make sure the window style (etc.) reflects the HWND style (roughly)
506 void wxTextCtrl::AdoptAttributesFromHWND()
508 wxWindow::AdoptAttributesFromHWND();
510 HWND hWnd
= GetHwnd();
511 long style
= ::GetWindowLong(hWnd
, GWL_STYLE
);
513 // retrieve the style to see whether this is an edit or richedit ctrl
515 wxString classname
= wxGetWindowClass(GetHWND());
517 if ( classname
.IsSameAs(wxT("EDIT"), false /* no case */) )
524 if ( wxSscanf(classname
, wxT("RichEdit%d0%c"), &m_verRichEdit
, &c
) != 2 )
526 wxLogDebug(wxT("Unknown edit control '%s'."), classname
.c_str());
531 #endif // wxUSE_RICHEDIT
533 if (style
& ES_MULTILINE
)
534 m_windowStyle
|= wxTE_MULTILINE
;
535 if (style
& ES_PASSWORD
)
536 m_windowStyle
|= wxTE_PASSWORD
;
537 if (style
& ES_READONLY
)
538 m_windowStyle
|= wxTE_READONLY
;
539 if (style
& ES_WANTRETURN
)
540 m_windowStyle
|= wxTE_PROCESS_ENTER
;
541 if (style
& ES_CENTER
)
542 m_windowStyle
|= wxTE_CENTRE
;
543 if (style
& ES_RIGHT
)
544 m_windowStyle
|= wxTE_RIGHT
;
547 WXDWORD
wxTextCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
549 long msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
551 // styles which we always add by default
552 if ( style
& wxTE_MULTILINE
)
554 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
;
555 if ( !(style
& wxTE_NO_VSCROLL
) )
557 // always adjust the vertical scrollbar automatically if we have it
558 msStyle
|= WS_VSCROLL
| ES_AUTOVSCROLL
;
561 // we have to use this style for the rich edit controls because
562 // without it the vertical scrollbar never appears at all in
563 // richedit 3.0 because of our ECO_NOHIDESEL hack (search for it)
564 if ( style
& wxTE_RICH2
)
566 msStyle
|= ES_DISABLENOSCROLL
;
568 #endif // wxUSE_RICHEDIT
571 style
|= wxTE_PROCESS_ENTER
;
575 // there is really no reason to not have this style for single line
577 msStyle
|= ES_AUTOHSCROLL
;
580 // note that wxTE_DONTWRAP is the same as wxHSCROLL so if we have a horz
581 // scrollbar, there is no wrapping -- which makes sense
582 if ( style
& wxTE_DONTWRAP
)
584 // automatically scroll the control horizontally as necessary
586 // NB: ES_AUTOHSCROLL is needed for richedit controls or they don't
587 // show horz scrollbar at all, even in spite of WS_HSCROLL, and as
588 // it doesn't seem to do any harm for plain edit controls, add it
590 msStyle
|= WS_HSCROLL
| ES_AUTOHSCROLL
;
593 if ( style
& wxTE_READONLY
)
594 msStyle
|= ES_READONLY
;
596 if ( style
& wxTE_PASSWORD
)
597 msStyle
|= ES_PASSWORD
;
599 if ( style
& wxTE_NOHIDESEL
)
600 msStyle
|= ES_NOHIDESEL
;
602 // note that we can't do do "& wxTE_LEFT" as wxTE_LEFT == 0
603 if ( style
& wxTE_CENTRE
)
604 msStyle
|= ES_CENTER
;
605 else if ( style
& wxTE_RIGHT
)
608 msStyle
|= ES_LEFT
; // ES_LEFT is 0 as well but for consistency...
613 void wxTextCtrl::SetWindowStyleFlag(long style
)
615 // changing the alignment of the control dynamically works under Win2003
616 // (but not older Windows version: it seems to work under some versions of
617 // XP but not other ones, and we have no way to determine it so be
618 // conservative here) and only for plain EDIT controls (not RICH ones) and
619 // we have to recreate the control to make it always work
620 if ( IsRich() || wxGetWinVersion() < wxWinVersion_2003
)
622 const long alignMask
= wxTE_LEFT
| wxTE_CENTRE
| wxTE_RIGHT
;
623 if ( (style
& alignMask
) != (GetWindowStyle() & alignMask
) )
625 const wxString value
= GetValue();
626 const wxPoint pos
= GetPosition();
627 const wxSize size
= GetSize();
629 // delete the old window
630 HWND hwnd
= GetHwnd();
632 ::DestroyWindow(hwnd
);
634 // create the new one with the updated flags
635 m_windowStyle
= style
;
636 MSWCreateText(value
, pos
, size
);
638 // and make sure it has the same attributes as before
641 // calling SetFont(m_font) would do nothing as the code would
642 // notice that the font didn't change, so force it to believe
644 wxFont font
= m_font
;
651 wxColour colFg
= m_foregroundColour
;
652 m_foregroundColour
= wxNullColour
;
653 SetForegroundColour(colFg
);
658 wxColour colBg
= m_backgroundColour
;
659 m_backgroundColour
= wxNullColour
;
660 SetBackgroundColour(colBg
);
663 // note that text styles are lost but this is probably not a big
664 // problem: if you use styles, you probably don't use nor change
665 // alignment flags anyhow
672 // we have to deal with some styles separately because they can't be
673 // changed by simply calling SetWindowLong(GWL_STYLE) but can be changed
674 // using richedit-specific EM_SETOPTIONS
676 ((style
& wxTE_NOHIDESEL
) != (GetWindowStyle() & wxTE_NOHIDESEL
)) )
678 bool set
= (style
& wxTE_NOHIDESEL
) != 0;
680 ::SendMessage(GetHwnd(), EM_SETOPTIONS
, set
? ECOOP_OR
: ECOOP_AND
,
681 set
? ECO_NOHIDESEL
: ~ECO_NOHIDESEL
);
683 #endif // wxUSE_RICHEDIT
685 wxControl::SetWindowStyleFlag(style
);
688 // ----------------------------------------------------------------------------
689 // set/get the controls text
690 // ----------------------------------------------------------------------------
692 bool wxTextCtrl::IsEmpty() const
694 // this is an optimization for multiline controls containing a lot of text
695 if ( IsMultiLine() && GetNumberOfLines() != 1 )
698 return wxTextCtrlBase::IsEmpty();
701 wxString
wxTextCtrl::GetValue() const
703 // range 0..-1 is special for GetRange() and means to retrieve all text
704 return GetRange(0, -1);
707 wxString
wxTextCtrl::GetRange(long from
, long to
) const
711 if ( from
>= to
&& to
!= -1 )
713 // nothing to retrieve
720 int len
= GetWindowTextLength(GetHwnd());
727 // we must use EM_STREAMOUT if we don't want to lose all characters
728 // not representable in the current character set (EM_GETTEXTRANGE
729 // simply replaces them with question marks...)
730 if ( GetRichVersion() > 1 )
732 // we must have some encoding, otherwise any 8bit chars in the
733 // control are simply *lost* (replaced by '?')
734 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
;
736 wxFont font
= m_defaultStyle
.GetFont();
742 encoding
= font
.GetEncoding();
746 if ( encoding
== wxFONTENCODING_SYSTEM
)
748 encoding
= wxLocale::GetSystemEncoding();
752 if ( encoding
== wxFONTENCODING_SYSTEM
)
754 encoding
= wxFONTENCODING_ISO8859_1
;
757 str
= StreamOut(encoding
);
761 // we have to manually extract the required part, luckily
762 // this is easy in this case as EOL characters in str are
763 // just LFs because we remove CRs in wxRichEditStreamOut
764 str
= str
.Mid(from
, to
- from
);
768 // StreamOut() wasn't used or failed, try to do it in normal way
770 #endif // !wxUSE_UNICODE
772 // alloc one extra WORD as needed by the control
773 wxStringBuffer
tmp(str
, ++len
);
777 textRange
.chrg
.cpMin
= from
;
778 textRange
.chrg
.cpMax
= to
;
779 textRange
.lpstrText
= p
;
781 (void)::SendMessage(GetHwnd(), EM_GETTEXTRANGE
,
782 0, (LPARAM
)&textRange
);
784 if ( m_verRichEdit
> 1 )
786 // RichEdit 2.0 uses just CR ('\r') for the
787 // newlines which is neither Unix nor Windows
788 // style - convert it to something reasonable
791 if ( *p
== wxT('\r') )
797 if ( m_verRichEdit
== 1 )
799 // convert to the canonical form - see comment below
800 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
803 //else: no text at all, leave the string empty
806 #endif // wxUSE_RICHEDIT
808 // retrieve all text: wxTextEntry method works even for multiline
809 // controls and must be used for single line ones to account for hints
810 str
= wxTextEntry::GetValue();
812 // need only a range?
815 str
= str
.Mid(from
, to
- from
);
818 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
819 // canonical one (same one as above) for consistency with the other kinds
820 // of controls and, more importantly, with the other ports
821 str
= wxTextFile::Translate(str
, wxTextFileType_Unix
);
827 void wxTextCtrl::DoSetValue(const wxString
& value
, int flags
)
829 // if the text is long enough, it's faster to just set it instead of first
830 // comparing it with the old one (chances are that it will be different
831 // anyhow, this comparison is there to avoid flicker for small single-line
832 // edit controls mostly)
833 if ( (value
.length() > 0x400) || (value
!= DoGetValue()) )
835 DoWriteText(value
, flags
/* doesn't include SelectionOnly here */);
837 // mark the control as being not dirty - we changed its text, not the
841 // for compatibility, don't move the cursor when doing SetValue()
842 SetInsertionPoint(0);
846 // still reset the modified flag even if the value didn't really change
847 // because now it comes from the program and not the user (and do it
848 // before generating the event so that the event handler could get the
849 // expected value from IsModified())
852 // still send an event for consistency
853 if (flags
& SetValue_SendEvent
)
858 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
860 // TODO: using memcpy() would improve performance a lot for big amounts of text
863 wxRichEditStreamIn(DWORD_PTR dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
867 const wchar_t ** const ppws
= (const wchar_t **)dwCookie
;
869 wchar_t *wbuf
= (wchar_t *)buf
;
870 const wchar_t *wpc
= *ppws
;
875 cb
-= sizeof(wchar_t);
876 (*pcb
) += sizeof(wchar_t);
884 // helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut
885 struct wxStreamOutData
892 wxRichEditStreamOut(DWORD_PTR dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
896 wxStreamOutData
*data
= (wxStreamOutData
*)dwCookie
;
898 const wchar_t *wbuf
= (const wchar_t *)buf
;
899 wchar_t *wpc
= data
->wpc
;
902 wchar_t wch
= *wbuf
++;
904 // turn "\r\n" into "\n" on the fly
910 cb
-= sizeof(wchar_t);
911 (*pcb
) += sizeof(wchar_t);
920 #if wxUSE_UNICODE_MSLU
921 #define UNUSED_IF_MSLU(param)
923 #define UNUSED_IF_MSLU(param) param
927 wxTextCtrl::StreamIn(const wxString
& value
,
928 wxFontEncoding
UNUSED_IF_MSLU(encoding
),
931 #if wxUSE_UNICODE_MSLU
932 const wchar_t *wpc
= value
.c_str();
933 #else // !wxUSE_UNICODE_MSLU
934 wxCSConv
conv(encoding
);
936 const size_t len
= conv
.MB2WC(NULL
, value
.mb_str(), value
.length());
938 if (len
== wxCONV_FAILED
)
941 wxWCharBuffer
wchBuf(len
); // allocates one extra character
942 wchar_t *wpc
= wchBuf
.data();
944 conv
.MB2WC(wpc
, value
.mb_str(), len
+ 1);
945 #endif // wxUSE_UNICODE_MSLU
947 // finally, stream it in the control
950 eds
.dwCookie
= (DWORD_PTR
)&wpc
;
951 // the cast below is needed for broken (very) old mingw32 headers
952 eds
.pfnCallback
= (EDITSTREAMCALLBACK
)wxRichEditStreamIn
;
954 // same problem as in DoWriteText(): we can get multiple events here
955 UpdatesCountFilter
ucf(m_updatesCount
);
957 ::SendMessage(GetHwnd(), EM_STREAMIN
,
960 (selectionOnly
? SFF_SELECTION
: 0),
963 // It's okay for EN_UPDATE to not be sent if the selection is empty and
964 // the text is empty, otherwise warn the programmer about it.
965 wxASSERT_MSG( ucf
.GotUpdate() || ( !HasSelection() && value
.empty() ),
966 wxT("EM_STREAMIN didn't send EN_UPDATE?") );
970 wxLogLastError(wxT("EM_STREAMIN"));
976 #if !wxUSE_UNICODE_MSLU
979 wxTextCtrl::StreamOut(wxFontEncoding encoding
, bool selectionOnly
) const
983 const int len
= GetWindowTextLength(GetHwnd());
985 wxWCharBuffer
wchBuf(len
);
986 wchar_t *wpc
= wchBuf
.data();
988 wxStreamOutData data
;
994 eds
.dwCookie
= (DWORD
)&data
;
995 eds
.pfnCallback
= wxRichEditStreamOut
;
1001 SF_TEXT
| SF_UNICODE
| (selectionOnly
? SFF_SELECTION
: 0),
1007 wxLogLastError(wxT("EM_STREAMOUT"));
1009 else // streamed out ok
1011 // NUL-terminate the string because its length could have been
1012 // decreased by wxRichEditStreamOut
1013 *(wchBuf
.data() + data
.len
) = L
'\0';
1015 // now convert to the given encoding (this is a possibly lossful
1016 // conversion but what else can we do)
1017 wxCSConv
conv(encoding
);
1018 size_t lenNeeded
= conv
.WC2MB(NULL
, wchBuf
, 0);
1020 if ( lenNeeded
!= wxCONV_FAILED
&& lenNeeded
++ )
1022 conv
.WC2MB(wxStringBuffer(out
, lenNeeded
), wchBuf
, lenNeeded
);
1029 #endif // !wxUSE_UNICODE_MSLU
1031 #endif // wxUSE_RICHEDIT
1033 void wxTextCtrl::WriteText(const wxString
& value
)
1038 void wxTextCtrl::DoWriteText(const wxString
& value
, int flags
)
1040 bool selectionOnly
= (flags
& SetValue_SelectionOnly
) != 0;
1042 if ( m_windowStyle
& wxTE_MULTILINE
)
1043 valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
1048 // there are several complications with the rich edit controls here
1052 // first, ensure that the new text will be in the default style
1053 if ( !m_defaultStyle
.IsDefault() )
1056 GetSelection(&start
, &end
);
1057 SetStyle(start
, end
, m_defaultStyle
);
1060 #if wxUSE_UNICODE_MSLU
1061 // RichEdit doesn't have Unicode version of EM_REPLACESEL on Win9x,
1062 // but EM_STREAMIN works
1063 if ( wxUsingUnicowsDll() && GetRichVersion() > 1 )
1065 done
= StreamIn(valueDos
, wxFONTENCODING_SYSTEM
, selectionOnly
);
1067 #endif // wxUSE_UNICODE_MSLU
1070 // next check if the text we're inserting must be shown in a non
1071 // default charset -- this only works for RichEdit > 1.0
1072 if ( GetRichVersion() > 1 )
1074 wxFont font
= m_defaultStyle
.GetFont();
1080 wxFontEncoding encoding
= font
.GetEncoding();
1081 if ( encoding
!= wxFONTENCODING_SYSTEM
)
1083 // we have to use EM_STREAMIN to force richedit control 2.0+
1084 // to show any text in the non default charset -- otherwise
1085 // it thinks it knows better than we do and always shows it
1086 // in the default one
1087 done
= StreamIn(valueDos
, encoding
, selectionOnly
);
1091 #endif // !wxUSE_UNICODE
1095 #endif // wxUSE_RICHEDIT
1097 // in some cases we get 2 EN_CHANGE notifications after the SendMessage
1098 // call (this happens for plain EDITs with EM_REPLACESEL and under some
1099 // -- undetermined -- conditions with rich edit) and sometimes we don't
1100 // get any events at all (plain EDIT with WM_SETTEXT), so ensure that
1101 // we generate exactly one of them by ignoring all but the first one in
1102 // SendUpdateEvent() and generating one ourselves if we hadn't got any
1103 // notifications from Windows
1104 if ( !(flags
& SetValue_SendEvent
) )
1105 m_updatesCount
= -2; // suppress any update event
1107 UpdatesCountFilter
ucf(m_updatesCount
);
1109 ::SendMessage(GetHwnd(), selectionOnly
? EM_REPLACESEL
: WM_SETTEXT
,
1110 // EM_REPLACESEL takes 1 to indicate the operation should be redoable
1111 selectionOnly
? 1 : 0, (LPARAM
)valueDos
.wx_str());
1113 if ( !ucf
.GotUpdate() && (flags
& SetValue_SendEvent
) )
1120 void wxTextCtrl::AppendText(const wxString
& text
)
1122 wxTextEntry::AppendText(text
);
1125 // don't do this if we're frozen, saves some time
1126 if ( !IsFrozen() && IsMultiLine() && GetRichVersion() > 1 )
1128 ::SendMessage(GetHwnd(), WM_VSCROLL
, SB_BOTTOM
, NULL
);
1130 #endif // wxUSE_RICHEDIT
1133 void wxTextCtrl::Clear()
1135 ::SetWindowText(GetHwnd(), wxEmptyString
);
1137 if ( IsMultiLine() && !IsRich() )
1139 // rich edit controls send EN_UPDATE from WM_SETTEXT handler themselves
1140 // but the normal ones don't -- make Clear() behaviour consistent by
1141 // always sending this event
1148 bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
1152 size_t lenOld
= GetValue().length();
1154 wxUint32 code
= event
.GetRawKeyCode();
1155 ::keybd_event((BYTE
)code
, 0, 0 /* key press */, 0);
1156 ::keybd_event((BYTE
)code
, 0, KEYEVENTF_KEYUP
, 0);
1158 // assume that any alphanumeric key changes the total number of characters
1159 // in the control - this should work in 99% of cases
1160 return GetValue().length() != lenOld
;
1165 // ----------------------------------------------------------------------------
1167 // ----------------------------------------------------------------------------
1169 void wxTextCtrl::SetInsertionPointEnd()
1171 // we must not do anything if the caret is already there because calling
1172 // SetInsertionPoint() thaws the controls if Freeze() had been called even
1173 // if it doesn't actually move the caret anywhere and so the simple fact of
1174 // doing it results in horrible flicker when appending big amounts of text
1175 // to the control in a few chunks (see DoAddText() test in the text sample)
1176 const wxTextPos lastPosition
= GetLastPosition();
1177 if ( GetInsertionPoint() == lastPosition
)
1182 SetInsertionPoint(lastPosition
);
1185 long wxTextCtrl::GetInsertionPoint() const
1193 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
1196 #endif // wxUSE_RICHEDIT
1198 return wxTextEntry::GetInsertionPoint();
1201 wxTextPos
wxTextCtrl::GetLastPosition() const
1203 if ( IsMultiLine() )
1205 int numLines
= GetNumberOfLines();
1206 long posStartLastLine
= XYToPosition(0, numLines
- 1);
1208 long lenLastLine
= GetLengthOfLineContainingPos(posStartLastLine
);
1210 return posStartLastLine
+ lenLastLine
;
1213 return wxTextEntry::GetLastPosition();
1216 // If the return values from and to are the same, there is no
1218 void wxTextCtrl::GetSelection(long *from
, long *to
) const
1223 CHARRANGE charRange
;
1224 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &charRange
);
1226 *from
= charRange
.cpMin
;
1227 *to
= charRange
.cpMax
;
1230 #endif // !wxUSE_RICHEDIT
1232 wxTextEntry::GetSelection(from
, to
);
1236 // ----------------------------------------------------------------------------
1238 // ----------------------------------------------------------------------------
1240 void wxTextCtrl::DoSetSelection(long from
, long to
, int flags
)
1242 HWND hWnd
= GetHwnd();
1247 // if from and to are both -1, it means (in wxWidgets) that all text
1248 // should be selected, translate this into Windows convention
1249 if ( (from
== -1) && (to
== -1) )
1257 ::SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
1260 #endif // wxUSE_RICHEDIT
1262 wxTextEntry::DoSetSelection(from
, to
, flags
);
1265 if ( (flags
& SetSel_Scroll
) && !IsFrozen() )
1268 // richedit 3.0 (i.e. the version living in riched20.dll distributed
1269 // with Windows 2000 and beyond) doesn't honour EM_SCROLLCARET when
1270 // emulating richedit 2.0 unless the control has focus or ECO_NOHIDESEL
1271 // option is set (but it does work ok in richedit 1.0 mode...)
1273 // so to make it work we either need to give focus to it here which
1274 // will probably create many problems (dummy focus events; window
1275 // containing the text control being brought to foreground
1276 // unexpectedly; ...) or to temporarily set ECO_NOHIDESEL which may
1277 // create other problems too -- and in fact it does because if we turn
1278 // on/off this style while appending the text to the control, the
1279 // vertical scrollbar never appears in it even if we append tons of
1280 // text and to work around this the only solution I found was to use
1281 // ES_DISABLENOSCROLL
1283 // this is very ugly but I don't see any other way to make this work
1285 if ( GetRichVersion() > 1 )
1287 if ( !HasFlag(wxTE_NOHIDESEL
) )
1289 // setting ECO_NOHIDESEL also sets WS_VISIBLE and possibly
1290 // others, remember the style so we can reset it later if needed
1291 style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1292 ::SendMessage(GetHwnd(), EM_SETOPTIONS
,
1293 ECOOP_OR
, ECO_NOHIDESEL
);
1295 //else: everything is already ok
1297 #endif // wxUSE_RICHEDIT
1299 ::SendMessage(hWnd
, EM_SCROLLCARET
, 0, (LPARAM
)0);
1302 // restore ECO_NOHIDESEL if we changed it
1303 if ( GetRichVersion() > 1 && !HasFlag(wxTE_NOHIDESEL
) )
1305 ::SendMessage(GetHwnd(), EM_SETOPTIONS
,
1306 ECOOP_AND
, ~ECO_NOHIDESEL
);
1307 if ( style
!= ::GetWindowLong(GetHwnd(), GWL_STYLE
) )
1308 ::SetWindowLong(GetHwnd(), GWL_STYLE
, style
);
1310 #endif // wxUSE_RICHEDIT
1314 // ----------------------------------------------------------------------------
1315 // Working with files
1316 // ----------------------------------------------------------------------------
1318 bool wxTextCtrl::DoLoadFile(const wxString
& file
, int fileType
)
1320 if ( wxTextCtrlBase::DoLoadFile(file
, fileType
) )
1322 // update the size limit if needed
1331 // ----------------------------------------------------------------------------
1333 // ----------------------------------------------------------------------------
1335 bool wxTextCtrl::IsModified() const
1337 return ::SendMessage(GetHwnd(), EM_GETMODIFY
, 0, 0) != 0;
1340 void wxTextCtrl::MarkDirty()
1342 ::SendMessage(GetHwnd(), EM_SETMODIFY
, TRUE
, 0);
1345 void wxTextCtrl::DiscardEdits()
1347 ::SendMessage(GetHwnd(), EM_SETMODIFY
, FALSE
, 0);
1350 // ----------------------------------------------------------------------------
1351 // Positions <-> coords
1352 // ----------------------------------------------------------------------------
1354 int wxTextCtrl::GetNumberOfLines() const
1356 return (int)::SendMessage(GetHwnd(), EM_GETLINECOUNT
, 0, 0);
1359 long wxTextCtrl::XYToPosition(long x
, long y
) const
1361 // This gets the char index for the _beginning_ of this line
1362 long charIndex
= ::SendMessage(GetHwnd(), EM_LINEINDEX
, y
, 0);
1364 return charIndex
+ x
;
1367 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
1369 HWND hWnd
= GetHwnd();
1371 // This gets the line number containing the character
1376 lineNo
= ::SendMessage(hWnd
, EM_EXLINEFROMCHAR
, 0, pos
);
1379 #endif // wxUSE_RICHEDIT
1381 lineNo
= ::SendMessage(hWnd
, EM_LINEFROMCHAR
, pos
, 0);
1390 // This gets the char index for the _beginning_ of this line
1391 long charIndex
= ::SendMessage(hWnd
, EM_LINEINDEX
, lineNo
, 0);
1392 if ( charIndex
== -1 )
1397 // The X position must therefore be the different between pos and charIndex
1399 *x
= pos
- charIndex
;
1406 wxTextCtrlHitTestResult
1407 wxTextCtrl::HitTest(const wxPoint
& pt
, long *posOut
) const
1409 // first get the position from Windows
1416 // for rich edit controls the position is passed iva the struct fields
1419 lParam
= (LPARAM
)&ptl
;
1422 #endif // wxUSE_RICHEDIT
1424 // for the plain ones, we are limited to 16 bit positions which are
1425 // combined in a single 32 bit value
1426 lParam
= MAKELPARAM(pt
.x
, pt
.y
);
1429 LRESULT pos
= ::SendMessage(GetHwnd(), EM_CHARFROMPOS
, 0, lParam
);
1433 // this seems to indicate an error...
1434 return wxTE_HT_UNKNOWN
;
1439 #endif // wxUSE_RICHEDIT
1441 // for plain EDIT controls the higher word contains something else
1446 // next determine where it is relatively to our point: EM_CHARFROMPOS
1447 // always returns the closest character but we need to be more precise, so
1448 // double check that we really are where it pretends
1452 // FIXME: we need to distinguish between richedit 2 and 3 here somehow but
1453 // we don't know how to do it
1456 ::SendMessage(GetHwnd(), EM_POSFROMCHAR
, (WPARAM
)&ptReal
, pos
);
1459 #endif // wxUSE_RICHEDIT
1461 LRESULT lRc
= ::SendMessage(GetHwnd(), EM_POSFROMCHAR
, pos
, 0);
1465 // this is apparently returned when pos corresponds to the last
1472 ptReal
.x
= LOWORD(lRc
);
1473 ptReal
.y
= HIWORD(lRc
);
1477 wxTextCtrlHitTestResult rc
;
1479 if ( pt
.y
> ptReal
.y
+ GetCharHeight() )
1481 else if ( pt
.x
> ptReal
.x
+ GetCharWidth() )
1482 rc
= wxTE_HT_BEYOND
;
1484 rc
= wxTE_HT_ON_TEXT
;
1492 // ----------------------------------------------------------------------------
1494 // ----------------------------------------------------------------------------
1496 void wxTextCtrl::ShowPosition(long pos
)
1498 HWND hWnd
= GetHwnd();
1500 // To scroll to a position, we pass the number of lines and characters
1501 // to scroll *by*. This means that we need to:
1502 // (1) Find the line position of the current line.
1503 // (2) Find the line position of pos.
1504 // (3) Scroll by (pos - current).
1505 // For now, ignore the horizontal scrolling.
1507 // Is this where scrolling is relative to - the line containing the caret?
1508 // Or is the first visible line??? Try first visible line.
1509 // int currentLineLineNo1 = (int)::SendMessage(hWnd, EM_LINEFROMCHAR, -1, 0L);
1511 int currentLineLineNo
= (int)::SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, 0, 0);
1513 int specifiedLineLineNo
= (int)::SendMessage(hWnd
, EM_LINEFROMCHAR
, pos
, 0);
1515 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
1517 if (linesToScroll
!= 0)
1518 ::SendMessage(hWnd
, EM_LINESCROLL
, 0, linesToScroll
);
1521 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
1523 return ::SendMessage(GetHwnd(), EM_LINELENGTH
, pos
, 0);
1526 int wxTextCtrl::GetLineLength(long lineNo
) const
1528 long pos
= XYToPosition(0, lineNo
);
1530 return GetLengthOfLineContainingPos(pos
);
1533 wxString
wxTextCtrl::GetLineText(long lineNo
) const
1535 size_t len
= (size_t)GetLineLength(lineNo
) + 1;
1537 // there must be at least enough place for the length WORD in the
1539 len
+= sizeof(WORD
);
1543 wxStringBufferLength
tmp(str
, len
);
1546 *(WORD
*)buf
= (WORD
)len
;
1547 len
= (size_t)::SendMessage(GetHwnd(), EM_GETLINE
, lineNo
, (LPARAM
)buf
);
1552 // remove the '\r' returned by the rich edit control, the user code
1553 // should never see it
1554 if ( buf
[len
- 2] == wxT('\r') && buf
[len
- 1] == wxT('\n') )
1556 // richedit 1.0 uses "\r\n" as line terminator, so remove "\r"
1557 // here and "\n" below
1558 buf
[len
- 2] = wxT('\n');
1561 else if ( buf
[len
- 1] == wxT('\r') )
1563 // richedit 2.0+ uses only "\r", replace it with "\n"
1564 buf
[len
- 1] = wxT('\n');
1567 #endif // wxUSE_RICHEDIT
1569 // remove the '\n' at the end, if any (this is how this function is
1570 // supposed to work according to the docs)
1571 if ( buf
[len
- 1] == wxT('\n') )
1583 void wxTextCtrl::SetMaxLength(unsigned long len
)
1588 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT
, 0, len
? len
: 0x7fffffff);
1591 #endif // wxUSE_RICHEDIT
1593 wxTextEntry::SetMaxLength(len
);
1597 // ----------------------------------------------------------------------------
1599 // ----------------------------------------------------------------------------
1601 void wxTextCtrl::Redo()
1604 if ( GetRichVersion() > 1 )
1606 ::SendMessage(GetHwnd(), EM_REDO
, 0, 0);
1609 #endif // wxUSE_RICHEDIT
1611 wxTextEntry::Redo();
1614 bool wxTextCtrl::CanRedo() const
1617 if ( GetRichVersion() > 1 )
1618 return ::SendMessage(GetHwnd(), EM_CANREDO
, 0, 0) != 0;
1619 #endif // wxUSE_RICHEDIT
1621 return wxTextEntry::CanRedo();
1624 // ----------------------------------------------------------------------------
1625 // caret handling (Windows only)
1626 // ----------------------------------------------------------------------------
1628 bool wxTextCtrl::ShowNativeCaret(bool show
)
1630 if ( show
!= m_isNativeCaretShown
)
1632 if ( !(show
? ::ShowCaret(GetHwnd()) : ::HideCaret(GetHwnd())) )
1634 // not an error, may simply indicate that it's not shown/hidden
1635 // yet (i.e. it had been hidden/shown 2 times before)
1639 m_isNativeCaretShown
= show
;
1645 // ----------------------------------------------------------------------------
1646 // implementation details
1647 // ----------------------------------------------------------------------------
1649 void wxTextCtrl::Command(wxCommandEvent
& event
)
1651 SetValue(event
.GetString());
1652 ProcessCommand (event
);
1655 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
1657 // By default, load the first file into the text window.
1658 if (event
.GetNumberOfFiles() > 0)
1660 LoadFile(event
.GetFiles()[0]);
1664 // ----------------------------------------------------------------------------
1665 // kbd input processing
1666 // ----------------------------------------------------------------------------
1668 bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG
* msg
)
1670 // check for our special keys here: if we don't do it and the parent frame
1671 // uses them as accelerators, they wouldn't work at all, so we disable
1672 // usual preprocessing for them
1673 if ( msg
->message
== WM_KEYDOWN
)
1675 const WPARAM vkey
= msg
->wParam
;
1676 if ( HIWORD(msg
->lParam
) & KF_ALTDOWN
)
1678 // Alt-Backspace is accelerator for "Undo"
1679 if ( vkey
== VK_BACK
)
1684 // we want to process some Ctrl-foo and Shift-bar but no key
1685 // combinations without either Ctrl or Shift nor with both of them
1687 const int ctrl
= wxIsCtrlDown(),
1688 shift
= wxIsShiftDown();
1689 switch ( ctrl
+ shift
)
1692 wxFAIL_MSG( wxT("how many modifiers have we got?") );
1696 if ( IsMultiLine() && vkey
== VK_RETURN
)
1703 // either Ctrl or Shift pressed
1718 else // Shift is pressed
1720 if ( vkey
== VK_INSERT
|| vkey
== VK_DELETE
)
1727 return wxControl::MSWShouldPreProcessMessage(msg
);
1730 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
1732 switch ( event
.GetKeyCode() )
1736 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1737 InitCommandEvent(event
);
1738 event
.SetString(GetValue());
1739 if ( HandleWindowEvent(event
) )
1740 if ( !HasFlag(wxTE_MULTILINE
) )
1742 //else: multiline controls need Enter for themselves
1747 // ok, so this is getting absolutely ridiculous but I don't see
1748 // any other way to fix this bug: when a multiline text control is
1749 // inside a wxFrame, we need to generate the navigation event as
1750 // otherwise nothing happens at all, but when the same control is
1751 // created inside a dialog, IsDialogMessage() *does* switch focus
1752 // all by itself and so if we do it here as well, it is advanced
1753 // twice and goes to the next control... to prevent this from
1754 // happening we're doing this ugly check, the logic being that if
1755 // we don't have focus then it had been already changed to the next
1758 // the right thing to do would, of course, be to understand what
1759 // the hell is IsDialogMessage() doing but this is beyond my feeble
1760 // forces at the moment unfortunately
1761 if ( !(m_windowStyle
& wxTE_PROCESS_TAB
))
1763 if ( FindFocus() == this )
1766 if (!event
.ShiftDown())
1767 flags
|= wxNavigationKeyEvent::IsForward
;
1768 if (event
.ControlDown())
1769 flags
|= wxNavigationKeyEvent::WinChange
;
1770 if (Navigate(flags
))
1776 // Insert tab since calling the default Windows handler
1777 // doesn't seem to do it
1778 WriteText(wxT("\t"));
1784 // no, we didn't process it
1788 void wxTextCtrl::OnKeyDown(wxKeyEvent
& event
)
1790 // richedit control doesn't send WM_PASTE, WM_CUT and WM_COPY messages
1791 // when Ctrl-V, X or C is pressed and this prevents wxClipboardTextEvent
1792 // from working. So we work around it by intercepting these shortcuts
1793 // ourselves and emitting clipboard events (which richedit will handle,
1794 // so everything works as before, including pasting of rich text):
1795 if ( event
.GetModifiers() == wxMOD_CONTROL
&& IsRich() )
1797 switch ( event
.GetKeyCode() )
1813 // no, we didn't process it
1817 WXLRESULT
wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1819 WXLRESULT lRc
= wxTextCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
1825 // we always want the chars and the arrows: the arrows for
1826 // navigation and the chars because we want Ctrl-C to work even
1827 // in a read only control
1828 long lDlgCode
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
1832 // we may have several different cases:
1833 // 1. normal: both TAB and ENTER are used for navigation
1834 // 2. ctrl wants TAB for itself: ENTER is used to pass to
1835 // the next control in the dialog
1836 // 3. ctrl wants ENTER for itself: TAB is used for dialog
1838 // 4. ctrl wants both TAB and ENTER: Ctrl-ENTER is used to
1839 // go to the next control (we need some way to do it)
1841 // multiline controls should always get ENTER for themselves
1842 if ( HasFlag(wxTE_PROCESS_ENTER
) || HasFlag(wxTE_MULTILINE
) )
1843 lDlgCode
|= DLGC_WANTMESSAGE
;
1845 if ( HasFlag(wxTE_PROCESS_TAB
) )
1846 lDlgCode
|= DLGC_WANTTAB
;
1852 // NB: use "=", not "|=" as the base class version returns
1853 // the same flags in the disabled state as usual (i.e.
1854 // including DLGC_WANTMESSAGE). This is strange (how
1855 // does it work in the native Win32 apps?) but for now
1864 // rich text controls seem to have a bug and don't change the
1865 // cursor to the standard arrow one from the I-beam cursor usually
1866 // used by them even when a popup menu is shown (this works fine
1867 // for plain EDIT controls though), so explicitly work around this
1870 extern wxMenu
*wxCurrentPopupMenu
;
1871 if ( wxCurrentPopupMenu
&&
1872 wxCurrentPopupMenu
->GetInvokingWindow() == this )
1873 ::SetCursor(GetHcursorOf(*wxSTANDARD_CURSOR
));
1875 #endif // wxUSE_MENUS
1881 // ----------------------------------------------------------------------------
1882 // text control event processing
1883 // ----------------------------------------------------------------------------
1885 bool wxTextCtrl::SendUpdateEvent()
1887 switch ( m_updatesCount
)
1890 // remember that we've got an update
1895 // we had already sent one event since the last control modification
1899 wxFAIL_MSG( wxT("unexpected wxTextCtrl::m_updatesCount value") );
1903 // we hadn't updated the control ourselves, this event comes from
1904 // the user, don't need to ignore it nor update the count
1908 // the control was updated programmatically and we do NOT want to
1913 return SendTextUpdatedEvent();
1916 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1925 // the text size limit has been hit -- try to increase it
1926 if ( !AdjustSpaceLimit() )
1928 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, m_windowId
);
1929 InitCommandEvent(event
);
1930 event
.SetString(GetValue());
1931 ProcessCommand(event
);
1935 // the other edit notification messages are not processed (or, in
1936 // the case of EN_{SET/KILL}FOCUS were already handled at WM_SET/
1946 WXHBRUSH
wxTextCtrl::MSWControlColor(WXHDC hDC
, WXHWND hWnd
)
1948 if ( !IsEnabled() && !HasFlag(wxTE_MULTILINE
) )
1949 return MSWControlColorDisabled(hDC
);
1951 return wxTextCtrlBase::MSWControlColor(hDC
, hWnd
);
1954 bool wxTextCtrl::HasSpaceLimit(unsigned int *len
) const
1956 // HACK: we try to automatically extend the limit for the amount of text
1957 // to allow (interactively) entering more than 64Kb of text under
1958 // Win9x but we shouldn't reset the text limit which was previously
1959 // set explicitly with SetMaxLength()
1961 // Unfortunately there is no EM_GETLIMITTEXTSETBYUSER and so we don't
1962 // know the limit we set (if any). We could solve this by storing the
1963 // limit we set in wxTextCtrl but to save space we prefer to simply
1964 // test here the actual limit value: we consider that SetMaxLength()
1965 // can only be called for small values while EN_MAXTEXT is only sent
1966 // for large values (in practice the default limit seems to be 30000
1967 // but make it smaller just to be on the safe side)
1968 *len
= ::SendMessage(GetHwnd(), EM_GETLIMITTEXT
, 0, 0);
1969 return *len
< 10001;
1973 bool wxTextCtrl::AdjustSpaceLimit()
1976 if ( HasSpaceLimit(&limit
) )
1979 unsigned int len
= ::GetWindowTextLength(GetHwnd());
1982 // increment in 32Kb chunks
1983 SetMaxLength(len
+ 0x8000);
1986 // we changed the limit
1990 bool wxTextCtrl::AcceptsFocusFromKeyboard() const
1992 // we don't want focus if we can't be edited unless we're a multiline
1993 // control because then it might be still nice to get focus from keyboard
1994 // to be able to scroll it without mouse
1995 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
1998 wxSize
wxTextCtrl::DoGetBestSize() const
2001 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
2003 int wText
= DEFAULT_ITEM_WIDTH
;
2006 if ( m_windowStyle
& wxTE_MULTILINE
)
2008 hText
*= wxMax(wxMin(GetNumberOfLines(), 10), 2);
2010 //else: for single line control everything is ok
2012 // we have to add the adjustments for the control height only once, not
2013 // once per line, so do it after multiplication above
2014 hText
+= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
) - cy
;
2016 return wxSize(wText
, hText
);
2019 // ----------------------------------------------------------------------------
2020 // standard handlers for standard edit menu events
2021 // ----------------------------------------------------------------------------
2023 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
2028 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
2033 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
2038 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
2043 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
2048 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
2053 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
2058 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
2060 event
.Enable( CanCut() );
2063 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
2065 event
.Enable( CanCopy() );
2068 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
2070 event
.Enable( CanPaste() );
2073 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
2075 event
.Enable( CanUndo() );
2078 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
2080 event
.Enable( CanRedo() );
2083 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
2085 event
.Enable( HasSelection() && IsEditable() );
2088 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
2090 event
.Enable( !IsEmpty() );
2093 void wxTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
2098 if (!m_privateContextMenu
)
2100 m_privateContextMenu
= new wxMenu
;
2101 m_privateContextMenu
->Append(wxID_UNDO
, _("&Undo"));
2102 m_privateContextMenu
->Append(wxID_REDO
, _("&Redo"));
2103 m_privateContextMenu
->AppendSeparator();
2104 m_privateContextMenu
->Append(wxID_CUT
, _("Cu&t"));
2105 m_privateContextMenu
->Append(wxID_COPY
, _("&Copy"));
2106 m_privateContextMenu
->Append(wxID_PASTE
, _("&Paste"));
2107 m_privateContextMenu
->Append(wxID_CLEAR
, _("&Delete"));
2108 m_privateContextMenu
->AppendSeparator();
2109 m_privateContextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
2111 PopupMenu(m_privateContextMenu
);
2119 void wxTextCtrl::OnSetFocus(wxFocusEvent
& event
)
2121 // be sure the caret remains invisible if the user had hidden it
2122 if ( !m_isNativeCaretShown
)
2124 ::HideCaret(GetHwnd());
2130 // the rest of the file only deals with the rich edit controls
2133 // ----------------------------------------------------------------------------
2134 // EN_LINK processing
2135 // ----------------------------------------------------------------------------
2137 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
2139 NMHDR
*hdr
= (NMHDR
* )lParam
;
2140 switch ( hdr
->code
)
2144 const MSGFILTER
*msgf
= (MSGFILTER
*)lParam
;
2145 UINT msg
= msgf
->msg
;
2147 // this is a bit crazy but richedit 1.0 sends us all mouse
2148 // events _except_ WM_LBUTTONUP (don't ask me why) so we have
2149 // generate the wxWin events for this message manually
2151 // NB: in fact, this is still not totally correct as it does
2152 // send us WM_LBUTTONUP if the selection was cleared by the
2153 // last click -- so currently we get 2 events in this case,
2154 // but as I don't see any obvious way to check for this I
2155 // leave this code in place because it's still better than
2156 // not getting left up events at all
2157 if ( msg
== WM_LBUTTONUP
)
2159 WXUINT flags
= msgf
->wParam
;
2160 int x
= GET_X_LPARAM(msgf
->lParam
),
2161 y
= GET_Y_LPARAM(msgf
->lParam
);
2163 HandleMouseEvent(msg
, x
, y
, flags
);
2167 // return true to process the event (and false to ignore it)
2172 const ENLINK
*enlink
= (ENLINK
*)hdr
;
2174 switch ( enlink
->msg
)
2177 // ok, so it is hardcoded - do we really nee to
2180 wxCursor
cur(wxCURSOR_HAND
);
2181 ::SetCursor(GetHcursorOf(cur
));
2187 case WM_LBUTTONDOWN
:
2189 case WM_LBUTTONDBLCLK
:
2190 case WM_RBUTTONDOWN
:
2192 case WM_RBUTTONDBLCLK
:
2193 // send a mouse event
2195 static const wxEventType eventsMouse
[] =
2206 // the event ids are consecutive
2208 evtMouse(eventsMouse
[enlink
->msg
- WM_MOUSEMOVE
]);
2210 InitMouseEvent(evtMouse
,
2211 GET_X_LPARAM(enlink
->lParam
),
2212 GET_Y_LPARAM(enlink
->lParam
),
2215 wxTextUrlEvent
event(m_windowId
, evtMouse
,
2217 enlink
->chrg
.cpMax
);
2219 InitCommandEvent(event
);
2221 *result
= ProcessCommand(event
);
2229 // not processed, leave it to the base class
2230 return wxTextCtrlBase::MSWOnNotify(idCtrl
, lParam
, result
);
2233 #if wxUSE_DRAG_AND_DROP
2235 void wxTextCtrl::SetDropTarget(wxDropTarget
*dropTarget
)
2237 if ( m_dropTarget
== wxRICHTEXT_DEFAULT_DROPTARGET
)
2239 // get rid of the built-in drop target
2240 ::RevokeDragDrop(GetHwnd());
2241 m_dropTarget
= NULL
;
2244 wxTextCtrlBase::SetDropTarget(dropTarget
);
2247 #endif // wxUSE_DRAG_AND_DROP
2249 // ----------------------------------------------------------------------------
2250 // colour setting for the rich edit controls
2251 // ----------------------------------------------------------------------------
2253 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
2255 if ( !wxTextCtrlBase::SetBackgroundColour(colour
) )
2257 // colour didn't really change
2263 // rich edit doesn't use WM_CTLCOLOR, hence we need to send
2264 // EM_SETBKGNDCOLOR additionally
2265 ::SendMessage(GetHwnd(), EM_SETBKGNDCOLOR
, 0, wxColourToRGB(colour
));
2271 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
2273 if ( !wxTextCtrlBase::SetForegroundColour(colour
) )
2275 // colour didn't really change
2281 // change the colour of everything
2284 cf
.cbSize
= sizeof(cf
);
2285 cf
.dwMask
= CFM_COLOR
;
2286 cf
.crTextColor
= wxColourToRGB(colour
);
2287 ::SendMessage(GetHwnd(), EM_SETCHARFORMAT
, SCF_ALL
, (LPARAM
)&cf
);
2293 bool wxTextCtrl::SetFont(const wxFont
& font
)
2295 if ( !wxTextCtrlBase::SetFont(font
) )
2298 if ( GetRichVersion() >= 4 )
2300 // Using WM_SETFONT is not enough with RichEdit 4.1: it does work but
2301 // for ASCII characters only and inserting a non-ASCII one into it
2302 // later reverts to the default font so use EM_SETCHARFORMAT to change
2303 // the default font for it.
2306 SetStyle(-1, -1, attr
);
2312 // ----------------------------------------------------------------------------
2313 // styling support for rich edit controls
2314 // ----------------------------------------------------------------------------
2316 bool wxTextCtrl::MSWSetCharFormat(const wxTextAttr
& style
, long start
, long end
)
2318 // initialize CHARFORMAT struct
2327 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
2328 // CHARFORMAT in that case
2330 if ( m_verRichEdit
== 1 )
2332 // this is the only thing the control is going to grok
2333 cf
.cbSize
= sizeof(CHARFORMAT
);
2338 // CHARFORMAT or CHARFORMAT2
2339 cf
.cbSize
= sizeof(cf
);
2342 if ( style
.HasFont() )
2344 // VZ: CFM_CHARSET doesn't seem to do anything at all in RichEdit 2.0
2345 // but using it doesn't seem to hurt neither so leaving it for now
2347 cf
.dwMask
|= CFM_FACE
| CFM_SIZE
| CFM_CHARSET
|
2348 CFM_ITALIC
| CFM_BOLD
| CFM_UNDERLINE
;
2350 // fill in data from LOGFONT but recalculate lfHeight because we need
2351 // the real height in twips and not the negative number which
2352 // wxFillLogFont() returns (this is correct in general and works with
2353 // the Windows font mapper, but not here)
2355 wxFont
font(style
.GetFont());
2358 wxFillLogFont(&lf
, &font
);
2359 cf
.yHeight
= 20*font
.GetPointSize(); // 1 pt = 20 twips
2360 cf
.bCharSet
= lf
.lfCharSet
;
2361 cf
.bPitchAndFamily
= lf
.lfPitchAndFamily
;
2362 wxStrlcpy(cf
.szFaceName
, lf
.lfFaceName
, WXSIZEOF(cf
.szFaceName
));
2364 // also deal with underline/italic/bold attributes: note that we must
2365 // always set CFM_ITALIC &c bits in dwMask, even if we don't set the
2366 // style to allow clearing it
2369 cf
.dwEffects
|= CFE_ITALIC
;
2372 if ( lf
.lfWeight
== FW_BOLD
)
2374 cf
.dwEffects
|= CFE_BOLD
;
2377 if ( lf
.lfUnderline
)
2379 cf
.dwEffects
|= CFE_UNDERLINE
;
2382 // strikeout fonts are not supported by wxWidgets
2385 if ( style
.HasTextColour() )
2387 cf
.dwMask
|= CFM_COLOR
;
2388 cf
.crTextColor
= wxColourToRGB(style
.GetTextColour());
2392 if ( m_verRichEdit
!= 1 && style
.HasBackgroundColour() )
2394 cf
.dwMask
|= CFM_BACKCOLOR
;
2395 cf
.crBackColor
= wxColourToRGB(style
.GetBackgroundColour());
2397 #endif // wxUSE_RICHEDIT2
2399 // Apply the style either to the selection or to the entire control.
2401 if ( start
!= -1 || end
!= -1 )
2403 DoSetSelection(start
, end
, SetSel_NoScroll
);
2404 selMode
= SCF_SELECTION
;
2411 if ( !::SendMessage(GetHwnd(), EM_SETCHARFORMAT
, selMode
, (LPARAM
)&cf
) )
2413 wxLogLastError(wxT("SendMessage(EM_SETCHARFORMAT)"));
2420 bool wxTextCtrl::MSWSetParaFormat(const wxTextAttr
& style
, long start
, long end
)
2430 // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
2431 // PARAFORMAT in that case
2433 if ( m_verRichEdit
== 1 )
2435 // this is the only thing the control is going to grok
2436 pf
.cbSize
= sizeof(PARAFORMAT
);
2441 // PARAFORMAT or PARAFORMAT2
2442 pf
.cbSize
= sizeof(pf
);
2445 if (style
.HasAlignment())
2447 pf
.dwMask
|= PFM_ALIGNMENT
;
2448 if (style
.GetAlignment() == wxTEXT_ALIGNMENT_RIGHT
)
2449 pf
.wAlignment
= PFA_RIGHT
;
2450 else if (style
.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE
)
2451 pf
.wAlignment
= PFA_CENTER
;
2452 else if (style
.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED
)
2453 pf
.wAlignment
= PFA_JUSTIFY
;
2455 pf
.wAlignment
= PFA_LEFT
;
2458 if (style
.HasLeftIndent())
2460 pf
.dwMask
|= PFM_STARTINDENT
| PFM_OFFSET
;
2462 // Convert from 1/10 mm to TWIPS
2463 pf
.dxStartIndent
= (int) (((double) style
.GetLeftIndent()) * mm2twips
/ 10.0) ;
2464 pf
.dxOffset
= (int) (((double) style
.GetLeftSubIndent()) * mm2twips
/ 10.0) ;
2467 if (style
.HasRightIndent())
2469 pf
.dwMask
|= PFM_RIGHTINDENT
;
2471 // Convert from 1/10 mm to TWIPS
2472 pf
.dxRightIndent
= (int) (((double) style
.GetRightIndent()) * mm2twips
/ 10.0) ;
2475 if (style
.HasTabs())
2477 pf
.dwMask
|= PFM_TABSTOPS
;
2479 const wxArrayInt
& tabs
= style
.GetTabs();
2481 pf
.cTabCount
= (SHORT
)wxMin(tabs
.GetCount(), MAX_TAB_STOPS
);
2483 for (i
= 0; i
< (size_t) pf
.cTabCount
; i
++)
2485 // Convert from 1/10 mm to TWIPS
2486 pf
.rgxTabs
[i
] = (int) (((double) tabs
[i
]) * mm2twips
/ 10.0) ;
2491 if ( m_verRichEdit
> 1 )
2493 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2495 // Use RTL paragraphs in RTL mode to get proper layout
2496 pf
.dwMask
|= PFM_RTLPARA
;
2497 pf
.wEffects
|= PFE_RTLPARA
;
2500 #endif // wxUSE_RICHEDIT2
2504 // Do format the selection.
2505 DoSetSelection(start
, end
, SetSel_NoScroll
);
2507 if ( !::SendMessage(GetHwnd(), EM_SETPARAFORMAT
, 0, (LPARAM
) &pf
) )
2509 wxLogLastError(wxT("SendMessage(EM_SETPARAFORMAT)"));
2518 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
2522 // can't do it with normal text control
2526 // the richedit 1.0 doesn't handle setting background colour, so don't
2527 // even try to do anything if it's the only thing we want to change
2528 if ( m_verRichEdit
== 1 && !style
.HasFont() && !style
.HasTextColour() &&
2529 !style
.HasLeftIndent() && !style
.HasRightIndent() && !style
.HasAlignment() &&
2532 // nothing to do: return true if there was really nothing to do and
2533 // false if we failed to set bg colour
2534 return !style
.HasBackgroundColour();
2537 // order the range if needed
2541 // we can only change the format of the selection, so select the range we
2542 // want and restore the old selection later, after MSWSetXXXFormat()
2543 // functions (possibly) change it.
2544 long startOld
, endOld
;
2545 GetSelection(&startOld
, &endOld
);
2547 bool ok
= MSWSetCharFormat(style
, start
, end
);
2548 if ( !MSWSetParaFormat(style
, start
, end
) )
2551 if ( start
!= startOld
|| end
!= endOld
)
2553 // restore the original selection
2554 DoSetSelection(startOld
, endOld
, SetSel_NoScroll
);
2560 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
2562 if ( !wxTextCtrlBase::SetDefaultStyle(style
) )
2567 // we have to do this or the style wouldn't apply for the text typed by
2569 wxTextPos posLast
= GetLastPosition();
2570 SetStyle(posLast
, posLast
, m_defaultStyle
);
2576 bool wxTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
2580 // can't do it with normal text control
2584 // initialize CHARFORMAT struct
2593 // we can't use CHARFORMAT2 with RichEdit 1.0, so pretend it is a simple
2594 // CHARFORMAT in that case
2596 if ( m_verRichEdit
== 1 )
2598 // this is the only thing the control is going to grok
2599 cf
.cbSize
= sizeof(CHARFORMAT
);
2604 // CHARFORMAT or CHARFORMAT2
2605 cf
.cbSize
= sizeof(cf
);
2607 // we can only change the format of the selection, so select the range we
2608 // want and restore the old selection later
2609 long startOld
, endOld
;
2610 GetSelection(&startOld
, &endOld
);
2612 // but do we really have to change the selection?
2613 bool changeSel
= position
!= startOld
|| position
!= endOld
;
2617 DoSetSelection(position
, position
+ 1, SetSel_NoScroll
);
2620 // get the selection formatting
2621 (void) ::SendMessage(GetHwnd(), EM_GETCHARFORMAT
,
2622 SCF_SELECTION
, (LPARAM
)&cf
) ;
2626 lf
.lfHeight
= cf
.yHeight
;
2628 lf
.lfCharSet
= ANSI_CHARSET
; // FIXME: how to get correct charset?
2629 lf
.lfClipPrecision
= 0;
2630 lf
.lfEscapement
= 0;
2631 wxStrcpy(lf
.lfFaceName
, cf
.szFaceName
);
2633 //NOTE: we _MUST_ set each of these values to _something_ since we
2634 //do not call wxZeroMemory on the LOGFONT lf
2635 if (cf
.dwEffects
& CFE_ITALIC
)
2638 lf
.lfItalic
= FALSE
;
2640 lf
.lfOrientation
= 0;
2641 lf
.lfPitchAndFamily
= cf
.bPitchAndFamily
;
2644 if (cf
.dwEffects
& CFE_STRIKEOUT
)
2645 lf
.lfStrikeOut
= TRUE
;
2647 lf
.lfStrikeOut
= FALSE
;
2649 if (cf
.dwEffects
& CFE_UNDERLINE
)
2650 lf
.lfUnderline
= TRUE
;
2652 lf
.lfUnderline
= FALSE
;
2654 if (cf
.dwEffects
& CFE_BOLD
)
2655 lf
.lfWeight
= FW_BOLD
;
2657 lf
.lfWeight
= FW_NORMAL
;
2659 wxFont font
= wxCreateFontFromLogFont(& lf
);
2662 style
.SetFont(font
);
2664 style
.SetTextColour(wxColour(cf
.crTextColor
));
2667 if ( m_verRichEdit
!= 1 )
2669 // cf.dwMask |= CFM_BACKCOLOR;
2670 style
.SetBackgroundColour(wxColour(cf
.crBackColor
));
2672 #endif // wxUSE_RICHEDIT2
2674 // now get the paragraph formatting
2677 // we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
2678 // PARAFORMAT in that case
2680 if ( m_verRichEdit
== 1 )
2682 // this is the only thing the control is going to grok
2683 pf
.cbSize
= sizeof(PARAFORMAT
);
2688 // PARAFORMAT or PARAFORMAT2
2689 pf
.cbSize
= sizeof(pf
);
2692 // do format the selection
2693 (void) ::SendMessage(GetHwnd(), EM_GETPARAFORMAT
, 0, (LPARAM
) &pf
) ;
2695 style
.SetLeftIndent( (int) ((double) pf
.dxStartIndent
* twips2mm
* 10.0), (int) ((double) pf
.dxOffset
* twips2mm
* 10.0) );
2696 style
.SetRightIndent( (int) ((double) pf
.dxRightIndent
* twips2mm
* 10.0) );
2698 if (pf
.wAlignment
== PFA_CENTER
)
2699 style
.SetAlignment(wxTEXT_ALIGNMENT_CENTRE
);
2700 else if (pf
.wAlignment
== PFA_RIGHT
)
2701 style
.SetAlignment(wxTEXT_ALIGNMENT_RIGHT
);
2702 else if (pf
.wAlignment
== PFA_JUSTIFY
)
2703 style
.SetAlignment(wxTEXT_ALIGNMENT_JUSTIFIED
);
2705 style
.SetAlignment(wxTEXT_ALIGNMENT_LEFT
);
2707 wxArrayInt tabStops
;
2709 for (i
= 0; i
< (size_t) pf
.cTabCount
; i
++)
2711 tabStops
.Add( (int) ((double) (pf
.rgxTabs
[i
] & 0xFFFF) * twips2mm
* 10.0) );
2716 // restore the original selection
2717 DoSetSelection(startOld
, endOld
, SetSel_NoScroll
);
2723 // ----------------------------------------------------------------------------
2725 // ----------------------------------------------------------------------------
2727 static const HINSTANCE INVALID_HINSTANCE
= (HINSTANCE
)-1;
2729 bool wxRichEditModule::OnInit()
2731 // don't do anything - we will load it when needed
2735 void wxRichEditModule::OnExit()
2737 for ( size_t i
= 0; i
< WXSIZEOF(ms_hRichEdit
); i
++ )
2739 if ( ms_hRichEdit
[i
] && ms_hRichEdit
[i
] != INVALID_HINSTANCE
)
2741 ::FreeLibrary(ms_hRichEdit
[i
]);
2742 ms_hRichEdit
[i
] = NULL
;
2746 if (ms_inkEditLib
.IsLoaded())
2747 ms_inkEditLib
.Unload();
2752 bool wxRichEditModule::Load(Version version
)
2754 if ( ms_hRichEdit
[version
] == INVALID_HINSTANCE
)
2756 // we had already tried to load it and failed
2760 if ( ms_hRichEdit
[version
] )
2762 // we've already got this one
2766 static const wxChar
*const dllnames
[] =
2773 wxCOMPILE_TIME_ASSERT( WXSIZEOF(dllnames
) == Version_Max
,
2774 RichEditDllNamesVersionsMismatch
);
2776 ms_hRichEdit
[version
] = ::LoadLibrary(dllnames
[version
]);
2778 if ( !ms_hRichEdit
[version
] )
2780 ms_hRichEdit
[version
] = INVALID_HINSTANCE
;
2789 // load the InkEdit library
2790 bool wxRichEditModule::LoadInkEdit()
2792 if (ms_inkEditLibLoadAttemped
)
2793 return ms_inkEditLib
.IsLoaded();
2795 ms_inkEditLibLoadAttemped
= true;
2798 return ms_inkEditLib
.Load(wxT("inked"));
2800 #endif // wxUSE_INKEDIT
2803 #endif // wxUSE_RICHEDIT
2805 #endif // wxUSE_TEXTCTRL && !(__SMARTPHONE__ && __WXWINCE__)