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"
30 #include "wx/clipbrd.h"
33 #include "wx/msw/private.h"
39 #include <sys/types.h>
41 #if defined(__BORLANDC__) && !defined(__WIN32__)
47 #define farmalloc malloc
54 #if defined(__WIN95__) && !defined(__GNUWIN32__)
58 #if !USE_SHARED_LIBRARY
59 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
61 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
62 EVT_CHAR(wxTextCtrl::OnChar
)
63 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
64 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
70 wxTextCtrl::wxTextCtrl(void)
71 #ifndef NO_TEXT_WINDOW_STREAM
79 bool wxTextCtrl::Create(wxWindow
*parent
, const wxWindowID id
,
80 const wxString
& value
,
82 const wxSize
& size
, const long style
,
83 const wxValidator
& validator
,
88 SetValidator(validator
);
89 if (parent
) parent
->AddChild(this);
91 m_windowStyle
= style
;
93 // Should this be taken from the system colours?
94 // SetBackgroundColour(wxColour(255, 255, 255));
96 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
98 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
101 m_windowId
= (int)NewControlId();
111 WXHGLOBAL m_globalHandle
= 0;
113 // Obscure method from the MS Developer's Network Disk for
114 // using global memory instead of the local heap, which
115 // runs out far too soon. Solves the problem with
116 // failing to appear.
118 // Doesn't seem to work for Win95, so removing.
120 // if ((wxGetOsVersion() != wxWINDOWS_NT) && (wxGetOsVersion() != wxWIN95))
121 // m_globalHandle = (WXHGLOBAL) GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
124 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
125 if (m_windowStyle
& wxTE_MULTILINE
)
126 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
128 msStyle
|= ES_AUTOHSCROLL
;
130 if (m_windowStyle
& wxTE_READONLY
)
131 msStyle
|= ES_READONLY
;
133 if (m_windowStyle
& wxHSCROLL
)
134 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
135 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
136 msStyle
|= ES_PASSWORD
;
138 char *windowClass
= "EDIT";
139 #if defined(__WIN95__)
140 if ( m_windowStyle
& wxTE_MULTILINE
)
145 msStyle
|= ES_AUTOVSCROLL
;
147 windowClass
= "RichEdit" ;
153 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
155 // If we're in Win95, and we want a simple 2D border,
156 // then make it an EDIT control instead.
157 #if defined(__WIN95__)
158 if (m_windowStyle
& wxSIMPLE_BORDER
)
160 windowClass
= "EDIT";
165 // Even with extended styles, need to combine with WS_BORDER
166 // for them to look right.
167 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
168 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
169 msStyle
|= WS_BORDER
;
171 HWND edit
= CreateWindowEx(exStyle
, windowClass
, NULL
,
173 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
174 m_globalHandle
? (HANDLE
) m_globalHandle
: wxGetInstance(), NULL
);
179 Ctl3dSubclassCtl(edit
);
184 m_hWnd
= (WXHWND
)edit
;
186 #if defined(__WIN95__)
189 // Have to enable events
190 ::SendMessage(edit
, EM_SETEVENTMASK
, 0, ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
194 SubclassWin(GetHWND());
196 if ( parent
->GetFont() && parent
->GetFont()->Ok() )
198 SetFont(* parent
->GetFont());
202 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
205 SetSize(x
, y
, width
, height
);
207 // Causes a crash for Symantec C++ and WIN32 for some reason
208 #if !(defined(__SC__) && defined(__WIN32__))
210 SetWindowText(edit
, (const char *)value
);
216 // Make sure the window style (etc.) reflects the HWND style (roughly)
217 void wxTextCtrl::AdoptAttributesFromHWND(void)
219 wxWindow::AdoptAttributesFromHWND();
221 HWND hWnd
= (HWND
) GetHWND();
222 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
227 GetClassName((HWND
) hWnd
, buf
, 256);
230 GetClassNameW((HWND
) hWnd
, buf
, 256);
232 GetClassNameA((HWND
) hWnd
, buf
, 256);
244 if (style
& ES_MULTILINE
)
245 m_windowStyle
|= wxTE_MULTILINE
;
246 if (style
& ES_PASSWORD
)
247 m_windowStyle
|= wxTE_PASSWORD
;
248 if (style
& ES_READONLY
)
249 m_windowStyle
|= wxTE_READONLY
;
250 if (style
& ES_WANTRETURN
)
251 m_windowStyle
|= wxTE_PROCESS_ENTER
;
254 void wxTextCtrl::SetupColours(void)
256 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
257 SetForegroundColour(GetParent()->GetDefaultForegroundColour());
260 wxString
wxTextCtrl::GetValue(void) const
262 int length
= GetWindowTextLength((HWND
) GetHWND());
263 char *s
= new char[length
+1];
264 GetWindowText((HWND
) GetHWND(), s
, length
+1);
270 void wxTextCtrl::SetValue(const wxString
& value
)
272 // If newlines are denoted by just 10, must stick 13 in front.
274 int len
= value
.Length();
276 for (i
= 0; i
< len
; i
++)
278 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
283 char *tmp
= new char[len
+ singletons
+ 1];
285 for (i
= 0; i
< len
; i
++)
287 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
296 SetWindowText((HWND
) GetHWND(), tmp
);
300 SetWindowText((HWND
) GetHWND(), (const char *)value
);
303 void wxTextCtrl::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
305 int currentX
, currentY
;
306 GetPosition(¤tX
, ¤tY
);
312 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
314 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
317 int cx
; // button font dimensions
320 wxGetCharSize(GetHWND(), &cx
, &cy
,GetFont());
322 float control_width
, control_height
, control_x
, control_y
;
324 // If we're prepared to use the existing size, then...
325 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
330 // Deal with default size (using -1 values)
332 w1
= DEFAULT_ITEM_WIDTH
;
334 control_x
= (float)x1
;
335 control_y
= (float)y1
;
336 control_width
= (float)w1
;
337 control_height
= (float)h1
;
339 // Calculations may have made text size too small
340 if (control_height
<= 0)
341 control_height
= (float)(int)(cy
*EDIT_CONTROL_FACTOR
) ;
343 if (control_width
<= 0)
344 control_width
= (float)DEFAULT_ITEM_WIDTH
;
346 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
347 (int)control_width
, (int)control_height
, TRUE
);
349 #if WXWIN_COMPATIBILITY
350 GetEventHandler()->OldOnSize(width, height);
352 wxSizeEvent event(wxSize(width, height), m_windowId);
353 event.eventObject = this;
354 GetEventHandler()->ProcessEvent(event);
359 // Clipboard operations
360 void wxTextCtrl::Copy(void)
362 HWND hWnd
= (HWND
) GetHWND();
363 SendMessage(hWnd
, WM_COPY
, 0, 0L);
366 void wxTextCtrl::Cut(void)
368 HWND hWnd
= (HWND
) GetHWND();
369 SendMessage(hWnd
, WM_CUT
, 0, 0L);
372 void wxTextCtrl::Paste(void)
374 HWND hWnd
= (HWND
) GetHWND();
375 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
378 void wxTextCtrl::SetEditable(const bool editable
)
380 HWND hWnd
= (HWND
) GetHWND();
381 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
384 void wxTextCtrl::SetInsertionPoint(const long pos
)
386 HWND hWnd
= (HWND
) GetHWND();
388 #if defined(__WIN95__)
394 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
395 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
400 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
401 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
404 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
407 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
410 void wxTextCtrl::SetInsertionPointEnd(void)
412 long pos
= GetLastPosition();
413 SetInsertionPoint(pos
);
416 long wxTextCtrl::GetInsertionPoint(void) const
418 #if defined(__WIN95__)
424 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
429 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
433 long wxTextCtrl::GetLastPosition(void) const
435 HWND hWnd
= (HWND
) GetHWND();
437 // Will always return a number > 0 (according to docs)
438 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
440 // This gets the char index for the _beginning_ of the last line
441 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
443 // Get number of characters in the last line. We'll add this to the character
444 // index for the last line, 1st position.
445 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
447 return (long)(charIndex
+ lineLength
);
450 void wxTextCtrl::Replace(const long from
, const long to
, const wxString
& value
)
452 HWND hWnd
= (HWND
) GetHWND();
453 long fromChar
= from
;
456 // Set selection and remove it
458 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
460 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
462 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
464 // Now replace with 'value', by pasting.
465 wxSetClipboardData(wxCF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
467 // Paste into edit control
468 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
471 void wxTextCtrl::Remove(const long from
, const long to
)
473 HWND hWnd
= (HWND
) GetHWND();
474 long fromChar
= from
;
477 // Cut all selected text
479 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
481 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
483 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
486 void wxTextCtrl::SetSelection(const long from
, const long to
)
488 HWND hWnd
= (HWND
) GetHWND();
489 long fromChar
= from
;
491 // if from and to are both -1, it means
492 // (in wxWindows) that all text should be selected.
493 // This translates into Windows convention
494 if ((from
== -1) && (to
== -1))
501 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
502 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
504 // WPARAM is 0: selection is scrolled into view
505 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
509 bool wxTextCtrl::LoadFile(const wxString
& file
)
511 if (!FileExists(WXSTRINGCAST file
))
518 ifstream
input(WXSTRINGCAST file
, ios::nocreate
| ios::in
);
522 // Previously a SETSEL/REPLACESEL call-pair were done to insert
523 // line by line into the control. Apart from being very slow this
524 // was limited to 32K of text by the external interface presenting
525 // positions as signed shorts. Now load in one chunk...
526 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
528 struct stat stat_buf
;
529 if (stat(file
, &stat_buf
) < 0)
531 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
532 // This may need to be a bigger buffer than the file size suggests,
533 // if it's a UNIX file. Give it an extra 1000 just in case.
534 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
537 while (!input
.eof() && input
.peek() != EOF
)
539 input
.getline(wxBuffer
, 500);
540 int len
= strlen(wxBuffer
);
542 wxBuffer
[len
+1] = 10;
544 strcpy(tmp_buffer
+pos
, wxBuffer
);
545 pos
+= strlen(wxBuffer
);
549 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
550 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
551 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
559 // If file is null, try saved file name first
560 // Returns TRUE if succeeds.
561 bool wxTextCtrl::SaveFile(const wxString
& file
)
570 ofstream
output(WXSTRINGCAST file
);
574 // This will only save 64K max
575 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
576 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
577 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
578 char *pstr
= tmp_buffer
;
580 // Convert \r\n to just \n
589 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
594 void wxTextCtrl::WriteText(const wxString
& text
)
597 int len
= text
.Length();
598 char *newtext
= new char[(len
*2)+1];
608 newtext
[j
] = text
[i
];
613 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
617 void wxTextCtrl::Clear(void)
619 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
620 SetWindowText((HWND
) GetHWND(), "");
623 bool wxTextCtrl::IsModified(void) const
625 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
628 // Makes 'unmodified'
629 void wxTextCtrl::DiscardEdits(void)
631 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
635 * Some of the following functions are yet to be implemented
639 int wxTextCtrl::GetNumberOfLines(void) const
641 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
644 long wxTextCtrl::XYToPosition(const long x
, const long y
) const
646 HWND hWnd
= (HWND
) GetHWND();
648 // This gets the char index for the _beginning_ of this line
649 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
650 return (long)(x
+ charIndex
);
653 void wxTextCtrl::PositionToXY(const long pos
, long *x
, long *y
) const
655 HWND hWnd
= (HWND
) GetHWND();
657 // This gets the line number containing the character
658 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
659 // This gets the char index for the _beginning_ of this line
660 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
661 // The X position must therefore be the different between pos and charIndex
662 *x
= (long)(pos
- charIndex
);
666 void wxTextCtrl::ShowPosition(const long pos
)
668 HWND hWnd
= (HWND
) GetHWND();
670 // To scroll to a position, we pass the number of lines and characters
671 // to scroll *by*. This means that we need to:
672 // (1) Find the line position of the current line.
673 // (2) Find the line position of pos.
674 // (3) Scroll by (pos - current).
675 // For now, ignore the horizontal scrolling.
677 // Is this where scrolling is relative to - the line containing the caret?
678 // Or is the first visible line??? Try first visible line.
679 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
681 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
683 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
685 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
688 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
689 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
692 if (linesToScroll
!= 0)
693 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
696 int wxTextCtrl::GetLineLength(const long lineNo
) const
698 long charIndex
= XYToPosition(0, lineNo
);
699 HWND hWnd
= (HWND
) GetHWND();
700 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
704 wxString
wxTextCtrl::GetLineText(const long lineNo
) const
706 HWND hWnd
= (HWND
) GetHWND();
707 *(WORD
*)wxBuffer
= 512;
708 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
709 wxBuffer
[noChars
] = 0;
710 return wxString(wxBuffer
);
717 void wxTextCtrl::Command(wxCommandEvent
& event
)
719 SetValue (event
.GetString());
720 ProcessCommand (event
);
723 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
725 // By default, load the first file into the text window.
726 if (event
.GetNumberOfFiles() > 0)
728 LoadFile(event
.GetFiles()[0]);
732 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
733 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
735 //=========================================================================
736 // Called then the buffer is full (gcc 2.6.3)
737 // or when "endl" is output (Borland 4.5)
738 //=========================================================================
739 // Class declaration using multiple inheritance doesn't work properly for
740 // Borland. See note in wb_text.h.
741 #ifndef NO_TEXT_WINDOW_STREAM
742 int wxTextCtrl::overflow(int c
)
744 // Make sure there is a holding area
745 if ( allocate()==EOF
)
747 wxError("Streambuf allocation failed","Internal error");
751 // Verify that there are no characters in get area
752 if ( gptr() && gptr() < egptr() )
754 wxError("Who's trespassing my get area?","Internal error");
761 // Make sure there is a put area
764 /* This doesn't seem to be fatal so comment out error message */
765 // wxError("Put area not opened","Internal error");
766 setp( base(), base() );
769 // Determine how many characters have been inserted but no consumed
770 int plen
= pptr() - pbase();
772 // Now Jerry relies on the fact that the buffer is at least 2 chars
773 // long, but the holding area "may be as small as 1" ???
774 // And we need an additional \0, so let's keep this inefficient but
777 // If c!=EOF, it is a character that must also be comsumed
778 int xtra
= c
==EOF
? 0 : 1;
780 // Write temporary C-string to wxTextWindow
782 char *txt
= new char[plen
+xtra
+1];
783 memcpy(txt
, pbase(), plen
);
784 txt
[plen
] = (char)c
; // append c
785 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
786 // If the put area already contained \0, output will be truncated there
792 setp(pbase(), epptr());
794 #if defined(__WATCOMC__)
796 #elif defined(zapeof) // HP-UX (all cfront based?)
799 return c
!=EOF
? c
: 0; // this should make everybody happy
803 int len = pptr() - pbase();
804 char *txt = new char[len+1];
805 strncpy(txt, pbase(), len);
808 setp(pbase(), epptr());
814 //=========================================================================
815 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
816 //=========================================================================
817 int wxTextCtrl::sync(void)
819 // Verify that there are no characters in get area
820 if ( gptr() && gptr() < egptr() )
822 wxError("Who's trespassing my get area?","Internal error");
826 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
830 int len = pptr() - pbase();
831 char *txt = new char[len+1];
832 strncpy(txt, pbase(), len);
835 setp(pbase(), epptr());
841 //=========================================================================
842 // Should not be called by a "ostream". Used by a "istream"
843 //=========================================================================
844 int wxTextCtrl::underflow(void)
850 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
856 wxTextCtrl
& wxTextCtrl::operator<<(const float f
)
858 static char buf
[100];
859 sprintf(buf
, "%.2f", f
);
864 wxTextCtrl
& wxTextCtrl::operator<<(const double d
)
866 static char buf
[100];
867 sprintf(buf
, "%.2f", d
);
872 wxTextCtrl
& wxTextCtrl::operator<<(const int i
)
874 static char buf
[100];
875 sprintf(buf
, "%i", i
);
880 wxTextCtrl
& wxTextCtrl::operator<<(const long i
)
882 static char buf
[100];
883 sprintf(buf
, "%ld", i
);
888 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
899 WXHBRUSH
wxTextCtrl::OnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
900 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
905 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
906 return (WXHBRUSH
) hbrush
;
910 if (GetParent()->GetTransparentBackground())
911 SetBkMode((HDC
) pDC
, TRANSPARENT
);
913 SetBkMode((HDC
) pDC
, OPAQUE
);
915 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
916 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
918 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
920 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
921 // has a zero usage count.
922 // NOT NOW - will be cleaned up at end of app.
923 // backgroundBrush->RealizeResource();
924 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
927 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
929 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
931 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
932 event
.SetEventObject( this );
933 if ( !GetEventHandler()->ProcessEvent(event
) )
940 long wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
947 if (GetWindowStyleFlag() & wxPROCESS_ENTER)
948 return DLGC_WANTALLKEYS;
951 case WM_CHAR: // Always an ASCII character
953 if (wParam == VK_RETURN)
955 wxCommandEvent event(wxEVENT_TYPE_TEXT_ENTER_COMMAND);
956 event.commandString = ((wxTextCtrl *)item)->GetValue();
957 event.eventObject = item;
958 item->ProcessCommand(event);
968 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
971 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
973 if ( m_windowStyle
& wxTE_MULTILINE
)
975 // No flicker - only problem is we probably can't change the background
979 ::GetClientRect((HWND) GetHWND(), &rect);
981 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
982 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
984 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
985 ::DeleteObject(hBrush);
986 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
989 // wxWindow::OnEraseBackground(event);
992 bool wxTextCtrl::MSWCommand(const WXUINT param
, const WXWORD
WXUNUSED(id
))
996 wxDebugMsg("Edit control %d: ", (int)id);
1000 wxDebugMsg("EN_SETFOCUS\n");
1003 wxDebugMsg("EN_KILLFOCUS\n");
1006 wxDebugMsg("EN_CHANGE\n");
1009 wxDebugMsg("EN_UPDATE\n");
1012 wxDebugMsg("EN_ERRSPACE\n");
1015 wxDebugMsg("EN_MAXTEXT\n");
1018 wxDebugMsg("EN_HSCROLL\n");
1021 wxDebugMsg("EN_VSCROLL\n");
1024 wxDebugMsg("Unknown EDIT notification\n");
1028 WXTYPE eventTyp
= 0;
1032 eventTyp
= wxEVENT_TYPE_SET_FOCUS
;
1035 eventTyp
= wxEVENT_TYPE_KILL_FOCUS
;
1040 eventTyp
= wxEVENT_TYPE_TEXT_COMMAND
;
1055 wxCommandEvent
event(eventTyp
, m_windowId
);
1056 wxString
val(GetValue());
1057 if ( !val
.IsNull() )
1058 event
.m_commandString
= WXSTRINGCAST val
;
1059 event
.SetEventObject( this );
1060 ProcessCommand(event
);
1069 // For Rich Edit controls. Do we need it?
1071 #if defined(__WIN95__)
1072 bool wxTextCtrl::MSWNotify(const WXWPARAM wParam
, const WXLPARAM lParam
)
1074 wxCommandEvent
event(0, m_windowId
);
1076 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1077 switch ( hdr1
->code
)
1079 // Insert case code here
1081 return wxControl::MSWNotify(wParam
, lParam
);
1085 event
.SetEventObject( this );
1086 event
.SetEventType(eventType
);
1088 if ( !ProcessEvent(event
) )