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,
133 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
134 if (m_windowStyle
& wxTE_MULTILINE
)
135 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
137 msStyle
|= ES_AUTOHSCROLL
;
139 if (m_windowStyle
& wxTE_READONLY
)
140 msStyle
|= ES_READONLY
;
142 if (m_windowStyle
& wxHSCROLL
)
143 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
144 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
145 msStyle
|= ES_PASSWORD
;
147 char *windowClass
= "EDIT";
148 #if defined(__WIN95__)
149 if ( m_windowStyle
& wxTE_MULTILINE
)
151 msStyle
|= ES_AUTOVSCROLL
;
153 windowClass
= "RichEdit" ;
160 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
162 // If we're in Win95, and we want a simple 2D border,
163 // then make it an EDIT control instead.
164 #if defined(__WIN95__)
165 if (m_windowStyle
& wxSIMPLE_BORDER
)
167 windowClass
= "EDIT";
172 // Even with extended styles, need to combine with WS_BORDER
173 // for them to look right.
174 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
175 msStyle
|= WS_BORDER
;
177 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, windowClass
, NULL
,
179 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
180 m_globalHandle
? (HINSTANCE
) m_globalHandle
: wxGetInstance(), NULL
);
182 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create text ctrl" );
187 Ctl3dSubclassCtl((HWND
)m_hWnd
);
192 #if defined(__WIN95__)
195 // Have to enable events
196 ::SendMessage((HWND
)m_hWnd
, EM_SETEVENTMASK
, 0,
197 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
201 SubclassWin(GetHWND());
203 if ( parent
->GetFont().Ok() && parent
->GetFont().Ok() )
205 SetFont(parent
->GetFont());
209 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
212 SetSize(x
, y
, width
, height
);
214 // Causes a crash for Symantec C++ and WIN32 for some reason
215 #if !(defined(__SC__) && defined(__WIN32__))
216 if ( !value
.IsEmpty() )
225 // Make sure the window style (etc.) reflects the HWND style (roughly)
226 void wxTextCtrl::AdoptAttributesFromHWND(void)
228 wxWindow::AdoptAttributesFromHWND();
230 HWND hWnd
= (HWND
) GetHWND();
231 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
236 GetClassName((HWND
) hWnd
, buf
, 256);
239 GetClassNameW((HWND
) hWnd
, buf
, 256);
241 GetClassNameA((HWND
) hWnd
, buf
, 256);
253 if (style
& ES_MULTILINE
)
254 m_windowStyle
|= wxTE_MULTILINE
;
255 if (style
& ES_PASSWORD
)
256 m_windowStyle
|= wxTE_PASSWORD
;
257 if (style
& ES_READONLY
)
258 m_windowStyle
|= wxTE_READONLY
;
259 if (style
& ES_WANTRETURN
)
260 m_windowStyle
|= wxTE_PROCESS_ENTER
;
263 void wxTextCtrl::SetupColours(void)
265 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
266 SetForegroundColour(GetParent()->GetForegroundColour());
269 wxString
wxTextCtrl::GetValue(void) const
271 int length
= GetWindowTextLength((HWND
) GetHWND());
272 char *s
= new char[length
+1];
273 GetWindowText((HWND
) GetHWND(), s
, length
+1);
279 void wxTextCtrl::SetValue(const wxString
& value
)
281 // If newlines are denoted by just 10, must stick 13 in front.
283 int len
= value
.Length();
285 for (i
= 0; i
< len
; i
++)
287 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
292 char *tmp
= new char[len
+ singletons
+ 1];
294 for (i
= 0; i
< len
; i
++)
296 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
305 SetWindowText((HWND
) GetHWND(), tmp
);
309 SetWindowText((HWND
) GetHWND(), (const char *)value
);
312 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
314 int currentX
, currentY
;
315 GetPosition(¤tX
, ¤tY
);
321 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
323 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
326 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
328 int cx
; // button font dimensions
331 wxGetCharSize(GetHWND(), &cx
, &cy
, & GetFont());
333 int control_width
, control_height
, control_x
, control_y
;
335 // If we're prepared to use the existing size, then...
336 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
341 // Deal with default size (using -1 values)
343 w1
= DEFAULT_ITEM_WIDTH
;
350 // Calculations may have made text size too small
351 if (control_height
<= 0)
352 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
354 if (control_width
<= 0)
355 control_width
= DEFAULT_ITEM_WIDTH
;
357 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
358 (int)control_width
, (int)control_height
, TRUE
);
361 // Clipboard operations
362 void wxTextCtrl::Copy(void)
364 HWND hWnd
= (HWND
) GetHWND();
365 SendMessage(hWnd
, WM_COPY
, 0, 0L);
368 void wxTextCtrl::Cut(void)
370 HWND hWnd
= (HWND
) GetHWND();
371 SendMessage(hWnd
, WM_CUT
, 0, 0L);
374 void wxTextCtrl::Paste(void)
376 HWND hWnd
= (HWND
) GetHWND();
377 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
380 void wxTextCtrl::SetEditable(bool editable
)
382 HWND hWnd
= (HWND
) GetHWND();
383 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
386 void wxTextCtrl::SetInsertionPoint(long pos
)
388 HWND hWnd
= (HWND
) GetHWND();
390 #if defined(__WIN95__)
396 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
397 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
402 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
403 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
406 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
409 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
412 void wxTextCtrl::SetInsertionPointEnd(void)
414 long pos
= GetLastPosition();
415 SetInsertionPoint(pos
);
418 long wxTextCtrl::GetInsertionPoint(void) const
420 #if defined(__WIN95__)
426 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
431 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
435 long wxTextCtrl::GetLastPosition(void) const
437 HWND hWnd
= (HWND
) GetHWND();
439 // Will always return a number > 0 (according to docs)
440 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
442 // This gets the char index for the _beginning_ of the last line
443 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
445 // Get number of characters in the last line. We'll add this to the character
446 // index for the last line, 1st position.
447 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
449 return (long)(charIndex
+ lineLength
);
452 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
454 HWND hWnd
= (HWND
) GetHWND();
455 long fromChar
= from
;
458 // Set selection and remove it
460 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
462 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
464 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
466 // Now replace with 'value', by pasting.
467 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
469 // Paste into edit control
470 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
473 void wxTextCtrl::Remove(long from
, long to
)
475 HWND hWnd
= (HWND
) GetHWND();
476 long fromChar
= from
;
479 // Cut all selected text
481 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
483 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
485 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
488 void wxTextCtrl::SetSelection(long from
, long to
)
490 HWND hWnd
= (HWND
) GetHWND();
491 long fromChar
= from
;
493 // if from and to are both -1, it means
494 // (in wxWindows) that all text should be selected.
495 // This translates into Windows convention
496 if ((from
== -1) && (to
== -1))
503 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
504 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
506 // WPARAM is 0: selection is scrolled into view
507 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
511 bool wxTextCtrl::LoadFile(const wxString
& file
)
513 if (!FileExists(WXSTRINGCAST file
))
520 // ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
521 ifstream
input(WXSTRINGCAST file
, ios::in
);
525 // Previously a SETSEL/REPLACESEL call-pair were done to insert
526 // line by line into the control. Apart from being very slow this
527 // was limited to 32K of text by the external interface presenting
528 // positions as signed shorts. Now load in one chunk...
529 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
531 struct stat stat_buf
;
532 if (stat(file
, &stat_buf
) < 0)
534 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
535 // This may need to be a bigger buffer than the file size suggests,
536 // if it's a UNIX file. Give it an extra 1000 just in case.
537 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
540 while (!input
.eof() && input
.peek() != EOF
)
542 input
.getline(wxBuffer
, 500);
543 int len
= strlen(wxBuffer
);
545 wxBuffer
[len
+1] = 10;
547 strcpy(tmp_buffer
+pos
, wxBuffer
);
548 pos
+= strlen(wxBuffer
);
552 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
553 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
554 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
562 // If file is null, try saved file name first
563 // Returns TRUE if succeeds.
564 bool wxTextCtrl::SaveFile(const wxString
& file
)
566 wxString
theFile(file
);
568 theFile
= m_fileName
;
571 m_fileName
= theFile
;
573 ofstream
output((char*) (const char*) theFile
);
577 // This will only save 64K max
578 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
579 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
580 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
581 char *pstr
= tmp_buffer
;
583 // Convert \r\n to just \n
592 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
597 void wxTextCtrl::WriteText(const wxString
& text
)
600 int len
= text
.Length();
601 char *newtext
= new char[(len
*2)+1];
611 newtext
[j
] = text
[i
];
616 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
620 void wxTextCtrl::Clear(void)
622 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
623 SetWindowText((HWND
) GetHWND(), "");
626 bool wxTextCtrl::IsModified(void) const
628 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
631 // Makes 'unmodified'
632 void wxTextCtrl::DiscardEdits(void)
634 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
638 * Some of the following functions are yet to be implemented
642 int wxTextCtrl::GetNumberOfLines(void) const
644 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
647 long wxTextCtrl::XYToPosition(long x
, long y
) const
649 HWND hWnd
= (HWND
) GetHWND();
651 // This gets the char index for the _beginning_ of this line
652 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
653 return (long)(x
+ charIndex
);
656 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
658 HWND hWnd
= (HWND
) GetHWND();
660 // This gets the line number containing the character
661 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
662 // This gets the char index for the _beginning_ of this line
663 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
664 // The X position must therefore be the different between pos and charIndex
665 *x
= (long)(pos
- charIndex
);
669 void wxTextCtrl::ShowPosition(long pos
)
671 HWND hWnd
= (HWND
) GetHWND();
673 // To scroll to a position, we pass the number of lines and characters
674 // to scroll *by*. This means that we need to:
675 // (1) Find the line position of the current line.
676 // (2) Find the line position of pos.
677 // (3) Scroll by (pos - current).
678 // For now, ignore the horizontal scrolling.
680 // Is this where scrolling is relative to - the line containing the caret?
681 // Or is the first visible line??? Try first visible line.
682 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
684 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
686 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
688 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
691 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
692 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
695 if (linesToScroll
!= 0)
696 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
699 int wxTextCtrl::GetLineLength(long lineNo
) const
701 long charIndex
= XYToPosition(0, lineNo
);
702 HWND hWnd
= (HWND
) GetHWND();
703 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
707 wxString
wxTextCtrl::GetLineText(long lineNo
) const
709 HWND hWnd
= (HWND
) GetHWND();
710 *(WORD
*)wxBuffer
= 512;
711 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
712 wxBuffer
[noChars
] = 0;
713 return wxString(wxBuffer
);
720 void wxTextCtrl::Command(wxCommandEvent
& event
)
722 SetValue (event
.GetString());
723 ProcessCommand (event
);
726 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
728 // By default, load the first file into the text window.
729 if (event
.GetNumberOfFiles() > 0)
731 LoadFile(event
.GetFiles()[0]);
735 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
736 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
738 //=========================================================================
739 // Called then the buffer is full (gcc 2.6.3)
740 // or when "endl" is output (Borland 4.5)
741 //=========================================================================
742 // Class declaration using multiple inheritance doesn't work properly for
743 // Borland. See note in wb_text.h.
744 #ifndef NO_TEXT_WINDOW_STREAM
745 int wxTextCtrl::overflow(int c
)
747 // Make sure there is a holding area
748 // this is not needed in <iostream> usage as it automagically allocates
749 // it, but does someone want to emulate it for safety's sake?
751 if ( allocate()==EOF
)
753 wxError("Streambuf allocation failed","Internal error");
758 // Verify that there are no characters in get area
759 if ( gptr() && gptr() < egptr() )
761 wxError("Who's trespassing my get area?","Internal error");
768 // Make sure there is a put area
771 /* This doesn't seem to be fatal so comment out error message */
772 // wxError("Put area not opened","Internal error");
775 setp( base(), base() );
777 setp( pbase(), pbase() );
781 // Determine how many characters have been inserted but no consumed
782 int plen
= pptr() - pbase();
784 // Now Jerry relies on the fact that the buffer is at least 2 chars
785 // long, but the holding area "may be as small as 1" ???
786 // And we need an additional \0, so let's keep this inefficient but
789 // If c!=EOF, it is a character that must also be comsumed
790 int xtra
= c
==EOF
? 0 : 1;
792 // Write temporary C-string to wxTextWindow
794 char *txt
= new char[plen
+xtra
+1];
795 memcpy(txt
, pbase(), plen
);
796 txt
[plen
] = (char)c
; // append c
797 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
798 // If the put area already contained \0, output will be truncated there
804 setp(pbase(), epptr());
806 #if defined(__WATCOMC__)
808 #elif defined(zapeof) // HP-UX (all cfront based?)
811 return c
!=EOF
? c
: 0; // this should make everybody happy
815 int len = pptr() - pbase();
816 char *txt = new char[len+1];
817 strncpy(txt, pbase(), len);
820 setp(pbase(), epptr());
826 //=========================================================================
827 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
828 //=========================================================================
829 int wxTextCtrl::sync(void)
831 // Verify that there are no characters in get area
832 if ( gptr() && gptr() < egptr() )
834 wxError("Who's trespassing my get area?","Internal error");
838 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
842 int len = pptr() - pbase();
843 char *txt = new char[len+1];
844 strncpy(txt, pbase(), len);
847 setp(pbase(), epptr());
853 //=========================================================================
854 // Should not be called by a "ostream". Used by a "istream"
855 //=========================================================================
856 int wxTextCtrl::underflow(void)
862 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
868 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
871 str
.Printf("%.2f", f
);
876 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
879 str
.Printf("%.2f", d
);
884 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
892 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
895 str
.Printf("%ld", i
);
900 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
910 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
911 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
916 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
917 return (WXHBRUSH
) hbrush
;
921 if (GetParent()->GetTransparentBackground())
922 SetBkMode((HDC
) pDC
, TRANSPARENT
);
924 SetBkMode((HDC
) pDC
, OPAQUE
);
926 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
927 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
929 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
931 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
932 // has a zero usage count.
933 // NOT NOW - will be cleaned up at end of app.
934 // backgroundBrush->RealizeResource();
935 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
938 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
940 // Fix by Marcel Rasche to allow Alt-Ctrl insertion of special characters
941 switch(event
.KeyCode())
951 char c
=(char)event
.KeyCode();
956 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
958 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
959 event
.SetEventObject( this );
960 if ( GetEventHandler()->ProcessEvent(event
) )
963 else if ( event
.KeyCode() == WXK_TAB
) {
964 wxNavigationKeyEvent event
;
965 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
966 event
.SetWindowChange(FALSE
);
967 event
.SetEventObject(this);
969 if ( GetEventHandler()->ProcessEvent(event
) )
976 long wxTextCtrl::MSWGetDlgCode()
978 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
979 if ( m_windowStyle
& wxPROCESS_ENTER
)
980 lRc
|= DLGC_WANTMESSAGE
;
981 else if ( m_windowStyle
& wxTE_MULTILINE
)
982 lRc
|= DLGC_WANTMESSAGE
;
987 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
989 if ( m_windowStyle
& wxTE_MULTILINE
)
991 // No flicker - only problem is we probably can't change the background
995 ::GetClientRect((HWND) GetHWND(), &rect);
997 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
998 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1000 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1001 ::DeleteObject(hBrush);
1002 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1005 // wxWindow::OnEraseBackground(event);
1008 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1012 wxDebugMsg("Edit control %d: ", (int)id);
1016 wxDebugMsg("EN_SETFOCUS\n");
1019 wxDebugMsg("EN_KILLFOCUS\n");
1022 wxDebugMsg("EN_CHANGE\n");
1025 wxDebugMsg("EN_UPDATE\n");
1028 wxDebugMsg("EN_ERRSPACE\n");
1031 wxDebugMsg("EN_MAXTEXT\n");
1034 wxDebugMsg("EN_HSCROLL\n");
1037 wxDebugMsg("EN_VSCROLL\n");
1040 wxDebugMsg("Unknown EDIT notification\n");
1049 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1052 event
.SetEventObject( this );
1053 GetEventHandler()->ProcessEvent(event
);
1059 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1060 wxString
val(GetValue());
1061 if ( !val
.IsNull() )
1062 event
.m_commandString
= WXSTRINGCAST val
;
1063 event
.SetEventObject( this );
1064 ProcessCommand(event
);
1068 // the other notification messages are not processed
1083 // For Rich Edit controls. Do we need it?
1085 #if defined(__WIN95__)
1086 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1088 wxCommandEvent
event(0, m_windowId
);
1090 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1091 switch ( hdr1
->code
)
1093 // Insert case code here
1095 return wxControl::MSWNotify(wParam
, lParam
);
1099 event
.SetEventObject( this );
1100 event
.SetEventType(eventType
);
1102 if ( !GetEventHandler()->ProcessEvent(event
) )