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(__TWIN32__)
70 #define wxUSE_RICHEDIT 1
72 #define wxUSE_RICHEDIT 0
75 #if wxUSE_RICHEDIT && !defined(__GNUWIN32__)
79 #if !USE_SHARED_LIBRARY
80 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
82 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
83 EVT_CHAR(wxTextCtrl::OnChar
)
84 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
85 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
91 wxTextCtrl::wxTextCtrl(void)
92 #ifndef NO_TEXT_WINDOW_STREAM
100 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
101 const wxString
& value
,
103 const wxSize
& size
, long style
,
104 const wxValidator
& validator
,
105 const wxString
& name
)
109 SetValidator(validator
);
110 if (parent
) parent
->AddChild(this);
112 m_windowStyle
= style
;
114 // Should this be taken from the system colours?
115 // SetBackgroundColour(wxColour(255, 255, 255));
117 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
119 SetForegroundColour(parent
->GetForegroundColour()) ;
122 m_windowId
= (int)NewControlId();
132 WXHGLOBAL m_globalHandle
= 0;
134 // Obscure method from the MS Developer's Network Disk for
135 // using global memory instead of the local heap, which
136 // runs out far too soon. Solves the problem with
137 // failing to appear.
139 // Doesn't seem to work for Win95, so removing.
141 // if ((wxGetOsVersion() != wxWINDOWS_NT) && (wxGetOsVersion() != wxWIN95))
142 // m_globalHandle = (WXHGLOBAL) GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
146 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
147 if (m_windowStyle
& wxTE_MULTILINE
)
148 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
150 msStyle
|= ES_AUTOHSCROLL
;
152 if (m_windowStyle
& wxTE_READONLY
)
153 msStyle
|= ES_READONLY
;
155 if (m_windowStyle
& wxHSCROLL
)
156 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
157 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
158 msStyle
|= ES_PASSWORD
;
160 char *windowClass
= "EDIT";
162 if ( m_windowStyle
& wxTE_MULTILINE
)
164 msStyle
|= ES_AUTOVSCROLL
;
166 windowClass
= "RichEdit" ;
173 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
175 // If we're in Win95, and we want a simple 2D border,
176 // then make it an EDIT control instead.
178 if (m_windowStyle
& wxSIMPLE_BORDER
)
180 windowClass
= "EDIT";
185 // Even with extended styles, need to combine with WS_BORDER
186 // for them to look right.
187 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
188 msStyle
|= WS_BORDER
;
190 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, windowClass
, NULL
,
192 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
193 m_globalHandle
? (HINSTANCE
) m_globalHandle
: wxGetInstance(), NULL
);
195 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create text ctrl" );
200 Ctl3dSubclassCtl((HWND
)m_hWnd
);
208 // Have to enable events
209 ::SendMessage((HWND
)m_hWnd
, EM_SETEVENTMASK
, 0,
210 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
214 SubclassWin(GetHWND());
216 if ( parent
->GetFont().Ok() && parent
->GetFont().Ok() )
218 SetFont(parent
->GetFont());
222 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
225 SetSize(x
, y
, width
, height
);
227 // Causes a crash for Symantec C++ and WIN32 for some reason
228 #if !(defined(__SC__) && defined(__WIN32__))
229 if ( !value
.IsEmpty() )
238 // Make sure the window style (etc.) reflects the HWND style (roughly)
239 void wxTextCtrl::AdoptAttributesFromHWND(void)
241 wxWindow::AdoptAttributesFromHWND();
243 HWND hWnd
= (HWND
) GetHWND();
244 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
249 GetClassName((HWND
) hWnd
, buf
, 256);
252 GetClassNameW((HWND
) hWnd
, buf
, 256);
255 GetClassName((HWND
) hWnd
, buf
, 256);
257 GetClassNameA((HWND
) hWnd
, buf
, 256);
270 if (style
& ES_MULTILINE
)
271 m_windowStyle
|= wxTE_MULTILINE
;
272 if (style
& ES_PASSWORD
)
273 m_windowStyle
|= wxTE_PASSWORD
;
274 if (style
& ES_READONLY
)
275 m_windowStyle
|= wxTE_READONLY
;
276 if (style
& ES_WANTRETURN
)
277 m_windowStyle
|= wxTE_PROCESS_ENTER
;
280 void wxTextCtrl::SetupColours(void)
282 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
283 SetForegroundColour(GetParent()->GetForegroundColour());
286 wxString
wxTextCtrl::GetValue(void) const
288 int length
= GetWindowTextLength((HWND
) GetHWND());
289 char *s
= new char[length
+1];
290 GetWindowText((HWND
) GetHWND(), s
, length
+1);
296 void wxTextCtrl::SetValue(const wxString
& value
)
298 // If newlines are denoted by just 10, must stick 13 in front.
300 int len
= value
.Length();
302 for (i
= 0; i
< len
; i
++)
304 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
309 char *tmp
= new char[len
+ singletons
+ 1];
311 for (i
= 0; i
< len
; i
++)
313 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
322 SetWindowText((HWND
) GetHWND(), tmp
);
326 SetWindowText((HWND
) GetHWND(), (const char *)value
);
329 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
331 int currentX
, currentY
;
332 GetPosition(¤tX
, ¤tY
);
338 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
340 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
343 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
345 int cx
; // button font dimensions
348 wxGetCharSize(GetHWND(), &cx
, &cy
, & this->GetFont());
350 int control_width
, control_height
, control_x
, control_y
;
352 // If we're prepared to use the existing size, then...
353 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
358 // Deal with default size (using -1 values)
360 w1
= DEFAULT_ITEM_WIDTH
;
367 // Calculations may have made text size too small
368 if (control_height
<= 0)
369 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
371 if (control_width
<= 0)
372 control_width
= DEFAULT_ITEM_WIDTH
;
374 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
375 (int)control_width
, (int)control_height
, TRUE
);
378 // Clipboard operations
379 void wxTextCtrl::Copy(void)
381 HWND hWnd
= (HWND
) GetHWND();
382 SendMessage(hWnd
, WM_COPY
, 0, 0L);
385 void wxTextCtrl::Cut(void)
387 HWND hWnd
= (HWND
) GetHWND();
388 SendMessage(hWnd
, WM_CUT
, 0, 0L);
391 void wxTextCtrl::Paste(void)
393 HWND hWnd
= (HWND
) GetHWND();
394 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
397 void wxTextCtrl::SetEditable(bool editable
)
399 HWND hWnd
= (HWND
) GetHWND();
400 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
403 void wxTextCtrl::SetInsertionPoint(long pos
)
405 HWND hWnd
= (HWND
) GetHWND();
413 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
414 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
419 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
420 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
423 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
426 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
429 void wxTextCtrl::SetInsertionPointEnd(void)
431 long pos
= GetLastPosition();
432 SetInsertionPoint(pos
);
435 long wxTextCtrl::GetInsertionPoint(void) const
443 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
448 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
452 long wxTextCtrl::GetLastPosition(void) const
454 HWND hWnd
= (HWND
) GetHWND();
456 // Will always return a number > 0 (according to docs)
457 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
459 // This gets the char index for the _beginning_ of the last line
460 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
462 // Get number of characters in the last line. We'll add this to the character
463 // index for the last line, 1st position.
464 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
466 return (long)(charIndex
+ lineLength
);
469 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
471 HWND hWnd
= (HWND
) GetHWND();
472 long fromChar
= from
;
475 // Set selection and remove it
477 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
479 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
481 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
483 // Now replace with 'value', by pasting.
484 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
486 // Paste into edit control
487 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
490 void wxTextCtrl::Remove(long from
, long to
)
492 HWND hWnd
= (HWND
) GetHWND();
493 long fromChar
= from
;
496 // Cut all selected text
498 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
500 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
502 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
505 void wxTextCtrl::SetSelection(long from
, long to
)
507 HWND hWnd
= (HWND
) GetHWND();
508 long fromChar
= from
;
510 // if from and to are both -1, it means
511 // (in wxWindows) that all text should be selected.
512 // This translates into Windows convention
513 if ((from
== -1) && (to
== -1))
520 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
521 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
523 // WPARAM is 0: selection is scrolled into view
524 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
528 bool wxTextCtrl::LoadFile(const wxString
& file
)
530 if (!wxFileExists(WXSTRINGCAST file
))
537 // ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
538 ifstream
input(WXSTRINGCAST file
, ios::in
);
542 // Previously a SETSEL/REPLACESEL call-pair were done to insert
543 // line by line into the control. Apart from being very slow this
544 // was limited to 32K of text by the external interface presenting
545 // positions as signed shorts. Now load in one chunk...
546 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
549 struct _stat stat_buf
;
550 if (stat((char*) (const char*) file
, &stat_buf
) < 0)
553 struct stat stat_buf
;
554 if (stat(file
, &stat_buf
) < 0)
558 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
559 // This may need to be a bigger buffer than the file size suggests,
560 // if it's a UNIX file. Give it an extra 1000 just in case.
561 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
564 while (!input
.eof() && input
.peek() != EOF
)
566 input
.getline(wxBuffer
, 500);
567 int len
= strlen(wxBuffer
);
569 wxBuffer
[len
+1] = 10;
571 strcpy(tmp_buffer
+pos
, wxBuffer
);
572 pos
+= strlen(wxBuffer
);
576 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
577 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
578 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
586 // If file is null, try saved file name first
587 // Returns TRUE if succeeds.
588 bool wxTextCtrl::SaveFile(const wxString
& file
)
590 wxString
theFile(file
);
592 theFile
= m_fileName
;
595 m_fileName
= theFile
;
597 ofstream
output((char*) (const char*) theFile
);
601 // This will only save 64K max
602 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
603 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
604 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
605 char *pstr
= tmp_buffer
;
607 // Convert \r\n to just \n
616 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
621 void wxTextCtrl::WriteText(const wxString
& text
)
624 int len
= text
.Length();
625 char *newtext
= new char[(len
*2)+1];
635 newtext
[j
] = text
[i
];
640 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
644 void wxTextCtrl::Clear(void)
646 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
647 SetWindowText((HWND
) GetHWND(), "");
650 bool wxTextCtrl::IsModified(void) const
652 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
655 // Makes 'unmodified'
656 void wxTextCtrl::DiscardEdits(void)
658 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
662 * Some of the following functions are yet to be implemented
666 int wxTextCtrl::GetNumberOfLines(void) const
668 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
671 long wxTextCtrl::XYToPosition(long x
, long y
) const
673 HWND hWnd
= (HWND
) GetHWND();
675 // This gets the char index for the _beginning_ of this line
676 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
677 return (long)(x
+ charIndex
);
680 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
682 HWND hWnd
= (HWND
) GetHWND();
684 // This gets the line number containing the character
685 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
686 // This gets the char index for the _beginning_ of this line
687 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
688 // The X position must therefore be the different between pos and charIndex
689 *x
= (long)(pos
- charIndex
);
693 void wxTextCtrl::ShowPosition(long pos
)
695 HWND hWnd
= (HWND
) GetHWND();
697 // To scroll to a position, we pass the number of lines and characters
698 // to scroll *by*. This means that we need to:
699 // (1) Find the line position of the current line.
700 // (2) Find the line position of pos.
701 // (3) Scroll by (pos - current).
702 // For now, ignore the horizontal scrolling.
704 // Is this where scrolling is relative to - the line containing the caret?
705 // Or is the first visible line??? Try first visible line.
706 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
708 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
710 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
712 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
715 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
716 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
719 if (linesToScroll
!= 0)
720 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
723 int wxTextCtrl::GetLineLength(long lineNo
) const
725 long charIndex
= XYToPosition(0, lineNo
);
726 HWND hWnd
= (HWND
) GetHWND();
727 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
731 wxString
wxTextCtrl::GetLineText(long lineNo
) const
733 HWND hWnd
= (HWND
) GetHWND();
734 *(WORD
*)wxBuffer
= 512;
735 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
736 wxBuffer
[noChars
] = 0;
737 return wxString(wxBuffer
);
744 void wxTextCtrl::Command(wxCommandEvent
& event
)
746 SetValue (event
.GetString());
747 ProcessCommand (event
);
750 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
752 // By default, load the first file into the text window.
753 if (event
.GetNumberOfFiles() > 0)
755 LoadFile(event
.GetFiles()[0]);
759 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
760 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
762 //=========================================================================
763 // Called then the buffer is full (gcc 2.6.3)
764 // or when "endl" is output (Borland 4.5)
765 //=========================================================================
766 // Class declaration using multiple inheritance doesn't work properly for
767 // Borland. See note in textctrl.h.
768 #ifndef NO_TEXT_WINDOW_STREAM
769 int wxTextCtrl::overflow(int c
)
771 // Make sure there is a holding area
772 // this is not needed in <iostream> usage as it automagically allocates
773 // it, but does someone want to emulate it for safety's sake?
775 if ( allocate()==EOF
)
777 wxLogError("Streambuf allocation failed");
782 // Verify that there are no characters in get area
783 if ( gptr() && gptr() < egptr() )
785 wxError("Who's trespassing my get area?","Internal error");
792 // Make sure there is a put area
795 /* This doesn't seem to be fatal so comment out error message */
796 // wxError("Put area not opened","Internal error");
799 setp( base(), base() );
801 setp( pbase(), pbase() );
805 // Determine how many characters have been inserted but no consumed
806 int plen
= pptr() - pbase();
808 // Now Jerry relies on the fact that the buffer is at least 2 chars
809 // long, but the holding area "may be as small as 1" ???
810 // And we need an additional \0, so let's keep this inefficient but
813 // If c!=EOF, it is a character that must also be comsumed
814 int xtra
= c
==EOF
? 0 : 1;
816 // Write temporary C-string to wxTextWindow
818 char *txt
= new char[plen
+xtra
+1];
819 memcpy(txt
, pbase(), plen
);
820 txt
[plen
] = (char)c
; // append c
821 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
822 // If the put area already contained \0, output will be truncated there
828 setp(pbase(), epptr());
830 #if defined(__WATCOMC__)
832 #elif defined(zapeof) // HP-UX (all cfront based?)
835 return c
!=EOF
? c
: 0; // this should make everybody happy
839 int len = pptr() - pbase();
840 char *txt = new char[len+1];
841 strncpy(txt, pbase(), len);
844 setp(pbase(), epptr());
850 //=========================================================================
851 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
852 //=========================================================================
853 int wxTextCtrl::sync(void)
855 // Verify that there are no characters in get area
856 if ( gptr() && gptr() < egptr() )
858 wxError("Who's trespassing my get area?","Internal error");
862 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
866 int len = pptr() - pbase();
867 char *txt = new char[len+1];
868 strncpy(txt, pbase(), len);
871 setp(pbase(), epptr());
877 //=========================================================================
878 // Should not be called by a "ostream". Used by a "istream"
879 //=========================================================================
880 int wxTextCtrl::underflow(void)
886 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
892 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
895 str
.Printf("%.2f", f
);
900 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
903 str
.Printf("%.2f", d
);
908 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
916 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
919 str
.Printf("%ld", i
);
924 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
934 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
935 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
940 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
941 return (WXHBRUSH
) hbrush
;
945 if (GetParent()->GetTransparentBackground())
946 SetBkMode((HDC
) pDC
, TRANSPARENT
);
948 SetBkMode((HDC
) pDC
, OPAQUE
);
950 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
951 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
953 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
955 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
956 // has a zero usage count.
957 // NOT NOW - will be cleaned up at end of app.
958 // backgroundBrush->RealizeResource();
959 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
962 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
964 // Fix by Marcel Rasche to allow Alt-Ctrl insertion of special characters
965 switch(event
.KeyCode())
975 char c
=(char)event
.KeyCode();
980 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
982 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
983 event
.SetEventObject( this );
984 if ( GetEventHandler()->ProcessEvent(event
) )
987 else if ( event
.KeyCode() == WXK_TAB
) {
988 wxNavigationKeyEvent event
;
989 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
990 event
.SetWindowChange(FALSE
);
991 event
.SetEventObject(this);
993 if ( GetEventHandler()->ProcessEvent(event
) )
1000 long wxTextCtrl::MSWGetDlgCode()
1002 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
1003 if ( m_windowStyle
& wxTE_PROCESS_ENTER
)
1004 lRc
|= DLGC_WANTMESSAGE
;
1005 else if ( m_windowStyle
& wxTE_MULTILINE
)
1006 lRc
|= DLGC_WANTMESSAGE
;
1008 if ( m_windowStyle
& wxTE_PROCESS_TAB
)
1009 lRc
|= DLGC_WANTTAB
;
1014 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
1016 if ( m_windowStyle
& wxTE_MULTILINE
)
1018 // No flicker - only problem is we probably can't change the background
1022 ::GetClientRect((HWND) GetHWND(), &rect);
1024 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1025 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1027 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1028 ::DeleteObject(hBrush);
1029 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1032 // wxWindow::OnEraseBackground(event);
1035 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1039 wxDebugMsg("Edit control %d: ", (int)id);
1043 wxDebugMsg("EN_SETFOCUS\n");
1046 wxDebugMsg("EN_KILLFOCUS\n");
1049 wxDebugMsg("EN_CHANGE\n");
1052 wxDebugMsg("EN_UPDATE\n");
1055 wxDebugMsg("EN_ERRSPACE\n");
1058 wxDebugMsg("EN_MAXTEXT\n");
1061 wxDebugMsg("EN_HSCROLL\n");
1064 wxDebugMsg("EN_VSCROLL\n");
1067 wxDebugMsg("Unknown EDIT notification\n");
1076 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1079 event
.SetEventObject( this );
1080 GetEventHandler()->ProcessEvent(event
);
1086 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1087 wxString
val(GetValue());
1088 if ( !val
.IsNull() )
1089 event
.m_commandString
= WXSTRINGCAST val
;
1090 event
.SetEventObject( this );
1091 ProcessCommand(event
);
1095 // the other notification messages are not processed
1110 // For Rich Edit controls. Do we need it?
1113 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1115 wxCommandEvent
event(0, m_windowId
);
1117 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1118 switch ( hdr1
->code
)
1120 // Insert case code here
1122 return wxControl::MSWNotify(wParam
, lParam
);
1126 event
.SetEventObject( this );
1127 event
.SetEventType(eventType
);
1129 if ( !GetEventHandler()->ProcessEvent(event
) )