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
, wxWindowID id
,
80 const wxString
& value
,
82 const wxSize
& size
, 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
? (HINSTANCE
) 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(int x
, int y
, int width
, int height
, 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
);
350 // Clipboard operations
351 void wxTextCtrl::Copy(void)
353 HWND hWnd
= (HWND
) GetHWND();
354 SendMessage(hWnd
, WM_COPY
, 0, 0L);
357 void wxTextCtrl::Cut(void)
359 HWND hWnd
= (HWND
) GetHWND();
360 SendMessage(hWnd
, WM_CUT
, 0, 0L);
363 void wxTextCtrl::Paste(void)
365 HWND hWnd
= (HWND
) GetHWND();
366 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
369 void wxTextCtrl::SetEditable(bool editable
)
371 HWND hWnd
= (HWND
) GetHWND();
372 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
375 void wxTextCtrl::SetInsertionPoint(long pos
)
377 HWND hWnd
= (HWND
) GetHWND();
379 #if defined(__WIN95__)
385 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
386 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
391 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
392 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
395 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
398 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
401 void wxTextCtrl::SetInsertionPointEnd(void)
403 long pos
= GetLastPosition();
404 SetInsertionPoint(pos
);
407 long wxTextCtrl::GetInsertionPoint(void) const
409 #if defined(__WIN95__)
415 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
420 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
424 long wxTextCtrl::GetLastPosition(void) const
426 HWND hWnd
= (HWND
) GetHWND();
428 // Will always return a number > 0 (according to docs)
429 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
431 // This gets the char index for the _beginning_ of the last line
432 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
434 // Get number of characters in the last line. We'll add this to the character
435 // index for the last line, 1st position.
436 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
438 return (long)(charIndex
+ lineLength
);
441 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
443 HWND hWnd
= (HWND
) GetHWND();
444 long fromChar
= from
;
447 // Set selection and remove it
449 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
451 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
453 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
455 // Now replace with 'value', by pasting.
456 wxSetClipboardData(wxCF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
458 // Paste into edit control
459 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
462 void wxTextCtrl::Remove(long from
, long to
)
464 HWND hWnd
= (HWND
) GetHWND();
465 long fromChar
= from
;
468 // Cut all selected text
470 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
472 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
474 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
477 void wxTextCtrl::SetSelection(long from
, long to
)
479 HWND hWnd
= (HWND
) GetHWND();
480 long fromChar
= from
;
482 // if from and to are both -1, it means
483 // (in wxWindows) that all text should be selected.
484 // This translates into Windows convention
485 if ((from
== -1) && (to
== -1))
492 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
493 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
495 // WPARAM is 0: selection is scrolled into view
496 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
500 bool wxTextCtrl::LoadFile(const wxString
& file
)
502 if (!FileExists(WXSTRINGCAST file
))
509 ifstream
input(WXSTRINGCAST file
, ios::nocreate
| ios::in
);
513 // Previously a SETSEL/REPLACESEL call-pair were done to insert
514 // line by line into the control. Apart from being very slow this
515 // was limited to 32K of text by the external interface presenting
516 // positions as signed shorts. Now load in one chunk...
517 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
519 struct stat stat_buf
;
520 if (stat(file
, &stat_buf
) < 0)
522 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
523 // This may need to be a bigger buffer than the file size suggests,
524 // if it's a UNIX file. Give it an extra 1000 just in case.
525 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
528 while (!input
.eof() && input
.peek() != EOF
)
530 input
.getline(wxBuffer
, 500);
531 int len
= strlen(wxBuffer
);
533 wxBuffer
[len
+1] = 10;
535 strcpy(tmp_buffer
+pos
, wxBuffer
);
536 pos
+= strlen(wxBuffer
);
540 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
541 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
542 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
550 // If file is null, try saved file name first
551 // Returns TRUE if succeeds.
552 bool wxTextCtrl::SaveFile(const wxString
& file
)
561 ofstream
output(WXSTRINGCAST file
);
565 // This will only save 64K max
566 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
567 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
568 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
569 char *pstr
= tmp_buffer
;
571 // Convert \r\n to just \n
580 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
585 void wxTextCtrl::WriteText(const wxString
& text
)
588 int len
= text
.Length();
589 char *newtext
= new char[(len
*2)+1];
599 newtext
[j
] = text
[i
];
604 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
608 void wxTextCtrl::Clear(void)
610 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
611 SetWindowText((HWND
) GetHWND(), "");
614 bool wxTextCtrl::IsModified(void) const
616 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
619 // Makes 'unmodified'
620 void wxTextCtrl::DiscardEdits(void)
622 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
626 * Some of the following functions are yet to be implemented
630 int wxTextCtrl::GetNumberOfLines(void) const
632 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
635 long wxTextCtrl::XYToPosition(long x
, long y
) const
637 HWND hWnd
= (HWND
) GetHWND();
639 // This gets the char index for the _beginning_ of this line
640 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
641 return (long)(x
+ charIndex
);
644 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
646 HWND hWnd
= (HWND
) GetHWND();
648 // This gets the line number containing the character
649 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
650 // This gets the char index for the _beginning_ of this line
651 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
652 // The X position must therefore be the different between pos and charIndex
653 *x
= (long)(pos
- charIndex
);
657 void wxTextCtrl::ShowPosition(long pos
)
659 HWND hWnd
= (HWND
) GetHWND();
661 // To scroll to a position, we pass the number of lines and characters
662 // to scroll *by*. This means that we need to:
663 // (1) Find the line position of the current line.
664 // (2) Find the line position of pos.
665 // (3) Scroll by (pos - current).
666 // For now, ignore the horizontal scrolling.
668 // Is this where scrolling is relative to - the line containing the caret?
669 // Or is the first visible line??? Try first visible line.
670 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
672 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
674 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
676 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
679 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
680 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
683 if (linesToScroll
!= 0)
684 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
687 int wxTextCtrl::GetLineLength(long lineNo
) const
689 long charIndex
= XYToPosition(0, lineNo
);
690 HWND hWnd
= (HWND
) GetHWND();
691 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
695 wxString
wxTextCtrl::GetLineText(long lineNo
) const
697 HWND hWnd
= (HWND
) GetHWND();
698 *(WORD
*)wxBuffer
= 512;
699 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
700 wxBuffer
[noChars
] = 0;
701 return wxString(wxBuffer
);
708 void wxTextCtrl::Command(wxCommandEvent
& event
)
710 SetValue (event
.GetString());
711 ProcessCommand (event
);
714 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
716 // By default, load the first file into the text window.
717 if (event
.GetNumberOfFiles() > 0)
719 LoadFile(event
.GetFiles()[0]);
723 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
724 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
726 //=========================================================================
727 // Called then the buffer is full (gcc 2.6.3)
728 // or when "endl" is output (Borland 4.5)
729 //=========================================================================
730 // Class declaration using multiple inheritance doesn't work properly for
731 // Borland. See note in wb_text.h.
732 #ifndef NO_TEXT_WINDOW_STREAM
733 int wxTextCtrl::overflow(int c
)
735 // Make sure there is a holding area
736 if ( allocate()==EOF
)
738 wxError("Streambuf allocation failed","Internal error");
742 // Verify that there are no characters in get area
743 if ( gptr() && gptr() < egptr() )
745 wxError("Who's trespassing my get area?","Internal error");
752 // Make sure there is a put area
755 /* This doesn't seem to be fatal so comment out error message */
756 // wxError("Put area not opened","Internal error");
757 setp( base(), base() );
760 // Determine how many characters have been inserted but no consumed
761 int plen
= pptr() - pbase();
763 // Now Jerry relies on the fact that the buffer is at least 2 chars
764 // long, but the holding area "may be as small as 1" ???
765 // And we need an additional \0, so let's keep this inefficient but
768 // If c!=EOF, it is a character that must also be comsumed
769 int xtra
= c
==EOF
? 0 : 1;
771 // Write temporary C-string to wxTextWindow
773 char *txt
= new char[plen
+xtra
+1];
774 memcpy(txt
, pbase(), plen
);
775 txt
[plen
] = (char)c
; // append c
776 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
777 // If the put area already contained \0, output will be truncated there
783 setp(pbase(), epptr());
785 #if defined(__WATCOMC__)
787 #elif defined(zapeof) // HP-UX (all cfront based?)
790 return c
!=EOF
? c
: 0; // this should make everybody happy
794 int len = pptr() - pbase();
795 char *txt = new char[len+1];
796 strncpy(txt, pbase(), len);
799 setp(pbase(), epptr());
805 //=========================================================================
806 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
807 //=========================================================================
808 int wxTextCtrl::sync(void)
810 // Verify that there are no characters in get area
811 if ( gptr() && gptr() < egptr() )
813 wxError("Who's trespassing my get area?","Internal error");
817 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
821 int len = pptr() - pbase();
822 char *txt = new char[len+1];
823 strncpy(txt, pbase(), len);
826 setp(pbase(), epptr());
832 //=========================================================================
833 // Should not be called by a "ostream". Used by a "istream"
834 //=========================================================================
835 int wxTextCtrl::underflow(void)
841 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
847 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
849 static char buf
[100];
850 sprintf(buf
, "%.2f", f
);
855 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
857 static char buf
[100];
858 sprintf(buf
, "%.2f", d
);
863 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
865 static char buf
[100];
866 sprintf(buf
, "%i", i
);
871 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
873 static char buf
[100];
874 sprintf(buf
, "%ld", i
);
879 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
890 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
891 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
896 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
897 return (WXHBRUSH
) hbrush
;
901 if (GetParent()->GetTransparentBackground())
902 SetBkMode((HDC
) pDC
, TRANSPARENT
);
904 SetBkMode((HDC
) pDC
, OPAQUE
);
906 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
907 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
909 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
911 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
912 // has a zero usage count.
913 // NOT NOW - will be cleaned up at end of app.
914 // backgroundBrush->RealizeResource();
915 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
918 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
920 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
922 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
923 event
.SetEventObject( this );
924 if ( GetEventHandler()->ProcessEvent(event
) )
927 else if ( event
.KeyCode() == WXK_TAB
) {
928 wxNavigationKeyEvent event
;
929 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
930 event
.SetWindowChange(FALSE
);
931 event
.SetEventObject(this);
933 if ( GetEventHandler()->ProcessEvent(event
) )
940 long wxTextCtrl::MSWGetDlgCode()
942 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
943 if ( m_windowStyle
& wxPROCESS_ENTER
) {
944 lRc
|= DLGC_WANTMESSAGE
;
951 long wxTextCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
957 if (GetWindowStyleFlag() & wxPROCESS_ENTER)
958 return DLGC_WANTALLKEYS;
961 case WM_CHAR: // Always an ASCII character
963 if (wParam == VK_RETURN)
965 wxCommandEvent event(wxEVENT_TYPE_TEXT_ENTER_COMMAND);
966 event.commandString = ((wxTextCtrl *)item)->GetValue();
967 event.eventObject = item;
968 item->ProcessCommand(event);
977 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
981 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
983 if ( m_windowStyle
& wxTE_MULTILINE
)
985 // No flicker - only problem is we probably can't change the background
989 ::GetClientRect((HWND) GetHWND(), &rect);
991 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
992 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
994 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
995 ::DeleteObject(hBrush);
996 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
999 // wxWindow::OnEraseBackground(event);
1002 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1006 wxDebugMsg("Edit control %d: ", (int)id);
1010 wxDebugMsg("EN_SETFOCUS\n");
1013 wxDebugMsg("EN_KILLFOCUS\n");
1016 wxDebugMsg("EN_CHANGE\n");
1019 wxDebugMsg("EN_UPDATE\n");
1022 wxDebugMsg("EN_ERRSPACE\n");
1025 wxDebugMsg("EN_MAXTEXT\n");
1028 wxDebugMsg("EN_HSCROLL\n");
1031 wxDebugMsg("EN_VSCROLL\n");
1034 wxDebugMsg("Unknown EDIT notification\n");
1043 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1046 event
.SetEventObject( this );
1047 ProcessEvent(event
);
1053 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1054 wxString
val(GetValue());
1055 if ( !val
.IsNull() )
1056 event
.m_commandString
= WXSTRINGCAST val
;
1057 event
.SetEventObject( this );
1058 ProcessCommand(event
);
1062 // the other notification messages are not processed
1077 // For Rich Edit controls. Do we need it?
1079 #if defined(__WIN95__)
1080 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1082 wxCommandEvent
event(0, m_windowId
);
1084 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1085 switch ( hdr1
->code
)
1087 // Insert case code here
1089 return wxControl::MSWNotify(wParam
, lParam
);
1093 event
.SetEventObject( this );
1094 event
.SetEventType(eventType
);
1096 if ( !ProcessEvent(event
) )