1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textctrl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/textctrl.h"
25 #include "wx/settings.h"
33 #include "wx/clipbrd.h"
36 #include "wx/msw/private.h"
50 #include <sys/types.h>
56 #if defined(__BORLANDC__) && !defined(__WIN32__)
59 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
62 #define farmalloc malloc
69 #if defined(__WIN95__) && !defined(__GNUWIN32__)
73 #if !USE_SHARED_LIBRARY
74 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
76 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
77 EVT_CHAR(wxTextCtrl::OnChar
)
78 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
79 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
85 wxTextCtrl::wxTextCtrl(void)
86 #ifndef NO_TEXT_WINDOW_STREAM
94 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
95 const wxString
& value
,
97 const wxSize
& size
, long style
,
98 const wxValidator
& validator
,
103 SetValidator(validator
);
104 if (parent
) parent
->AddChild(this);
106 m_windowStyle
= style
;
108 // Should this be taken from the system colours?
109 // SetBackgroundColour(wxColour(255, 255, 255));
111 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
113 SetForegroundColour(parent
->GetForegroundColour()) ;
116 m_windowId
= (int)NewControlId();
126 WXHGLOBAL m_globalHandle
= 0;
128 // Obscure method from the MS Developer's Network Disk for
129 // using global memory instead of the local heap, which
130 // runs out far too soon. Solves the problem with
131 // failing to appear.
133 // Doesn't seem to work for Win95, so removing.
135 // if ((wxGetOsVersion() != wxWINDOWS_NT) && (wxGetOsVersion() != wxWIN95))
136 // m_globalHandle = (WXHGLOBAL) GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
140 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
141 if (m_windowStyle
& wxTE_MULTILINE
)
142 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
144 msStyle
|= ES_AUTOHSCROLL
;
146 if (m_windowStyle
& wxTE_READONLY
)
147 msStyle
|= ES_READONLY
;
149 if (m_windowStyle
& wxHSCROLL
)
150 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
151 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
152 msStyle
|= ES_PASSWORD
;
154 char *windowClass
= "EDIT";
155 #if defined(__WIN95__)
156 if ( m_windowStyle
& wxTE_MULTILINE
)
158 msStyle
|= ES_AUTOVSCROLL
;
160 windowClass
= "RichEdit" ;
167 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
169 // If we're in Win95, and we want a simple 2D border,
170 // then make it an EDIT control instead.
171 #if defined(__WIN95__)
172 if (m_windowStyle
& wxSIMPLE_BORDER
)
174 windowClass
= "EDIT";
179 // Even with extended styles, need to combine with WS_BORDER
180 // for them to look right.
181 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
182 msStyle
|= WS_BORDER
;
184 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, windowClass
, NULL
,
186 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
187 m_globalHandle
? (HINSTANCE
) m_globalHandle
: wxGetInstance(), NULL
);
189 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create text ctrl" );
194 Ctl3dSubclassCtl((HWND
)m_hWnd
);
199 #if defined(__WIN95__)
202 // Have to enable events
203 ::SendMessage((HWND
)m_hWnd
, EM_SETEVENTMASK
, 0,
204 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
208 SubclassWin(GetHWND());
210 if ( parent
->GetFont().Ok() && parent
->GetFont().Ok() )
212 SetFont(parent
->GetFont());
216 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
219 SetSize(x
, y
, width
, height
);
221 // Causes a crash for Symantec C++ and WIN32 for some reason
222 #if !(defined(__SC__) && defined(__WIN32__))
223 if ( !value
.IsEmpty() )
232 // Make sure the window style (etc.) reflects the HWND style (roughly)
233 void wxTextCtrl::AdoptAttributesFromHWND(void)
235 wxWindow::AdoptAttributesFromHWND();
237 HWND hWnd
= (HWND
) GetHWND();
238 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
243 GetClassName((HWND
) hWnd
, buf
, 256);
246 GetClassNameW((HWND
) hWnd
, buf
, 256);
248 GetClassNameA((HWND
) hWnd
, buf
, 256);
260 if (style
& ES_MULTILINE
)
261 m_windowStyle
|= wxTE_MULTILINE
;
262 if (style
& ES_PASSWORD
)
263 m_windowStyle
|= wxTE_PASSWORD
;
264 if (style
& ES_READONLY
)
265 m_windowStyle
|= wxTE_READONLY
;
266 if (style
& ES_WANTRETURN
)
267 m_windowStyle
|= wxTE_PROCESS_ENTER
;
270 void wxTextCtrl::SetupColours(void)
272 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
273 SetForegroundColour(GetParent()->GetForegroundColour());
276 wxString
wxTextCtrl::GetValue(void) const
278 int length
= GetWindowTextLength((HWND
) GetHWND());
279 char *s
= new char[length
+1];
280 GetWindowText((HWND
) GetHWND(), s
, length
+1);
286 void wxTextCtrl::SetValue(const wxString
& value
)
288 // If newlines are denoted by just 10, must stick 13 in front.
290 int len
= value
.Length();
292 for (i
= 0; i
< len
; i
++)
294 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
299 char *tmp
= new char[len
+ singletons
+ 1];
301 for (i
= 0; i
< len
; i
++)
303 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
312 SetWindowText((HWND
) GetHWND(), tmp
);
316 SetWindowText((HWND
) GetHWND(), (const char *)value
);
319 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
321 int currentX
, currentY
;
322 GetPosition(¤tX
, ¤tY
);
328 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
330 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
333 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
335 int cx
; // button font dimensions
338 wxGetCharSize(GetHWND(), &cx
, &cy
, & this->GetFont());
340 int control_width
, control_height
, control_x
, control_y
;
342 // If we're prepared to use the existing size, then...
343 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
348 // Deal with default size (using -1 values)
350 w1
= DEFAULT_ITEM_WIDTH
;
357 // Calculations may have made text size too small
358 if (control_height
<= 0)
359 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
361 if (control_width
<= 0)
362 control_width
= DEFAULT_ITEM_WIDTH
;
364 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
365 (int)control_width
, (int)control_height
, TRUE
);
368 // Clipboard operations
369 void wxTextCtrl::Copy(void)
371 HWND hWnd
= (HWND
) GetHWND();
372 SendMessage(hWnd
, WM_COPY
, 0, 0L);
375 void wxTextCtrl::Cut(void)
377 HWND hWnd
= (HWND
) GetHWND();
378 SendMessage(hWnd
, WM_CUT
, 0, 0L);
381 void wxTextCtrl::Paste(void)
383 HWND hWnd
= (HWND
) GetHWND();
384 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
387 void wxTextCtrl::SetEditable(bool editable
)
389 HWND hWnd
= (HWND
) GetHWND();
390 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
393 void wxTextCtrl::SetInsertionPoint(long pos
)
395 HWND hWnd
= (HWND
) GetHWND();
397 #if defined(__WIN95__)
403 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
404 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
409 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
410 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
413 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
416 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
419 void wxTextCtrl::SetInsertionPointEnd(void)
421 long pos
= GetLastPosition();
422 SetInsertionPoint(pos
);
425 long wxTextCtrl::GetInsertionPoint(void) const
427 #if defined(__WIN95__)
433 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
438 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
442 long wxTextCtrl::GetLastPosition(void) const
444 HWND hWnd
= (HWND
) GetHWND();
446 // Will always return a number > 0 (according to docs)
447 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
449 // This gets the char index for the _beginning_ of the last line
450 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
452 // Get number of characters in the last line. We'll add this to the character
453 // index for the last line, 1st position.
454 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
456 return (long)(charIndex
+ lineLength
);
459 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
461 HWND hWnd
= (HWND
) GetHWND();
462 long fromChar
= from
;
465 // Set selection and remove it
467 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
469 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
471 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
473 // Now replace with 'value', by pasting.
474 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
476 // Paste into edit control
477 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
480 void wxTextCtrl::Remove(long from
, long to
)
482 HWND hWnd
= (HWND
) GetHWND();
483 long fromChar
= from
;
486 // Cut all selected text
488 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
490 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
492 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
495 void wxTextCtrl::SetSelection(long from
, long to
)
497 HWND hWnd
= (HWND
) GetHWND();
498 long fromChar
= from
;
500 // if from and to are both -1, it means
501 // (in wxWindows) that all text should be selected.
502 // This translates into Windows convention
503 if ((from
== -1) && (to
== -1))
510 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
511 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
513 // WPARAM is 0: selection is scrolled into view
514 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
518 bool wxTextCtrl::LoadFile(const wxString
& file
)
520 if (!wxFileExists(WXSTRINGCAST file
))
527 // ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
528 ifstream
input(WXSTRINGCAST file
, ios::in
);
532 // Previously a SETSEL/REPLACESEL call-pair were done to insert
533 // line by line into the control. Apart from being very slow this
534 // was limited to 32K of text by the external interface presenting
535 // positions as signed shorts. Now load in one chunk...
536 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
539 struct _stat stat_buf
;
540 if (stat((char*) (const char*) file
, &stat_buf
) < 0)
543 struct stat stat_buf
;
544 if (stat(file
, &stat_buf
) < 0)
548 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
549 // This may need to be a bigger buffer than the file size suggests,
550 // if it's a UNIX file. Give it an extra 1000 just in case.
551 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
554 while (!input
.eof() && input
.peek() != EOF
)
556 input
.getline(wxBuffer
, 500);
557 int len
= strlen(wxBuffer
);
559 wxBuffer
[len
+1] = 10;
561 strcpy(tmp_buffer
+pos
, wxBuffer
);
562 pos
+= strlen(wxBuffer
);
566 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
567 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
568 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
576 // If file is null, try saved file name first
577 // Returns TRUE if succeeds.
578 bool wxTextCtrl::SaveFile(const wxString
& file
)
580 wxString
theFile(file
);
582 theFile
= m_fileName
;
585 m_fileName
= theFile
;
587 ofstream
output((char*) (const char*) theFile
);
591 // This will only save 64K max
592 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
593 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
594 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
595 char *pstr
= tmp_buffer
;
597 // Convert \r\n to just \n
606 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
611 void wxTextCtrl::WriteText(const wxString
& text
)
614 int len
= text
.Length();
615 char *newtext
= new char[(len
*2)+1];
625 newtext
[j
] = text
[i
];
630 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
634 void wxTextCtrl::Clear(void)
636 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
637 SetWindowText((HWND
) GetHWND(), "");
640 bool wxTextCtrl::IsModified(void) const
642 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
645 // Makes 'unmodified'
646 void wxTextCtrl::DiscardEdits(void)
648 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
652 * Some of the following functions are yet to be implemented
656 int wxTextCtrl::GetNumberOfLines(void) const
658 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
661 long wxTextCtrl::XYToPosition(long x
, long y
) const
663 HWND hWnd
= (HWND
) GetHWND();
665 // This gets the char index for the _beginning_ of this line
666 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
667 return (long)(x
+ charIndex
);
670 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
672 HWND hWnd
= (HWND
) GetHWND();
674 // This gets the line number containing the character
675 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
676 // This gets the char index for the _beginning_ of this line
677 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
678 // The X position must therefore be the different between pos and charIndex
679 *x
= (long)(pos
- charIndex
);
683 void wxTextCtrl::ShowPosition(long pos
)
685 HWND hWnd
= (HWND
) GetHWND();
687 // To scroll to a position, we pass the number of lines and characters
688 // to scroll *by*. This means that we need to:
689 // (1) Find the line position of the current line.
690 // (2) Find the line position of pos.
691 // (3) Scroll by (pos - current).
692 // For now, ignore the horizontal scrolling.
694 // Is this where scrolling is relative to - the line containing the caret?
695 // Or is the first visible line??? Try first visible line.
696 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
698 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
700 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
702 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
705 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
706 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
709 if (linesToScroll
!= 0)
710 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
713 int wxTextCtrl::GetLineLength(long lineNo
) const
715 long charIndex
= XYToPosition(0, lineNo
);
716 HWND hWnd
= (HWND
) GetHWND();
717 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
721 wxString
wxTextCtrl::GetLineText(long lineNo
) const
723 HWND hWnd
= (HWND
) GetHWND();
724 *(WORD
*)wxBuffer
= 512;
725 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
726 wxBuffer
[noChars
] = 0;
727 return wxString(wxBuffer
);
734 void wxTextCtrl::Command(wxCommandEvent
& event
)
736 SetValue (event
.GetString());
737 ProcessCommand (event
);
740 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
742 // By default, load the first file into the text window.
743 if (event
.GetNumberOfFiles() > 0)
745 LoadFile(event
.GetFiles()[0]);
749 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
750 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
752 //=========================================================================
753 // Called then the buffer is full (gcc 2.6.3)
754 // or when "endl" is output (Borland 4.5)
755 //=========================================================================
756 // Class declaration using multiple inheritance doesn't work properly for
757 // Borland. See note in textctrl.h.
758 #ifndef NO_TEXT_WINDOW_STREAM
759 int wxTextCtrl::overflow(int c
)
761 // Make sure there is a holding area
762 // this is not needed in <iostream> usage as it automagically allocates
763 // it, but does someone want to emulate it for safety's sake?
765 if ( allocate()==EOF
)
767 wxLogError("Streambuf allocation failed");
772 // Verify that there are no characters in get area
773 if ( gptr() && gptr() < egptr() )
775 wxError("Who's trespassing my get area?","Internal error");
782 // Make sure there is a put area
785 /* This doesn't seem to be fatal so comment out error message */
786 // wxError("Put area not opened","Internal error");
789 setp( base(), base() );
791 setp( pbase(), pbase() );
795 // Determine how many characters have been inserted but no consumed
796 int plen
= pptr() - pbase();
798 // Now Jerry relies on the fact that the buffer is at least 2 chars
799 // long, but the holding area "may be as small as 1" ???
800 // And we need an additional \0, so let's keep this inefficient but
803 // If c!=EOF, it is a character that must also be comsumed
804 int xtra
= c
==EOF
? 0 : 1;
806 // Write temporary C-string to wxTextWindow
808 char *txt
= new char[plen
+xtra
+1];
809 memcpy(txt
, pbase(), plen
);
810 txt
[plen
] = (char)c
; // append c
811 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
812 // If the put area already contained \0, output will be truncated there
818 setp(pbase(), epptr());
820 #if defined(__WATCOMC__)
822 #elif defined(zapeof) // HP-UX (all cfront based?)
825 return c
!=EOF
? c
: 0; // this should make everybody happy
829 int len = pptr() - pbase();
830 char *txt = new char[len+1];
831 strncpy(txt, pbase(), len);
834 setp(pbase(), epptr());
840 //=========================================================================
841 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
842 //=========================================================================
843 int wxTextCtrl::sync(void)
845 // Verify that there are no characters in get area
846 if ( gptr() && gptr() < egptr() )
848 wxError("Who's trespassing my get area?","Internal error");
852 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
856 int len = pptr() - pbase();
857 char *txt = new char[len+1];
858 strncpy(txt, pbase(), len);
861 setp(pbase(), epptr());
867 //=========================================================================
868 // Should not be called by a "ostream". Used by a "istream"
869 //=========================================================================
870 int wxTextCtrl::underflow(void)
876 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
882 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
885 str
.Printf("%.2f", f
);
890 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
893 str
.Printf("%.2f", d
);
898 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
906 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
909 str
.Printf("%ld", i
);
914 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
924 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
925 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
930 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
931 return (WXHBRUSH
) hbrush
;
935 if (GetParent()->GetTransparentBackground())
936 SetBkMode((HDC
) pDC
, TRANSPARENT
);
938 SetBkMode((HDC
) pDC
, OPAQUE
);
940 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
941 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
943 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
945 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
946 // has a zero usage count.
947 // NOT NOW - will be cleaned up at end of app.
948 // backgroundBrush->RealizeResource();
949 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
952 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
954 // Fix by Marcel Rasche to allow Alt-Ctrl insertion of special characters
955 switch(event
.KeyCode())
965 char c
=(char)event
.KeyCode();
970 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
972 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
973 event
.SetEventObject( this );
974 if ( GetEventHandler()->ProcessEvent(event
) )
977 else if ( event
.KeyCode() == WXK_TAB
) {
978 wxNavigationKeyEvent event
;
979 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
980 event
.SetWindowChange(FALSE
);
981 event
.SetEventObject(this);
983 if ( GetEventHandler()->ProcessEvent(event
) )
990 long wxTextCtrl::MSWGetDlgCode()
992 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
993 if ( m_windowStyle
& wxTE_PROCESS_ENTER
)
994 lRc
|= DLGC_WANTMESSAGE
;
995 else if ( m_windowStyle
& wxTE_MULTILINE
)
996 lRc
|= DLGC_WANTMESSAGE
;
998 if ( m_windowStyle
& wxTE_PROCESS_TAB
)
1004 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
1006 if ( m_windowStyle
& wxTE_MULTILINE
)
1008 // No flicker - only problem is we probably can't change the background
1012 ::GetClientRect((HWND) GetHWND(), &rect);
1014 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1015 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1017 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1018 ::DeleteObject(hBrush);
1019 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1022 // wxWindow::OnEraseBackground(event);
1025 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1029 wxDebugMsg("Edit control %d: ", (int)id);
1033 wxDebugMsg("EN_SETFOCUS\n");
1036 wxDebugMsg("EN_KILLFOCUS\n");
1039 wxDebugMsg("EN_CHANGE\n");
1042 wxDebugMsg("EN_UPDATE\n");
1045 wxDebugMsg("EN_ERRSPACE\n");
1048 wxDebugMsg("EN_MAXTEXT\n");
1051 wxDebugMsg("EN_HSCROLL\n");
1054 wxDebugMsg("EN_VSCROLL\n");
1057 wxDebugMsg("Unknown EDIT notification\n");
1066 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1069 event
.SetEventObject( this );
1070 GetEventHandler()->ProcessEvent(event
);
1076 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1077 wxString
val(GetValue());
1078 if ( !val
.IsNull() )
1079 event
.m_commandString
= WXSTRINGCAST val
;
1080 event
.SetEventObject( this );
1081 ProcessCommand(event
);
1085 // the other notification messages are not processed
1100 // For Rich Edit controls. Do we need it?
1102 #if defined(__WIN95__)
1103 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1105 wxCommandEvent
event(0, m_windowId
);
1107 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1108 switch ( hdr1
->code
)
1110 // Insert case code here
1112 return wxControl::MSWNotify(wParam
, lParam
);
1116 event
.SetEventObject( this );
1117 event
.SetEventType(eventType
);
1119 if ( !GetEventHandler()->ProcessEvent(event
) )