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 wxUSE_RICHEDIT && !defined(__GNUWIN32__)
73 #if !USE_SHARED_LIBRARY
74 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
76 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
77 EVT_CHAR(wxTextCtrl::OnChar
)
78 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
79 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
81 #endif // USE_SHARED_LIBRARY
84 wxTextCtrl::wxTextCtrl()
85 #ifndef NO_TEXT_WINDOW_STREAM
94 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
95 const wxString
& value
,
97 const wxSize
& size
, long style
,
98 const wxValidator
& validator
,
103 SetValidator(validator
);
104 if (parent
) parent
->AddChild(this);
106 m_windowStyle
= style
;
108 // Should this be taken from the system colours?
109 // SetBackgroundColour(wxColour(255, 255, 255));
111 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
113 SetForegroundColour(parent
->GetForegroundColour()) ;
116 m_windowId
= (int)NewControlId();
125 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
126 if (m_windowStyle
& wxTE_MULTILINE
)
128 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
129 "wxTE_PROCESS_ENTER style is ignored for multiline controls" );
131 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
132 m_windowStyle
|= wxTE_PROCESS_ENTER
;
135 msStyle
|= ES_AUTOHSCROLL
;
137 if (m_windowStyle
& wxTE_READONLY
)
138 msStyle
|= ES_READONLY
;
140 if (m_windowStyle
& wxHSCROLL
)
141 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
142 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
143 msStyle
|= ES_PASSWORD
;
145 const char *windowClass
= "EDIT";
148 if ( m_windowStyle
& wxTE_MULTILINE
)
150 msStyle
|= ES_AUTOVSCROLL
;
152 windowClass
= "RichEdit" ;
159 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
161 // If we're in Win95, and we want a simple 2D border,
162 // then make it an EDIT control instead.
164 if (m_windowStyle
& wxSIMPLE_BORDER
)
166 windowClass
= "EDIT";
171 // Even with extended styles, need to combine with WS_BORDER
172 // for them to look right.
173 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
174 msStyle
|= WS_BORDER
;
176 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, windowClass
, NULL
,
178 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
179 wxGetInstance(), NULL
);
181 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create text ctrl" );
186 Ctl3dSubclassCtl((HWND
)m_hWnd
);
194 // Have to enable events
195 ::SendMessage((HWND
)m_hWnd
, EM_SETEVENTMASK
, 0,
196 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
200 SubclassWin(GetHWND());
202 if ( parent
->GetFont().Ok() && parent
->GetFont().Ok() )
204 SetFont(parent
->GetFont());
208 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
211 SetSize(x
, y
, width
, height
);
213 // Causes a crash for Symantec C++ and WIN32 for some reason
214 #if !(defined(__SC__) && defined(__WIN32__))
215 if ( !value
.IsEmpty() )
224 // Make sure the window style (etc.) reflects the HWND style (roughly)
225 void wxTextCtrl::AdoptAttributesFromHWND()
227 wxWindow::AdoptAttributesFromHWND();
229 HWND hWnd
= (HWND
) GetHWND();
230 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
232 // retrieve the style to see whether this is an edit or richedit ctrl
237 GetClassName((HWND
) hWnd
, buf
, 256);
240 GetClassNameW((HWND
) hWnd
, buf
, 256);
243 GetClassName((HWND
) hWnd
, buf
, 256);
245 GetClassNameA((HWND
) hWnd
, buf
, 256);
259 if (style
& ES_MULTILINE
)
260 m_windowStyle
|= wxTE_MULTILINE
;
261 if (style
& ES_PASSWORD
)
262 m_windowStyle
|= wxTE_PASSWORD
;
263 if (style
& ES_READONLY
)
264 m_windowStyle
|= wxTE_READONLY
;
265 if (style
& ES_WANTRETURN
)
266 m_windowStyle
|= wxTE_PROCESS_ENTER
;
269 void wxTextCtrl::SetupColours()
271 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
272 SetForegroundColour(GetParent()->GetForegroundColour());
275 wxString
wxTextCtrl::GetValue() const
277 int length
= GetWindowTextLength((HWND
) GetHWND());
278 char *s
= new char[length
+1];
279 GetWindowText((HWND
) GetHWND(), s
, length
+1);
285 void wxTextCtrl::SetValue(const wxString
& value
)
287 // If newlines are denoted by just 10, must stick 13 in front.
289 int len
= value
.Length();
291 for (i
= 0; i
< len
; i
++)
293 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
298 char *tmp
= new char[len
+ singletons
+ 1];
300 for (i
= 0; i
< len
; i
++)
302 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
311 SetWindowText((HWND
) GetHWND(), tmp
);
315 SetWindowText((HWND
) GetHWND(), (const char *)value
);
318 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
320 int currentX
, currentY
;
321 GetPosition(¤tX
, ¤tY
);
327 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
329 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
332 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
334 int cx
; // button font dimensions
337 wxGetCharSize(GetHWND(), &cx
, &cy
, & this->GetFont());
339 int control_width
, control_height
, control_x
, control_y
;
341 // If we're prepared to use the existing size, then...
342 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
347 // Deal with default size (using -1 values)
349 w1
= DEFAULT_ITEM_WIDTH
;
356 // Calculations may have made text size too small
357 if (control_height
<= 0)
358 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
360 if (control_width
<= 0)
361 control_width
= DEFAULT_ITEM_WIDTH
;
363 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
364 (int)control_width
, (int)control_height
, TRUE
);
367 // Clipboard operations
368 void wxTextCtrl::Copy()
370 HWND hWnd
= (HWND
) GetHWND();
371 SendMessage(hWnd
, WM_COPY
, 0, 0L);
374 void wxTextCtrl::Cut()
376 HWND hWnd
= (HWND
) GetHWND();
377 SendMessage(hWnd
, WM_CUT
, 0, 0L);
380 void wxTextCtrl::Paste()
382 HWND hWnd
= (HWND
) GetHWND();
383 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
386 void wxTextCtrl::SetEditable(bool editable
)
388 HWND hWnd
= (HWND
) GetHWND();
389 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
392 void wxTextCtrl::SetInsertionPoint(long pos
)
394 HWND hWnd
= (HWND
) GetHWND();
402 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
403 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
408 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
409 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
412 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
415 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
418 void wxTextCtrl::SetInsertionPointEnd()
420 long pos
= GetLastPosition();
421 SetInsertionPoint(pos
);
424 long wxTextCtrl::GetInsertionPoint() const
432 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
437 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
441 long wxTextCtrl::GetLastPosition() const
443 HWND hWnd
= (HWND
) GetHWND();
445 // Will always return a number > 0 (according to docs)
446 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
448 // This gets the char index for the _beginning_ of the last line
449 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
451 // Get number of characters in the last line. We'll add this to the character
452 // index for the last line, 1st position.
453 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
455 return (long)(charIndex
+ lineLength
);
458 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
460 HWND hWnd
= (HWND
) GetHWND();
461 long fromChar
= from
;
464 // Set selection and remove it
466 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
468 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
470 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
472 // Now replace with 'value', by pasting.
473 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
475 // Paste into edit control
476 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
479 void wxTextCtrl::Remove(long from
, long to
)
481 HWND hWnd
= (HWND
) GetHWND();
482 long fromChar
= from
;
485 // Cut all selected text
487 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
489 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
491 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
494 void wxTextCtrl::SetSelection(long from
, long to
)
496 HWND hWnd
= (HWND
) GetHWND();
497 long fromChar
= from
;
499 // if from and to are both -1, it means
500 // (in wxWindows) that all text should be selected.
501 // This translates into Windows convention
502 if ((from
== -1) && (to
== -1))
509 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
510 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
512 // WPARAM is 0: selection is scrolled into view
513 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
517 bool wxTextCtrl::LoadFile(const wxString
& file
)
519 if (!wxFileExists(WXSTRINGCAST file
))
526 // ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
527 ifstream
input(WXSTRINGCAST file
, ios::in
);
531 // Previously a SETSEL/REPLACESEL call-pair were done to insert
532 // line by line into the control. Apart from being very slow this
533 // was limited to 32K of text by the external interface presenting
534 // positions as signed shorts. Now load in one chunk...
535 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
538 struct _stat stat_buf
;
539 if (stat((char*) (const char*) file
, &stat_buf
) < 0)
542 struct stat stat_buf
;
543 if (stat(file
, &stat_buf
) < 0)
547 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
548 // This may need to be a bigger buffer than the file size suggests,
549 // if it's a UNIX file. Give it an extra 1000 just in case.
550 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
553 while (!input
.eof() && input
.peek() != EOF
)
555 input
.getline(wxBuffer
, 500);
556 int len
= strlen(wxBuffer
);
558 wxBuffer
[len
+1] = 10;
560 strcpy(tmp_buffer
+pos
, wxBuffer
);
561 pos
+= strlen(wxBuffer
);
565 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
566 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
567 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
575 // If file is null, try saved file name first
576 // Returns TRUE if succeeds.
577 bool wxTextCtrl::SaveFile(const wxString
& file
)
579 wxString
theFile(file
);
582 theFile
= m_fileName
;
587 m_fileName
= theFile
;
589 ofstream
output((char*) (const char*) theFile
);
593 // This will only save 64K max
594 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
595 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
596 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
597 char *pstr
= tmp_buffer
;
599 // Convert \r\n to just \n
608 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
613 void wxTextCtrl::WriteText(const wxString
& text
)
616 int len
= text
.Length();
617 char *newtext
= new char[(len
*2)+1];
627 newtext
[j
] = text
[i
];
632 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
636 void wxTextCtrl::AppendText(const wxString
& text
)
638 SetInsertionPointEnd();
642 void wxTextCtrl::Clear()
644 SetWindowText((HWND
) GetHWND(), "");
647 bool wxTextCtrl::IsModified() const
649 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
652 // Makes 'unmodified'
653 void wxTextCtrl::DiscardEdits()
655 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
659 * Some of the following functions are yet to be implemented
663 int wxTextCtrl::GetNumberOfLines() const
665 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
668 long wxTextCtrl::XYToPosition(long x
, long y
) const
670 HWND hWnd
= (HWND
) GetHWND();
672 // This gets the char index for the _beginning_ of this line
673 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
674 return (long)(x
+ charIndex
);
677 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
679 HWND hWnd
= (HWND
) GetHWND();
681 // This gets the line number containing the character
682 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
683 // This gets the char index for the _beginning_ of this line
684 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
685 // The X position must therefore be the different between pos and charIndex
686 *x
= (long)(pos
- charIndex
);
690 void wxTextCtrl::ShowPosition(long pos
)
692 HWND hWnd
= (HWND
) GetHWND();
694 // To scroll to a position, we pass the number of lines and characters
695 // to scroll *by*. This means that we need to:
696 // (1) Find the line position of the current line.
697 // (2) Find the line position of pos.
698 // (3) Scroll by (pos - current).
699 // For now, ignore the horizontal scrolling.
701 // Is this where scrolling is relative to - the line containing the caret?
702 // Or is the first visible line??? Try first visible line.
703 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
705 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
707 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
709 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
712 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
713 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
716 if (linesToScroll
!= 0)
717 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
720 int wxTextCtrl::GetLineLength(long lineNo
) const
722 long charIndex
= XYToPosition(0, lineNo
);
723 HWND hWnd
= (HWND
) GetHWND();
724 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
728 wxString
wxTextCtrl::GetLineText(long lineNo
) const
730 HWND hWnd
= (HWND
) GetHWND();
731 *(WORD
*)wxBuffer
= 512;
732 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
733 wxBuffer
[noChars
] = 0;
734 return wxString(wxBuffer
);
741 void wxTextCtrl::Command(wxCommandEvent
& event
)
743 SetValue (event
.GetString());
744 ProcessCommand (event
);
747 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
749 // By default, load the first file into the text window.
750 if (event
.GetNumberOfFiles() > 0)
752 LoadFile(event
.GetFiles()[0]);
756 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
757 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
759 //=========================================================================
760 // Called then the buffer is full (gcc 2.6.3)
761 // or when "endl" is output (Borland 4.5)
762 //=========================================================================
763 // Class declaration using multiple inheritance doesn't work properly for
764 // Borland. See note in textctrl.h.
765 #ifndef NO_TEXT_WINDOW_STREAM
766 int wxTextCtrl::overflow(int c
)
768 // Make sure there is a holding area
769 // this is not needed in <iostream> usage as it automagically allocates
770 // it, but does someone want to emulate it for safety's sake?
772 if ( allocate()==EOF
)
774 wxLogError("Streambuf allocation failed");
779 // Verify that there are no characters in get area
780 if ( gptr() && gptr() < egptr() )
782 wxError("Who's trespassing my get area?","Internal error");
789 // Make sure there is a put area
792 /* This doesn't seem to be fatal so comment out error message */
793 // wxError("Put area not opened","Internal error");
796 setp( base(), base() );
798 setp( pbase(), pbase() );
802 // Determine how many characters have been inserted but no consumed
803 int plen
= pptr() - pbase();
805 // Now Jerry relies on the fact that the buffer is at least 2 chars
806 // long, but the holding area "may be as small as 1" ???
807 // And we need an additional \0, so let's keep this inefficient but
810 // If c!=EOF, it is a character that must also be comsumed
811 int xtra
= c
==EOF
? 0 : 1;
813 // Write temporary C-string to wxTextWindow
815 char *txt
= new char[plen
+xtra
+1];
816 memcpy(txt
, pbase(), plen
);
817 txt
[plen
] = (char)c
; // append c
818 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
819 // If the put area already contained \0, output will be truncated there
825 setp(pbase(), epptr());
827 #if defined(__WATCOMC__)
829 #elif defined(zapeof) // HP-UX (all cfront based?)
832 return c
!=EOF
? c
: 0; // this should make everybody happy
836 int len = pptr() - pbase();
837 char *txt = new char[len+1];
838 strncpy(txt, pbase(), len);
841 setp(pbase(), epptr());
847 //=========================================================================
848 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
849 //=========================================================================
850 int wxTextCtrl::sync()
852 // Verify that there are no characters in get area
853 if ( gptr() && gptr() < egptr() )
855 wxError("Who's trespassing my get area?","Internal error");
859 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
863 int len = pptr() - pbase();
864 char *txt = new char[len+1];
865 strncpy(txt, pbase(), len);
868 setp(pbase(), epptr());
874 //=========================================================================
875 // Should not be called by a "ostream". Used by a "istream"
876 //=========================================================================
877 int wxTextCtrl::underflow()
883 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
889 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
892 str
.Printf("%.2f", f
);
897 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
900 str
.Printf("%.2f", d
);
905 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
913 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
916 str
.Printf("%ld", i
);
921 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
931 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
932 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
937 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
938 return (WXHBRUSH
) hbrush
;
942 if (GetParent()->GetTransparentBackground())
943 SetBkMode((HDC
) pDC
, TRANSPARENT
);
945 SetBkMode((HDC
) pDC
, OPAQUE
);
947 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
948 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
950 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
952 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
953 // has a zero usage count.
954 // NOT NOW - will be cleaned up at end of app.
955 // backgroundBrush->RealizeResource();
956 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
959 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
961 switch( event
.KeyCode() )
963 // Fix by Marcel Rasche to allow Alt-Ctrl insertion of special characters
972 char c
= (char)event
.KeyCode();
978 wxASSERT_MSG( m_windowStyle
& wxTE_PROCESS_ENTER
,
979 "this text ctrl should never receive return" );
980 if ( m_windowStyle
& wxTE_MULTILINE
== 0 )
982 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
983 event
.SetEventObject( this );
984 if ( GetEventHandler()->ProcessEvent(event
) )
987 //else: multiline controls need Enter for themselves
992 // only produce navigation event if we don't process TAB ourself or
993 // if it's a Shift-Tab keypress (we assume nobody will ever need
994 // this key combo for himself)
996 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
997 // handled by Windows
998 if ( event
.ShiftDown() || !(m_windowStyle
& wxTE_PROCESS_TAB
) )
1000 wxNavigationKeyEvent eventNav
;
1001 eventNav
.SetDirection(!event
.ShiftDown());
1002 eventNav
.SetWindowChange(FALSE
);
1003 eventNav
.SetEventObject(this);
1005 if ( GetEventHandler()->ProcessEvent(eventNav
) )
1010 // don't just call event.Skip() because this will cause TABs and ENTERs
1011 // be passed upwards and we don't always want this - instead process it
1016 long wxTextCtrl::MSWGetDlgCode()
1018 // we always want the characters and the arrows
1019 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
1021 // we may have several different cases:
1022 // 1. normal case: both TAB and ENTER are used for dialog navigation
1023 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
1024 // control in the dialog
1025 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
1026 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
1028 if ( m_windowStyle
& wxTE_PROCESS_ENTER
)
1029 lRc
|= DLGC_WANTMESSAGE
;
1030 if ( m_windowStyle
& wxTE_PROCESS_TAB
)
1031 lRc
|= DLGC_WANTTAB
;
1036 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
1038 if ( m_windowStyle
& wxTE_MULTILINE
)
1040 // No flicker - only problem is we probably can't change the background
1044 ::GetClientRect((HWND) GetHWND(), &rect);
1046 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1047 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1049 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1050 ::DeleteObject(hBrush);
1051 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1054 // wxWindow::OnEraseBackground(event);
1057 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1061 wxDebugMsg("Edit control %d: ", (int)id);
1065 wxDebugMsg("EN_SETFOCUS\n");
1068 wxDebugMsg("EN_KILLFOCUS\n");
1071 wxDebugMsg("EN_CHANGE\n");
1074 wxDebugMsg("EN_UPDATE\n");
1077 wxDebugMsg("EN_ERRSPACE\n");
1080 wxDebugMsg("EN_MAXTEXT\n");
1083 wxDebugMsg("EN_HSCROLL\n");
1086 wxDebugMsg("EN_VSCROLL\n");
1089 wxDebugMsg("Unknown EDIT notification\n");
1098 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1101 event
.SetEventObject( this );
1102 GetEventHandler()->ProcessEvent(event
);
1108 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1109 wxString
val(GetValue());
1110 if ( !val
.IsNull() )
1111 event
.m_commandString
= WXSTRINGCAST val
;
1112 event
.SetEventObject( this );
1113 ProcessCommand(event
);
1117 // the other notification messages are not processed
1132 // For Rich Edit controls. Do we need it?
1135 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1137 wxCommandEvent
event(0, m_windowId
);
1139 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1140 switch ( hdr1
->code
)
1142 // Insert case code here
1144 return wxControl::MSWNotify(wParam
, lParam
);
1148 event
.SetEventObject( this );
1149 event
.SetEventType(eventType
);
1151 if ( !GetEventHandler()->ProcessEvent(event
) )