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"
47 #include <sys/types.h>
49 #if defined(__BORLANDC__) && !defined(__WIN32__)
55 #define farmalloc malloc
62 #if defined(__WIN95__) && !defined(__GNUWIN32__)
66 #if !USE_SHARED_LIBRARY
67 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
69 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
70 EVT_CHAR(wxTextCtrl::OnChar
)
71 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
72 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
78 wxTextCtrl::wxTextCtrl(void)
79 #ifndef NO_TEXT_WINDOW_STREAM
87 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
88 const wxString
& value
,
90 const wxSize
& size
, long style
,
91 const wxValidator
& validator
,
96 SetValidator(validator
);
97 if (parent
) parent
->AddChild(this);
99 m_windowStyle
= style
;
101 // Should this be taken from the system colours?
102 // SetBackgroundColour(wxColour(255, 255, 255));
104 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
106 SetForegroundColour(parent
->GetForegroundColour()) ;
109 m_windowId
= (int)NewControlId();
119 WXHGLOBAL m_globalHandle
= 0;
121 // Obscure method from the MS Developer's Network Disk for
122 // using global memory instead of the local heap, which
123 // runs out far too soon. Solves the problem with
124 // failing to appear.
126 // Doesn't seem to work for Win95, so removing.
128 // if ((wxGetOsVersion() != wxWINDOWS_NT) && (wxGetOsVersion() != wxWIN95))
129 // m_globalHandle = (WXHGLOBAL) GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
132 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
133 if (m_windowStyle
& wxTE_MULTILINE
)
134 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
136 msStyle
|= ES_AUTOHSCROLL
;
138 if (m_windowStyle
& wxTE_READONLY
)
139 msStyle
|= ES_READONLY
;
141 if (m_windowStyle
& wxHSCROLL
)
142 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
143 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
144 msStyle
|= ES_PASSWORD
;
146 char *windowClass
= "EDIT";
147 #if defined(__WIN95__)
148 if ( m_windowStyle
& wxTE_MULTILINE
)
153 msStyle
|= ES_AUTOVSCROLL
;
155 windowClass
= "RichEdit" ;
161 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
163 // If we're in Win95, and we want a simple 2D border,
164 // then make it an EDIT control instead.
165 #if defined(__WIN95__)
166 if (m_windowStyle
& wxSIMPLE_BORDER
)
168 windowClass
= "EDIT";
173 // Even with extended styles, need to combine with WS_BORDER
174 // for them to look right.
175 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
176 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
177 msStyle
|= WS_BORDER
;
179 HWND edit
= CreateWindowEx(exStyle
, windowClass
, NULL
,
181 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
182 m_globalHandle
? (HINSTANCE
) m_globalHandle
: wxGetInstance(), NULL
);
187 Ctl3dSubclassCtl(edit
);
192 m_hWnd
= (WXHWND
)edit
;
194 #if defined(__WIN95__)
197 // Have to enable events
198 ::SendMessage(edit
, EM_SETEVENTMASK
, 0, ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
202 SubclassWin(GetHWND());
204 if ( parent
->GetFont() && parent
->GetFont()->Ok() )
206 SetFont(* parent
->GetFont());
210 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
213 SetSize(x
, y
, width
, height
);
215 // Causes a crash for Symantec C++ and WIN32 for some reason
216 #if !(defined(__SC__) && defined(__WIN32__))
218 SetWindowText(edit
, (const char *)value
);
224 // Make sure the window style (etc.) reflects the HWND style (roughly)
225 void wxTextCtrl::AdoptAttributesFromHWND(void)
227 wxWindow::AdoptAttributesFromHWND();
229 HWND hWnd
= (HWND
) GetHWND();
230 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
235 GetClassName((HWND
) hWnd
, buf
, 256);
238 GetClassNameW((HWND
) hWnd
, buf
, 256);
240 GetClassNameA((HWND
) hWnd
, buf
, 256);
252 if (style
& ES_MULTILINE
)
253 m_windowStyle
|= wxTE_MULTILINE
;
254 if (style
& ES_PASSWORD
)
255 m_windowStyle
|= wxTE_PASSWORD
;
256 if (style
& ES_READONLY
)
257 m_windowStyle
|= wxTE_READONLY
;
258 if (style
& ES_WANTRETURN
)
259 m_windowStyle
|= wxTE_PROCESS_ENTER
;
262 void wxTextCtrl::SetupColours(void)
264 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
265 SetForegroundColour(GetParent()->GetForegroundColour());
268 wxString
wxTextCtrl::GetValue(void) const
270 int length
= GetWindowTextLength((HWND
) GetHWND());
271 char *s
= new char[length
+1];
272 GetWindowText((HWND
) GetHWND(), s
, length
+1);
278 void wxTextCtrl::SetValue(const wxString
& value
)
280 // If newlines are denoted by just 10, must stick 13 in front.
282 int len
= value
.Length();
284 for (i
= 0; i
< len
; i
++)
286 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
291 char *tmp
= new char[len
+ singletons
+ 1];
293 for (i
= 0; i
< len
; i
++)
295 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
304 SetWindowText((HWND
) GetHWND(), tmp
);
308 SetWindowText((HWND
) GetHWND(), (const char *)value
);
311 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
313 int currentX
, currentY
;
314 GetPosition(¤tX
, ¤tY
);
320 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
322 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
325 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
327 int cx
; // button font dimensions
330 wxGetCharSize(GetHWND(), &cx
, &cy
,GetFont());
332 int control_width
, control_height
, control_x
, control_y
;
334 // If we're prepared to use the existing size, then...
335 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
340 // Deal with default size (using -1 values)
342 w1
= DEFAULT_ITEM_WIDTH
;
349 // Calculations may have made text size too small
350 if (control_height
<= 0)
351 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
353 if (control_width
<= 0)
354 control_width
= DEFAULT_ITEM_WIDTH
;
356 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
357 (int)control_width
, (int)control_height
, TRUE
);
360 // Clipboard operations
361 void wxTextCtrl::Copy(void)
363 HWND hWnd
= (HWND
) GetHWND();
364 SendMessage(hWnd
, WM_COPY
, 0, 0L);
367 void wxTextCtrl::Cut(void)
369 HWND hWnd
= (HWND
) GetHWND();
370 SendMessage(hWnd
, WM_CUT
, 0, 0L);
373 void wxTextCtrl::Paste(void)
375 HWND hWnd
= (HWND
) GetHWND();
376 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
379 void wxTextCtrl::SetEditable(bool editable
)
381 HWND hWnd
= (HWND
) GetHWND();
382 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
385 void wxTextCtrl::SetInsertionPoint(long pos
)
387 HWND hWnd
= (HWND
) GetHWND();
389 #if defined(__WIN95__)
395 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
396 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
401 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
402 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
405 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
408 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
411 void wxTextCtrl::SetInsertionPointEnd(void)
413 long pos
= GetLastPosition();
414 SetInsertionPoint(pos
);
417 long wxTextCtrl::GetInsertionPoint(void) const
419 #if defined(__WIN95__)
425 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
430 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
434 long wxTextCtrl::GetLastPosition(void) const
436 HWND hWnd
= (HWND
) GetHWND();
438 // Will always return a number > 0 (according to docs)
439 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
441 // This gets the char index for the _beginning_ of the last line
442 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
444 // Get number of characters in the last line. We'll add this to the character
445 // index for the last line, 1st position.
446 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
448 return (long)(charIndex
+ lineLength
);
451 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
453 HWND hWnd
= (HWND
) GetHWND();
454 long fromChar
= from
;
457 // Set selection and remove it
459 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
461 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
463 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
465 // Now replace with 'value', by pasting.
466 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
468 // Paste into edit control
469 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
472 void wxTextCtrl::Remove(long from
, long to
)
474 HWND hWnd
= (HWND
) GetHWND();
475 long fromChar
= from
;
478 // Cut all selected text
480 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
482 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
484 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
487 void wxTextCtrl::SetSelection(long from
, long to
)
489 HWND hWnd
= (HWND
) GetHWND();
490 long fromChar
= from
;
492 // if from and to are both -1, it means
493 // (in wxWindows) that all text should be selected.
494 // This translates into Windows convention
495 if ((from
== -1) && (to
== -1))
502 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
503 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
505 // WPARAM is 0: selection is scrolled into view
506 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
510 bool wxTextCtrl::LoadFile(const wxString
& file
)
512 if (!FileExists(WXSTRINGCAST file
))
519 // ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
520 ifstream
input(WXSTRINGCAST file
, ios::in
);
524 // Previously a SETSEL/REPLACESEL call-pair were done to insert
525 // line by line into the control. Apart from being very slow this
526 // was limited to 32K of text by the external interface presenting
527 // positions as signed shorts. Now load in one chunk...
528 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
530 struct stat stat_buf
;
531 if (stat(file
, &stat_buf
) < 0)
533 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
534 // This may need to be a bigger buffer than the file size suggests,
535 // if it's a UNIX file. Give it an extra 1000 just in case.
536 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
539 while (!input
.eof() && input
.peek() != EOF
)
541 input
.getline(wxBuffer
, 500);
542 int len
= strlen(wxBuffer
);
544 wxBuffer
[len
+1] = 10;
546 strcpy(tmp_buffer
+pos
, wxBuffer
);
547 pos
+= strlen(wxBuffer
);
551 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
552 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
553 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
561 // If file is null, try saved file name first
562 // Returns TRUE if succeeds.
563 bool wxTextCtrl::SaveFile(const wxString
& file
)
565 wxString
theFile(file
);
567 theFile
= m_fileName
;
570 m_fileName
= theFile
;
572 ofstream
output((char*) (const char*) theFile
);
576 // This will only save 64K max
577 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
578 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
579 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
580 char *pstr
= tmp_buffer
;
582 // Convert \r\n to just \n
591 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
596 void wxTextCtrl::WriteText(const wxString
& text
)
599 int len
= text
.Length();
600 char *newtext
= new char[(len
*2)+1];
610 newtext
[j
] = text
[i
];
615 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
619 void wxTextCtrl::Clear(void)
621 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
622 SetWindowText((HWND
) GetHWND(), "");
625 bool wxTextCtrl::IsModified(void) const
627 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
630 // Makes 'unmodified'
631 void wxTextCtrl::DiscardEdits(void)
633 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
637 * Some of the following functions are yet to be implemented
641 int wxTextCtrl::GetNumberOfLines(void) const
643 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
646 long wxTextCtrl::XYToPosition(long x
, long y
) const
648 HWND hWnd
= (HWND
) GetHWND();
650 // This gets the char index for the _beginning_ of this line
651 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
652 return (long)(x
+ charIndex
);
655 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
657 HWND hWnd
= (HWND
) GetHWND();
659 // This gets the line number containing the character
660 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
661 // This gets the char index for the _beginning_ of this line
662 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
663 // The X position must therefore be the different between pos and charIndex
664 *x
= (long)(pos
- charIndex
);
668 void wxTextCtrl::ShowPosition(long pos
)
670 HWND hWnd
= (HWND
) GetHWND();
672 // To scroll to a position, we pass the number of lines and characters
673 // to scroll *by*. This means that we need to:
674 // (1) Find the line position of the current line.
675 // (2) Find the line position of pos.
676 // (3) Scroll by (pos - current).
677 // For now, ignore the horizontal scrolling.
679 // Is this where scrolling is relative to - the line containing the caret?
680 // Or is the first visible line??? Try first visible line.
681 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
683 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
685 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
687 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
690 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
691 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
694 if (linesToScroll
!= 0)
695 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
698 int wxTextCtrl::GetLineLength(long lineNo
) const
700 long charIndex
= XYToPosition(0, lineNo
);
701 HWND hWnd
= (HWND
) GetHWND();
702 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
706 wxString
wxTextCtrl::GetLineText(long lineNo
) const
708 HWND hWnd
= (HWND
) GetHWND();
709 *(WORD
*)wxBuffer
= 512;
710 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
711 wxBuffer
[noChars
] = 0;
712 return wxString(wxBuffer
);
719 void wxTextCtrl::Command(wxCommandEvent
& event
)
721 SetValue (event
.GetString());
722 ProcessCommand (event
);
725 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
727 // By default, load the first file into the text window.
728 if (event
.GetNumberOfFiles() > 0)
730 LoadFile(event
.GetFiles()[0]);
734 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
735 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
737 //=========================================================================
738 // Called then the buffer is full (gcc 2.6.3)
739 // or when "endl" is output (Borland 4.5)
740 //=========================================================================
741 // Class declaration using multiple inheritance doesn't work properly for
742 // Borland. See note in wb_text.h.
743 #ifndef NO_TEXT_WINDOW_STREAM
744 int wxTextCtrl::overflow(int c
)
746 // Make sure there is a holding area
747 if ( allocate()==EOF
)
749 wxError("Streambuf allocation failed","Internal error");
753 // Verify that there are no characters in get area
754 if ( gptr() && gptr() < egptr() )
756 wxError("Who's trespassing my get area?","Internal error");
763 // Make sure there is a put area
766 /* This doesn't seem to be fatal so comment out error message */
767 // wxError("Put area not opened","Internal error");
768 setp( base(), base() );
771 // Determine how many characters have been inserted but no consumed
772 int plen
= pptr() - pbase();
774 // Now Jerry relies on the fact that the buffer is at least 2 chars
775 // long, but the holding area "may be as small as 1" ???
776 // And we need an additional \0, so let's keep this inefficient but
779 // If c!=EOF, it is a character that must also be comsumed
780 int xtra
= c
==EOF
? 0 : 1;
782 // Write temporary C-string to wxTextWindow
784 char *txt
= new char[plen
+xtra
+1];
785 memcpy(txt
, pbase(), plen
);
786 txt
[plen
] = (char)c
; // append c
787 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
788 // If the put area already contained \0, output will be truncated there
794 setp(pbase(), epptr());
796 #if defined(__WATCOMC__)
798 #elif defined(zapeof) // HP-UX (all cfront based?)
801 return c
!=EOF
? c
: 0; // this should make everybody happy
805 int len = pptr() - pbase();
806 char *txt = new char[len+1];
807 strncpy(txt, pbase(), len);
810 setp(pbase(), epptr());
816 //=========================================================================
817 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
818 //=========================================================================
819 int wxTextCtrl::sync(void)
821 // Verify that there are no characters in get area
822 if ( gptr() && gptr() < egptr() )
824 wxError("Who's trespassing my get area?","Internal error");
828 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
832 int len = pptr() - pbase();
833 char *txt = new char[len+1];
834 strncpy(txt, pbase(), len);
837 setp(pbase(), epptr());
843 //=========================================================================
844 // Should not be called by a "ostream". Used by a "istream"
845 //=========================================================================
846 int wxTextCtrl::underflow(void)
852 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
858 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
861 str
.Printf("%.2f", f
);
866 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
869 str
.Printf("%.2f", d
);
874 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
882 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
885 str
.Printf("%ld", i
);
890 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
900 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
901 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
906 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
907 return (WXHBRUSH
) hbrush
;
911 if (GetParent()->GetTransparentBackground())
912 SetBkMode((HDC
) pDC
, TRANSPARENT
);
914 SetBkMode((HDC
) pDC
, OPAQUE
);
916 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
917 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
919 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
921 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
922 // has a zero usage count.
923 // NOT NOW - will be cleaned up at end of app.
924 // backgroundBrush->RealizeResource();
925 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
928 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
930 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
932 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
933 event
.SetEventObject( this );
934 if ( GetEventHandler()->ProcessEvent(event
) )
937 else if ( event
.KeyCode() == WXK_TAB
) {
938 wxNavigationKeyEvent event
;
939 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
940 event
.SetWindowChange(FALSE
);
941 event
.SetEventObject(this);
943 if ( GetEventHandler()->ProcessEvent(event
) )
950 long wxTextCtrl::MSWGetDlgCode()
952 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
953 if ( m_windowStyle
& wxPROCESS_ENTER
)
954 lRc
|= DLGC_WANTMESSAGE
;
955 else if ( m_windowStyle
& wxTE_MULTILINE
)
956 lRc
|= DLGC_WANTMESSAGE
;
961 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
963 if ( m_windowStyle
& wxTE_MULTILINE
)
965 // No flicker - only problem is we probably can't change the background
969 ::GetClientRect((HWND) GetHWND(), &rect);
971 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
972 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
974 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
975 ::DeleteObject(hBrush);
976 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
979 // wxWindow::OnEraseBackground(event);
982 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
986 wxDebugMsg("Edit control %d: ", (int)id);
990 wxDebugMsg("EN_SETFOCUS\n");
993 wxDebugMsg("EN_KILLFOCUS\n");
996 wxDebugMsg("EN_CHANGE\n");
999 wxDebugMsg("EN_UPDATE\n");
1002 wxDebugMsg("EN_ERRSPACE\n");
1005 wxDebugMsg("EN_MAXTEXT\n");
1008 wxDebugMsg("EN_HSCROLL\n");
1011 wxDebugMsg("EN_VSCROLL\n");
1014 wxDebugMsg("Unknown EDIT notification\n");
1023 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1026 event
.SetEventObject( this );
1027 ProcessEvent(event
);
1033 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1034 wxString
val(GetValue());
1035 if ( !val
.IsNull() )
1036 event
.m_commandString
= WXSTRINGCAST val
;
1037 event
.SetEventObject( this );
1038 ProcessCommand(event
);
1042 // the other notification messages are not processed
1057 // For Rich Edit controls. Do we need it?
1059 #if defined(__WIN95__)
1060 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1062 wxCommandEvent
event(0, m_windowId
);
1064 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1065 switch ( hdr1
->code
)
1067 // Insert case code here
1069 return wxControl::MSWNotify(wParam
, lParam
);
1073 event
.SetEventObject( this );
1074 event
.SetEventType(eventType
);
1076 if ( !ProcessEvent(event
) )