1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "textctrl.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/textctrl.h"
33 #include "wx/settings.h"
42 #include "wx/clipbrd.h"
45 #include "wx/textfile.h"
49 #include "wx/msw/private.h"
53 #include <sys/types.h>
61 #if wxUSE_RICHEDIT && !defined(__GNUWIN32_OLD__)
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
71 // this module initializes RichEdit DLL if needed
72 class wxRichEditModule
: public wxModule
75 virtual bool OnInit();
76 virtual void OnExit();
78 // get the version currently loaded, -1 if none
79 static int GetLoadedVersion() { return ms_verRichEdit
; }
81 // load the richedit DLL of at least of required version
82 static bool Load(int version
= 1);
85 // the handle to richedit DLL and the version of the DLL loaded
86 static HINSTANCE ms_hRichEdit
;
88 // the DLL version loaded or -1 if none
89 static int ms_verRichEdit
;
91 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
94 HINSTANCE
wxRichEditModule::ms_hRichEdit
= (HINSTANCE
)NULL
;
95 int wxRichEditModule::ms_verRichEdit
= -1;
97 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
99 #endif // wxUSE_RICHEDIT
101 // ----------------------------------------------------------------------------
102 // event tables and other macros
103 // ----------------------------------------------------------------------------
105 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
107 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
108 EVT_CHAR(wxTextCtrl::OnChar
)
109 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
111 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
112 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
113 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
114 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
115 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
117 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
118 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
119 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
120 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
121 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
125 // ============================================================================
127 // ============================================================================
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 wxTextCtrl::wxTextCtrl()
140 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
141 const wxString
& value
,
145 const wxValidator
& validator
,
146 const wxString
& name
)
148 // base initialization
149 if ( !CreateBase(parent
, id
, pos
, size
, style
, validator
, name
) )
153 parent
->AddChild(this);
155 // translate wxWin style flags to MSW ones, checking for consistency while
157 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
158 if ( m_windowStyle
& wxTE_MULTILINE
)
160 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
161 wxT("wxTE_PROCESS_ENTER style is ignored for multiline "
162 "text controls (they always process it)") );
164 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
;
165 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
166 msStyle
|= WS_VSCROLL
;
167 m_windowStyle
|= wxTE_PROCESS_ENTER
;
170 msStyle
|= ES_AUTOHSCROLL
;
172 if (m_windowStyle
& wxHSCROLL
)
173 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
);
175 if (m_windowStyle
& wxTE_READONLY
)
176 msStyle
|= ES_READONLY
;
178 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
179 msStyle
|= ES_PASSWORD
;
181 // we always want the characters and the arrows
182 m_lDlgCode
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
184 // we may have several different cases:
185 // 1. normal case: both TAB and ENTER are used for dialog navigation
186 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
187 // control in the dialog
188 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
189 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
191 if ( m_windowStyle
& wxTE_PROCESS_ENTER
)
192 m_lDlgCode
|= DLGC_WANTMESSAGE
;
193 if ( m_windowStyle
& wxTE_PROCESS_TAB
)
194 m_lDlgCode
|= DLGC_WANTTAB
;
196 // do create the control - either an EDIT or RICHEDIT
197 wxString windowClass
= wxT("EDIT");
200 if ( m_windowStyle
& wxTE_RICH
)
202 static bool s_errorGiven
= FALSE
; // MT-FIXME
204 // only give the error msg once if the DLL can't be loaded
207 // first try to load the RichEdit DLL (will do nothing if already
209 if ( !wxRichEditModule::Load() )
211 wxLogError(_("Impossible to create a rich edit control, "
212 "using simple text control instead. Please "
213 "reinstall riched32.dll"));
225 msStyle
|= ES_AUTOVSCROLL
;
228 int ver
= wxRichEditModule::GetLoadedVersion();
231 windowClass
= wxT("RICHEDIT");
235 #ifndef RICHEDIT_CLASS
236 wxString RICHEDIT_CLASS
;
237 RICHEDIT_CLASS
.Printf(_T("RichEdit%d0"), ver
);
239 RICHEDIT_CLASS
+= _T('W');
241 RICHEDIT_CLASS
+= _T('A');
242 #endif // Unicode/ANSI
243 #endif // !RICHEDIT_CLASS
245 windowClass
= RICHEDIT_CLASS
;
251 #endif // wxUSE_RICHEDIT
254 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
256 // Even with extended styles, need to combine with WS_BORDER for them to
258 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
259 msStyle
|= WS_BORDER
;
261 // NB: don't use pos and size as CreateWindowEx arguments because they
262 // might be -1 in which case we should use the default values (and
263 // SetSize called below takes care of it)
264 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
,
274 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create text ctrl") );
279 Ctl3dSubclassCtl(GetHwnd());
287 // Have to enable events
288 ::SendMessage(GetHwnd(), EM_SETEVENTMASK
, 0,
289 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
293 SubclassWin(GetHWND());
295 // set font, position, size and initial value
296 wxFont
& fontParent
= parent
->GetFont();
297 if ( fontParent
.Ok() )
303 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
306 // Causes a crash for Symantec C++ and WIN32 for some reason
307 #if !(defined(__SC__) && defined(__WIN32__))
308 if ( !value
.IsEmpty() )
317 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
322 // Make sure the window style (etc.) reflects the HWND style (roughly)
323 void wxTextCtrl::AdoptAttributesFromHWND()
325 wxWindow::AdoptAttributesFromHWND();
327 HWND hWnd
= GetHwnd();
328 long style
= GetWindowLong(hWnd
, GWL_STYLE
);
330 // retrieve the style to see whether this is an edit or richedit ctrl
334 GetClassName(hWnd
, buf
, WXSIZEOF(buf
));
336 if ( wxStricmp(buf
, wxT("EDIT")) == 0 )
340 #endif // wxUSE_RICHEDIT
342 if (style
& ES_MULTILINE
)
343 m_windowStyle
|= wxTE_MULTILINE
;
344 if (style
& ES_PASSWORD
)
345 m_windowStyle
|= wxTE_PASSWORD
;
346 if (style
& ES_READONLY
)
347 m_windowStyle
|= wxTE_READONLY
;
348 if (style
& ES_WANTRETURN
)
349 m_windowStyle
|= wxTE_PROCESS_ENTER
;
352 void wxTextCtrl::SetupColours()
354 wxColour bkgndColour
;
355 if (IsEditable() || (m_windowStyle
& wxTE_MULTILINE
))
356 bkgndColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
);
358 bkgndColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
360 SetBackgroundColour(bkgndColour
);
361 SetForegroundColour(GetParent()->GetForegroundColour());
364 // ----------------------------------------------------------------------------
365 // set/get the controls text
366 // ----------------------------------------------------------------------------
368 wxString
wxTextCtrl::GetValue() const
370 // we can't use wxGetWindowText() (i.e. WM_GETTEXT internally) for
371 // retrieving more than 64Kb under Win9x
375 int len
= GetWindowTextLength(GetHwnd()) + 1;
378 wxChar
*p
= str
.GetWriteBuf(len
);
381 textRange
.chrg
.cpMin
= 0;
382 textRange
.chrg
.cpMax
= -1;
383 textRange
.lpstrText
= p
;
385 (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
387 // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for the
388 // newlines which is neither Unix nor Windows style (Win95 with
389 // riched20.dll shows this behaviour) - convert it to something
393 if ( *p
== _T('\r') )
401 #endif // wxUSE_RICHEDIT
403 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
404 // same one as above for consitency
405 wxString str
= wxGetWindowText(GetHWND());
407 return wxTextFile::Translate(str
, wxTextFileType_Unix
);
410 void wxTextCtrl::SetValue(const wxString
& value
)
412 // if the text is long enough, it's faster to just set it instead of first
413 // comparing it with the old one (chances are that it will be different
414 // anyhow, this comparison is there to avoid flicker for small single-line
415 // edit controls mostly)
416 if ( (value
.length() > 0x400) || (value
!= GetValue()) )
418 wxString valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
420 SetWindowText(GetHwnd(), valueDos
.c_str());
426 void wxTextCtrl::WriteText(const wxString
& value
)
428 wxString valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
430 SendMessage(GetHwnd(), EM_REPLACESEL
, 0, (LPARAM
)valueDos
.c_str());
435 void wxTextCtrl::AppendText(const wxString
& text
)
437 SetInsertionPointEnd();
441 void wxTextCtrl::Clear()
443 SetWindowText(GetHwnd(), wxT(""));
446 // ----------------------------------------------------------------------------
447 // Clipboard operations
448 // ----------------------------------------------------------------------------
450 void wxTextCtrl::Copy()
454 HWND hWnd
= GetHwnd();
455 SendMessage(hWnd
, WM_COPY
, 0, 0L);
459 void wxTextCtrl::Cut()
463 HWND hWnd
= GetHwnd();
464 SendMessage(hWnd
, WM_CUT
, 0, 0L);
468 void wxTextCtrl::Paste()
472 HWND hWnd
= GetHwnd();
473 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
477 bool wxTextCtrl::CanCopy() const
479 // Can copy if there's a selection
481 GetSelection(& from
, & to
);
485 bool wxTextCtrl::CanCut() const
487 // Can cut if there's a selection
489 GetSelection(& from
, & to
);
493 bool wxTextCtrl::CanPaste() const
498 int dataFormat
= 0; // 0 == any format
499 return (::SendMessage( GetHwnd(), EM_CANPASTE
, (WPARAM
) (UINT
) dataFormat
, 0) != 0);
505 // Standard edit control: check for straight text on clipboard
506 bool isTextAvailable
= FALSE
;
507 if ( ::OpenClipboard(GetHwndOf(wxTheApp
->GetTopWindow())) )
509 isTextAvailable
= (::IsClipboardFormatAvailable(CF_TEXT
) != 0);
513 return isTextAvailable
;
516 // ----------------------------------------------------------------------------
518 // ----------------------------------------------------------------------------
520 void wxTextCtrl::SetEditable(bool editable
)
522 bool isEditable
= IsEditable();
524 HWND hWnd
= GetHwnd();
525 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
527 if (editable
!= isEditable
)
534 void wxTextCtrl::SetInsertionPoint(long pos
)
536 HWND hWnd
= GetHwnd();
544 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
545 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
548 #endif // wxUSE_RICHEDIT
550 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
551 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
554 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
557 static const char *nothing
= "";
558 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
561 void wxTextCtrl::SetInsertionPointEnd()
563 long pos
= GetLastPosition();
564 SetInsertionPoint(pos
);
567 long wxTextCtrl::GetInsertionPoint() const
575 SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
580 DWORD Pos
= (DWORD
)SendMessage(GetHwnd(), EM_GETSEL
, 0, 0L);
584 long wxTextCtrl::GetLastPosition() const
586 HWND hWnd
= GetHwnd();
588 // Will always return a number > 0 (according to docs)
589 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
591 // This gets the char index for the _beginning_ of the last line
592 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
594 // Get number of characters in the last line. We'll add this to the character
595 // index for the last line, 1st position.
596 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
598 return (long)(charIndex
+ lineLength
);
601 // If the return values from and to are the same, there is no
603 void wxTextCtrl::GetSelection(long* from
, long* to
) const
609 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) (CHARRANGE
*) & charRange
);
611 *from
= charRange
.cpMin
;
612 *to
= charRange
.cpMax
;
617 DWORD dwStart
, dwEnd
;
618 WPARAM wParam
= (WPARAM
) (DWORD
*) & dwStart
; // receives starting position
619 LPARAM lParam
= (LPARAM
) (DWORD
*) & dwEnd
; // receives ending position
621 ::SendMessage(GetHwnd(), EM_GETSEL
, wParam
, lParam
);
627 bool wxTextCtrl::IsEditable() const
629 long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
631 return ((style
& ES_READONLY
) == 0);
634 // ----------------------------------------------------------------------------
636 // ----------------------------------------------------------------------------
638 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
641 HWND hWnd
= GetHwnd();
642 long fromChar
= from
;
645 // Set selection and remove it
647 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
649 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
651 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
653 // Now replace with 'value', by pasting.
654 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)value
, 0, 0);
656 // Paste into edit control
657 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
659 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
663 void wxTextCtrl::Remove(long from
, long to
)
665 HWND hWnd
= GetHwnd();
666 long fromChar
= from
;
669 // Cut all selected text
671 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
673 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
675 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
678 void wxTextCtrl::SetSelection(long from
, long to
)
680 HWND hWnd
= GetHwnd();
681 long fromChar
= from
;
684 // if from and to are both -1, it means (in wxWindows) that all text should
685 // be selected. Translate into Windows convention
686 if ((from
== -1) && (to
== -1))
693 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
694 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
696 // WPARAM is 0: selection is scrolled into view
697 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
701 bool wxTextCtrl::LoadFile(const wxString
& file
)
703 if ( wxTextCtrlBase::LoadFile(file
) )
705 // update the size limit if needed
714 bool wxTextCtrl::IsModified() const
716 return (SendMessage(GetHwnd(), EM_GETMODIFY
, 0, 0) != 0);
719 // Makes 'unmodified'
720 void wxTextCtrl::DiscardEdits()
722 SendMessage(GetHwnd(), EM_SETMODIFY
, FALSE
, 0L);
725 int wxTextCtrl::GetNumberOfLines() const
727 return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
730 long wxTextCtrl::XYToPosition(long x
, long y
) const
732 HWND hWnd
= GetHwnd();
734 // This gets the char index for the _beginning_ of this line
735 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
736 return (long)(x
+ charIndex
);
739 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
741 HWND hWnd
= GetHwnd();
743 // This gets the line number containing the character
748 lineNo
= (int)SendMessage(hWnd
, EM_EXLINEFROMCHAR
, 0, (LPARAM
)pos
);
751 #endif // wxUSE_RICHEDIT
752 lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, 0);
760 // This gets the char index for the _beginning_ of this line
761 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
762 if ( charIndex
== -1 )
767 // The X position must therefore be the different between pos and charIndex
769 *x
= (long)(pos
- charIndex
);
776 void wxTextCtrl::ShowPosition(long pos
)
778 HWND hWnd
= GetHwnd();
780 // To scroll to a position, we pass the number of lines and characters
781 // to scroll *by*. This means that we need to:
782 // (1) Find the line position of the current line.
783 // (2) Find the line position of pos.
784 // (3) Scroll by (pos - current).
785 // For now, ignore the horizontal scrolling.
787 // Is this where scrolling is relative to - the line containing the caret?
788 // Or is the first visible line??? Try first visible line.
789 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
791 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
793 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
795 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
797 if (linesToScroll
!= 0)
798 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)linesToScroll
);
801 int wxTextCtrl::GetLineLength(long lineNo
) const
803 long charIndex
= XYToPosition(0, lineNo
);
804 int len
= (int)SendMessage(GetHwnd(), EM_LINELENGTH
, charIndex
, 0);
808 wxString
wxTextCtrl::GetLineText(long lineNo
) const
810 size_t len
= (size_t)GetLineLength(lineNo
) + 1;
811 char *buf
= (char *)malloc(len
);
813 int noChars
= (int)SendMessage(GetHwnd(), EM_GETLINE
, lineNo
, (LPARAM
)buf
);
823 // ----------------------------------------------------------------------------
825 // ----------------------------------------------------------------------------
827 void wxTextCtrl::Undo()
831 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
835 void wxTextCtrl::Redo()
839 // Same as Undo, since Undo undoes the undo, i.e. a redo.
840 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
844 bool wxTextCtrl::CanUndo() const
846 return (::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0);
849 bool wxTextCtrl::CanRedo() const
851 return (::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0);
854 // ----------------------------------------------------------------------------
855 // implemenation details
856 // ----------------------------------------------------------------------------
858 void wxTextCtrl::Command(wxCommandEvent
& event
)
860 SetValue(event
.GetString());
861 ProcessCommand (event
);
864 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
866 // By default, load the first file into the text window.
867 if (event
.GetNumberOfFiles() > 0)
869 LoadFile(event
.GetFiles()[0]);
873 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
875 switch ( event
.KeyCode() )
878 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
880 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
881 event
.SetEventObject( this );
882 if ( GetEventHandler()->ProcessEvent(event
) )
885 //else: multiline controls need Enter for themselves
890 // always produce navigation event - even if we process TAB
891 // ourselves the fact that we got here means that the user code
892 // decided to skip processing of this TAB - probably to let it
893 // do its default job.
895 wxNavigationKeyEvent eventNav
;
896 eventNav
.SetDirection(!event
.ShiftDown());
897 eventNav
.SetWindowChange(event
.ControlDown());
898 eventNav
.SetEventObject(this);
900 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
906 // no, we didn't process it
910 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
917 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
920 event
.SetEventObject( this );
921 GetEventHandler()->ProcessEvent(event
);
927 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
928 event
.SetEventObject( this );
929 event
.SetString( GetValue() );
930 ProcessCommand( event
);
935 // the text size limit has been hit - increase it
939 // the other notification messages are not processed
952 void wxTextCtrl::AdjustSpaceLimit()
955 unsigned int len
= ::GetWindowTextLength(GetHwnd()),
956 limit
= ::SendMessage(GetHwnd(), EM_GETLIMITTEXT
, 0, 0);
959 limit
= len
+ 0x8000; // 32Kb
964 // as a nice side effect, this also allows passing limit > 64Kb
965 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT
, 0, limit
);
968 #endif // wxUSE_RICHEDIT
970 if ( limit
> 0xffff )
972 // this will set it to a platform-dependent maximum (much more
973 // than 64Kb under NT)
977 ::SendMessage(GetHwnd(), EM_LIMITTEXT
, limit
, 0);
983 bool wxTextCtrl::AcceptsFocus() const
985 // we don't want focus if we can't be edited
986 return IsEditable() && wxControl::AcceptsFocus();
989 wxSize
wxTextCtrl::DoGetBestSize() const
992 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
994 int wText
= DEFAULT_ITEM_WIDTH
;
996 int hText
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
997 if ( m_windowStyle
& wxTE_MULTILINE
)
999 hText
*= wxMin(GetNumberOfLines(), 5);
1001 //else: for single line control everything is ok
1003 return wxSize(wText
, hText
);
1006 // ----------------------------------------------------------------------------
1007 // standard handlers for standard edit menu events
1008 // ----------------------------------------------------------------------------
1010 void wxTextCtrl::OnCut(wxCommandEvent
& event
)
1015 void wxTextCtrl::OnCopy(wxCommandEvent
& event
)
1020 void wxTextCtrl::OnPaste(wxCommandEvent
& event
)
1025 void wxTextCtrl::OnUndo(wxCommandEvent
& event
)
1030 void wxTextCtrl::OnRedo(wxCommandEvent
& event
)
1035 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1037 event
.Enable( CanCut() );
1040 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1042 event
.Enable( CanCopy() );
1045 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1047 event
.Enable( CanPaste() );
1050 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1052 event
.Enable( CanUndo() );
1055 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1057 event
.Enable( CanRedo() );
1060 // ----------------------------------------------------------------------------
1062 // ----------------------------------------------------------------------------
1066 bool wxRichEditModule::OnInit()
1068 // don't do anything - we will load it when needed
1072 void wxRichEditModule::OnExit()
1076 FreeLibrary(ms_hRichEdit
);
1081 bool wxRichEditModule::Load(int version
)
1083 wxCHECK_MSG( version
>= 1 && version
<= 3, FALSE
,
1084 _T("incorrect richedit control version requested") );
1086 if ( version
<= ms_verRichEdit
)
1088 // we've already got this or better
1094 ::FreeLibrary(ms_hRichEdit
);
1097 // always try load riched20.dll first - like this we won't have to reload
1098 // it later if we're first asked for RE 1 and then for RE 2 or 3
1099 wxString dllname
= _T("riched20.dll");
1100 ms_hRichEdit
= ::LoadLibrary(dllname
);
1101 ms_verRichEdit
= 2; // no way to tell if it's 2 or 3, assume 2
1103 if ( !ms_hRichEdit
&& (version
== 1) )
1105 // fall back to RE 1
1106 dllname
= _T("riched32.dll");
1107 ms_hRichEdit
= ::LoadLibrary(dllname
);
1111 if ( !ms_hRichEdit
)
1113 wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname
.c_str());
1115 ms_verRichEdit
= -1;
1123 #endif // wxUSE_RICHEDIT