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__) || defined(wxUSE_NORLANDER_HEADERS))
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);
158 // translate wxWin style flags to MSW ones, checking for consistency while
160 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
161 if ( m_windowStyle
& wxTE_MULTILINE
)
163 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
164 wxT("wxTE_PROCESS_ENTER style is ignored for multiline "
165 "text controls (they always process it)") );
167 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
;
168 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
169 msStyle
|= WS_VSCROLL
;
170 m_windowStyle
|= wxTE_PROCESS_ENTER
;
173 msStyle
|= ES_AUTOHSCROLL
;
175 if (m_windowStyle
& wxHSCROLL
)
176 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
);
178 if (m_windowStyle
& wxTE_READONLY
)
179 msStyle
|= ES_READONLY
;
181 if (m_windowStyle
& wxHSCROLL
)
182 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
);
183 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
184 msStyle
|= ES_PASSWORD
;
186 // we always want the characters and the arrows
187 m_lDlgCode
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
189 // we may have several different cases:
190 // 1. normal case: both TAB and ENTER are used for dialog navigation
191 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
192 // control in the dialog
193 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
194 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
196 if ( m_windowStyle
& wxTE_PROCESS_ENTER
)
197 m_lDlgCode
|= DLGC_WANTMESSAGE
;
198 if ( m_windowStyle
& wxTE_PROCESS_TAB
)
199 m_lDlgCode
|= DLGC_WANTTAB
;
201 // do create the control - either an EDIT or RICHEDIT
202 wxString windowClass
= wxT("EDIT");
205 if ( m_windowStyle
& wxTE_RICH
)
207 static bool s_errorGiven
= FALSE
; // MT-FIXME
209 // only give the error msg once if the DLL can't be loaded
212 // first try to load the RichEdit DLL (will do nothing if already
214 if ( !wxRichEditModule::Load() )
216 wxLogError(_("Impossible to create a rich edit control, "
217 "using simple text control instead. Please "
218 "reinstall riched32.dll"));
230 msStyle
|= ES_AUTOVSCROLL
;
233 int ver
= wxRichEditModule::GetLoadedVersion();
236 windowClass
= wxT("RICHEDIT");
240 #ifndef RICHEDIT_CLASS
241 wxString RICHEDIT_CLASS
;
242 RICHEDIT_CLASS
.Printf(_T("RichEdit%d0"), ver
);
244 RICHEDIT_CLASS
+= _T('W');
246 RICHEDIT_CLASS
+= _T('A');
247 #endif // Unicode/ANSI
248 #endif // !RICHEDIT_CLASS
250 windowClass
= RICHEDIT_CLASS
;
256 #endif // wxUSE_RICHEDIT
259 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
261 // Even with extended styles, need to combine with WS_BORDER for them to
263 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
264 msStyle
|= WS_BORDER
;
266 // NB: don't use pos and size as CreateWindowEx arguments because they
267 // might be -1 in which case we should use the default values (and
268 // SetSize called below takes care of it)
269 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
,
279 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create text ctrl") );
284 Ctl3dSubclassCtl(GetHwnd());
292 // Have to enable events
293 ::SendMessage(GetHwnd(), EM_SETEVENTMASK
, 0,
294 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
298 SubclassWin(GetHWND());
300 // set font, position, size and initial value
301 wxFont
& fontParent
= parent
->GetFont();
302 if ( fontParent
.Ok() )
308 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
311 // Causes a crash for Symantec C++ and WIN32 for some reason
312 #if !(defined(__SC__) && defined(__WIN32__))
313 if ( !value
.IsEmpty() )
319 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
324 // Make sure the window style (etc.) reflects the HWND style (roughly)
325 void wxTextCtrl::AdoptAttributesFromHWND()
327 wxWindow::AdoptAttributesFromHWND();
329 HWND hWnd
= GetHwnd();
330 long style
= GetWindowLong(hWnd
, GWL_STYLE
);
332 // retrieve the style to see whether this is an edit or richedit ctrl
336 GetClassName(hWnd
, buf
, WXSIZEOF(buf
));
338 if ( wxStricmp(buf
, wxT("EDIT")) == 0 )
342 #endif // wxUSE_RICHEDIT
344 if (style
& ES_MULTILINE
)
345 m_windowStyle
|= wxTE_MULTILINE
;
346 if (style
& ES_PASSWORD
)
347 m_windowStyle
|= wxTE_PASSWORD
;
348 if (style
& ES_READONLY
)
349 m_windowStyle
|= wxTE_READONLY
;
350 if (style
& ES_WANTRETURN
)
351 m_windowStyle
|= wxTE_PROCESS_ENTER
;
354 void wxTextCtrl::SetupColours()
356 // FIXME why is bg colour not inherited from parent?
357 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
358 SetForegroundColour(GetParent()->GetForegroundColour());
361 // ----------------------------------------------------------------------------
362 // set/get the controls text
363 // ----------------------------------------------------------------------------
365 wxString
wxTextCtrl::GetValue() const
367 // we can't use wxGetWindowText() (i.e. WM_GETTEXT internally) for
368 // retrieving more than 64Kb under Win9x
374 int len
= GetWindowTextLength(GetHwnd()) + 1;
375 wxChar
*p
= str
.GetWriteBuf(len
);
378 textRange
.chrg
.cpMin
= 0;
379 textRange
.chrg
.cpMax
= -1;
380 textRange
.lpstrText
= p
;
382 (void)SendMessage(GetHwnd(), EM_GETTEXTRANGE
, 0, (LPARAM
)&textRange
);
384 // believe it or not, but EM_GETTEXTRANGE uses just CR ('\r') for the
385 // newlines which is neither Unix nor Windows style (Win95 with
386 // riched20.dll shows this behaviour) - convert it to something
390 if ( *p
== _T('\r') )
398 #endif // wxUSE_RICHEDIT
400 // WM_GETTEXT uses standard DOS CR+LF (\r\n) convention - convert to the
401 // same one as above for consitency
402 wxString str
= wxGetWindowText(GetHWND());
404 return wxTextFile::Translate(str
, wxTextFileType_Unix
);
407 void wxTextCtrl::SetValue(const wxString
& value
)
409 // if the text is long enough, it's faster to just set it instead of first
410 // comparing it with the old one (chances are that it will be different
411 // anyhow, this comparison is there to avoid flicker for small single-line
412 // edit controls mostly)
413 if ( (value
.length() > 0x400) || (value
!= GetValue()) )
415 wxString valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
417 SetWindowText(GetHwnd(), valueDos
);
423 void wxTextCtrl::WriteText(const wxString
& value
)
425 wxString valueDos
= wxTextFile::Translate(value
, wxTextFileType_Dos
);
427 SendMessage(GetHwnd(), EM_REPLACESEL
, 0, (LPARAM
)valueDos
.c_str());
432 void wxTextCtrl::AppendText(const wxString
& text
)
434 SetInsertionPointEnd();
438 void wxTextCtrl::Clear()
440 SetWindowText(GetHwnd(), wxT(""));
443 // ----------------------------------------------------------------------------
444 // Clipboard operations
445 // ----------------------------------------------------------------------------
447 void wxTextCtrl::Copy()
451 HWND hWnd
= GetHwnd();
452 SendMessage(hWnd
, WM_COPY
, 0, 0L);
456 void wxTextCtrl::Cut()
460 HWND hWnd
= GetHwnd();
461 SendMessage(hWnd
, WM_CUT
, 0, 0L);
465 void wxTextCtrl::Paste()
469 HWND hWnd
= GetHwnd();
470 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
474 bool wxTextCtrl::CanCopy() const
476 // Can copy if there's a selection
478 GetSelection(& from
, & to
);
482 bool wxTextCtrl::CanCut() const
484 // Can cut if there's a selection
486 GetSelection(& from
, & to
);
490 bool wxTextCtrl::CanPaste() const
495 int dataFormat
= 0; // 0 == any format
496 return (::SendMessage( GetHwnd(), EM_CANPASTE
, (WPARAM
) (UINT
) dataFormat
, 0) != 0);
502 // Standard edit control: check for straight text on clipboard
503 bool isTextAvailable
= FALSE
;
504 if ( ::OpenClipboard(GetHwndOf(wxTheApp
->GetTopWindow())) )
506 isTextAvailable
= (::IsClipboardFormatAvailable(CF_TEXT
) != 0);
510 return isTextAvailable
;
513 // ----------------------------------------------------------------------------
515 // ----------------------------------------------------------------------------
517 void wxTextCtrl::SetEditable(bool editable
)
519 HWND hWnd
= GetHwnd();
520 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
523 void wxTextCtrl::SetInsertionPoint(long pos
)
525 HWND hWnd
= GetHwnd();
533 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
534 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
537 #endif // wxUSE_RICHEDIT
539 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
540 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
543 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
546 static const char *nothing
= "";
547 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
550 void wxTextCtrl::SetInsertionPointEnd()
552 long pos
= GetLastPosition();
553 SetInsertionPoint(pos
);
556 long wxTextCtrl::GetInsertionPoint() const
564 SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
569 DWORD Pos
= (DWORD
)SendMessage(GetHwnd(), EM_GETSEL
, 0, 0L);
573 long wxTextCtrl::GetLastPosition() const
575 HWND hWnd
= GetHwnd();
577 // Will always return a number > 0 (according to docs)
578 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
580 // This gets the char index for the _beginning_ of the last line
581 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
583 // Get number of characters in the last line. We'll add this to the character
584 // index for the last line, 1st position.
585 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
587 return (long)(charIndex
+ lineLength
);
590 // If the return values from and to are the same, there is no
592 void wxTextCtrl::GetSelection(long* from
, long* to
) const
598 ::SendMessage(GetHwnd(), EM_EXGETSEL
, 0, (LPARAM
) (CHARRANGE
*) & charRange
);
600 *from
= charRange
.cpMin
;
601 *to
= charRange
.cpMax
;
606 DWORD dwStart
, dwEnd
;
607 WPARAM wParam
= (WPARAM
) (DWORD
*) & dwStart
; // receives starting position
608 LPARAM lParam
= (LPARAM
) (DWORD
*) & dwEnd
; // receives ending position
610 ::SendMessage(GetHwnd(), EM_GETSEL
, wParam
, lParam
);
616 bool wxTextCtrl::IsEditable() const
618 long style
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
620 return ((style
& ES_READONLY
) == 0);
623 // ----------------------------------------------------------------------------
625 // ----------------------------------------------------------------------------
627 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
630 HWND hWnd
= GetHwnd();
631 long fromChar
= from
;
634 // Set selection and remove it
636 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
638 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
640 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
642 // Now replace with 'value', by pasting.
643 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)value
, 0, 0);
645 // Paste into edit control
646 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
648 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
652 void wxTextCtrl::Remove(long from
, long to
)
654 HWND hWnd
= GetHwnd();
655 long fromChar
= from
;
658 // Cut all selected text
660 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
662 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
664 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
667 void wxTextCtrl::SetSelection(long from
, long to
)
669 HWND hWnd
= GetHwnd();
670 long fromChar
= from
;
673 // if from and to are both -1, it means (in wxWindows) that all text should
674 // be selected. Translate into Windows convention
675 if ((from
== -1) && (to
== -1))
682 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
683 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
685 // WPARAM is 0: selection is scrolled into view
686 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
690 bool wxTextCtrl::LoadFile(const wxString
& file
)
692 if ( wxTextCtrlBase::LoadFile(file
) )
694 // update the size limit if needed
703 bool wxTextCtrl::IsModified() const
705 return (SendMessage(GetHwnd(), EM_GETMODIFY
, 0, 0) != 0);
708 // Makes 'unmodified'
709 void wxTextCtrl::DiscardEdits()
711 SendMessage(GetHwnd(), EM_SETMODIFY
, FALSE
, 0L);
714 int wxTextCtrl::GetNumberOfLines() const
716 return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
719 long wxTextCtrl::XYToPosition(long x
, long y
) const
721 HWND hWnd
= GetHwnd();
723 // This gets the char index for the _beginning_ of this line
724 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
725 return (long)(x
+ charIndex
);
728 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
730 HWND hWnd
= GetHwnd();
732 // This gets the line number containing the character
737 lineNo
= (int)SendMessage(hWnd
, EM_EXLINEFROMCHAR
, 0, (LPARAM
)pos
);
740 #endif // wxUSE_RICHEDIT
741 lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, 0);
749 // This gets the char index for the _beginning_ of this line
750 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
751 if ( charIndex
== -1 )
756 // The X position must therefore be the different between pos and charIndex
758 *x
= (long)(pos
- charIndex
);
765 void wxTextCtrl::ShowPosition(long pos
)
767 HWND hWnd
= GetHwnd();
769 // To scroll to a position, we pass the number of lines and characters
770 // to scroll *by*. This means that we need to:
771 // (1) Find the line position of the current line.
772 // (2) Find the line position of pos.
773 // (3) Scroll by (pos - current).
774 // For now, ignore the horizontal scrolling.
776 // Is this where scrolling is relative to - the line containing the caret?
777 // Or is the first visible line??? Try first visible line.
778 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
780 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
782 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
784 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
786 if (linesToScroll
!= 0)
787 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)linesToScroll
);
790 int wxTextCtrl::GetLineLength(long lineNo
) const
792 long charIndex
= XYToPosition(0, lineNo
);
793 int len
= (int)SendMessage(GetHwnd(), EM_LINELENGTH
, charIndex
, 0);
797 wxString
wxTextCtrl::GetLineText(long lineNo
) const
799 size_t len
= (size_t)GetLineLength(lineNo
) + 1;
800 char *buf
= (char *)malloc(len
);
802 int noChars
= (int)SendMessage(GetHwnd(), EM_GETLINE
, lineNo
, (LPARAM
)buf
);
812 // ----------------------------------------------------------------------------
814 // ----------------------------------------------------------------------------
816 void wxTextCtrl::Undo()
820 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
824 void wxTextCtrl::Redo()
828 // Same as Undo, since Undo undoes the undo, i.e. a redo.
829 ::SendMessage(GetHwnd(), EM_UNDO
, 0, 0);
833 bool wxTextCtrl::CanUndo() const
835 return (::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0);
838 bool wxTextCtrl::CanRedo() const
840 return (::SendMessage(GetHwnd(), EM_CANUNDO
, 0, 0) != 0);
843 // ----------------------------------------------------------------------------
844 // implemenation details
845 // ----------------------------------------------------------------------------
847 void wxTextCtrl::Command(wxCommandEvent
& event
)
849 SetValue(event
.GetString());
850 ProcessCommand (event
);
853 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
855 // By default, load the first file into the text window.
856 if (event
.GetNumberOfFiles() > 0)
858 LoadFile(event
.GetFiles()[0]);
862 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
864 switch ( event
.KeyCode() )
867 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
869 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
870 event
.SetEventObject( this );
871 if ( GetEventHandler()->ProcessEvent(event
) )
874 //else: multiline controls need Enter for themselves
879 // always produce navigation event - even if we process TAB
880 // ourselves the fact that we got here means that the user code
881 // decided to skip processing of this TAB - probably to let it
882 // do its default job.
884 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
885 // handled by Windows
887 wxNavigationKeyEvent eventNav
;
888 eventNav
.SetDirection(!event
.ShiftDown());
889 eventNav
.SetWindowChange(FALSE
);
890 eventNav
.SetEventObject(this);
892 if ( GetEventHandler()->ProcessEvent(eventNav
) )
902 // don't just call event.Skip() because this will cause TABs and ENTERs
903 // be passed upwards and we don't always want this - instead 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 wxString
val(GetValue());
930 event
.m_commandString
= WXSTRINGCAST val
;
931 event
.SetEventObject( this );
932 ProcessCommand(event
);
937 // the text size limit has been hit - increase it
941 // the other notification messages are not processed
954 void wxTextCtrl::AdjustSpaceLimit()
957 unsigned int len
= ::GetWindowTextLength(GetHwnd()),
958 limit
= ::SendMessage(GetHwnd(), EM_GETLIMITTEXT
, 0, 0);
961 limit
= len
+ 0x8000; // 32Kb
966 // as a nice side effect, this also allows passing limit > 64Kb
967 ::SendMessage(GetHwnd(), EM_EXLIMITTEXT
, 0, limit
);
970 #endif // wxUSE_RICHEDIT
972 if ( limit
> 0xffff )
974 // this will set it to a platform-dependent maximum (much more
975 // than 64Kb under NT)
979 ::SendMessage(GetHwnd(), EM_LIMITTEXT
, limit
, 0);
985 bool wxTextCtrl::AcceptsFocus() const
987 // we don't want focus if we can't be edited
988 return IsEditable() && wxControl::AcceptsFocus();
991 wxSize
wxTextCtrl::DoGetBestSize() const
994 wxGetCharSize(GetHWND(), &cx
, &cy
, &GetFont());
996 int wText
= DEFAULT_ITEM_WIDTH
;
998 int hText
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
999 if ( m_windowStyle
& wxTE_MULTILINE
)
1001 hText
*= wxMin(GetNumberOfLines(), 5);
1003 //else: for single line control everything is ok
1005 return wxSize(wText
, hText
);
1008 // ----------------------------------------------------------------------------
1009 // standard handlers for standard edit menu events
1010 // ----------------------------------------------------------------------------
1012 void wxTextCtrl::OnCut(wxCommandEvent
& event
)
1017 void wxTextCtrl::OnCopy(wxCommandEvent
& event
)
1022 void wxTextCtrl::OnPaste(wxCommandEvent
& event
)
1027 void wxTextCtrl::OnUndo(wxCommandEvent
& event
)
1032 void wxTextCtrl::OnRedo(wxCommandEvent
& event
)
1037 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1039 event
.Enable( CanCut() );
1042 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1044 event
.Enable( CanCopy() );
1047 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1049 event
.Enable( CanPaste() );
1052 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1054 event
.Enable( CanUndo() );
1057 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1059 event
.Enable( CanRedo() );
1062 // ----------------------------------------------------------------------------
1064 // ----------------------------------------------------------------------------
1068 bool wxRichEditModule::OnInit()
1070 // don't do anything - we will load it when needed
1074 void wxRichEditModule::OnExit()
1078 FreeLibrary(ms_hRichEdit
);
1083 bool wxRichEditModule::Load(int version
)
1085 wxCHECK_MSG( version
>= 1 && version
<= 3, FALSE
,
1086 _T("incorrect richedit control version requested") );
1088 if ( version
<= ms_verRichEdit
)
1090 // we've already got this or better
1096 ::FreeLibrary(ms_hRichEdit
);
1099 // always try load riched20.dll first - like this we won't have to reload
1100 // it later if we're first asked for RE 1 and then for RE 2 or 3
1101 wxString dllname
= _T("riched20.dll");
1102 ms_hRichEdit
= ::LoadLibrary(dllname
);
1103 ms_verRichEdit
= 2; // no way to tell if it's 2 or 3, assume 2
1105 if ( !ms_hRichEdit
&& (version
== 1) )
1107 // fall back to RE 1
1108 dllname
= _T("riched32.dll");
1109 ms_hRichEdit
= ::LoadLibrary(dllname
);
1113 if ( !ms_hRichEdit
)
1115 wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname
.c_str());
1117 ms_verRichEdit
= -1;
1125 #endif // wxUSE_RICHEDIT