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__)
62 #define farmalloc malloc
69 #if defined(__WIN95__) && !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
)
85 wxTextCtrl::wxTextCtrl(void)
86 #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();
126 WXHGLOBAL m_globalHandle
= 0;
128 // Obscure method from the MS Developer's Network Disk for
129 // using global memory instead of the local heap, which
130 // runs out far too soon. Solves the problem with
131 // failing to appear.
133 // Doesn't seem to work for Win95, so removing.
135 // if ((wxGetOsVersion() != wxWINDOWS_NT) && (wxGetOsVersion() != wxWIN95))
136 // m_globalHandle = (WXHGLOBAL) GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
140 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
141 if (m_windowStyle
& wxTE_MULTILINE
)
142 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
144 msStyle
|= ES_AUTOHSCROLL
;
146 if (m_windowStyle
& wxTE_READONLY
)
147 msStyle
|= ES_READONLY
;
149 if (m_windowStyle
& wxHSCROLL
)
150 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
151 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
152 msStyle
|= ES_PASSWORD
;
154 char *windowClass
= "EDIT";
155 #if defined(__WIN95__)
156 if ( m_windowStyle
& wxTE_MULTILINE
)
158 msStyle
|= ES_AUTOVSCROLL
;
160 windowClass
= "RichEdit" ;
167 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
169 // If we're in Win95, and we want a simple 2D border,
170 // then make it an EDIT control instead.
171 #if defined(__WIN95__)
172 if (m_windowStyle
& wxSIMPLE_BORDER
)
174 windowClass
= "EDIT";
179 // Even with extended styles, need to combine with WS_BORDER
180 // for them to look right.
181 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
182 msStyle
|= WS_BORDER
;
184 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, windowClass
, NULL
,
186 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
187 m_globalHandle
? (HINSTANCE
) m_globalHandle
: wxGetInstance(), NULL
);
189 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create text ctrl" );
194 Ctl3dSubclassCtl((HWND
)m_hWnd
);
199 #if defined(__WIN95__)
202 // Have to enable events
203 ::SendMessage((HWND
)m_hWnd
, EM_SETEVENTMASK
, 0,
204 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
208 SubclassWin(GetHWND());
210 if ( parent
->GetFont().Ok() && parent
->GetFont().Ok() )
212 SetFont(parent
->GetFont());
216 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
219 SetSize(x
, y
, width
, height
);
221 // Causes a crash for Symantec C++ and WIN32 for some reason
222 #if !(defined(__SC__) && defined(__WIN32__))
223 if ( !value
.IsEmpty() )
232 // Make sure the window style (etc.) reflects the HWND style (roughly)
233 void wxTextCtrl::AdoptAttributesFromHWND(void)
235 wxWindow::AdoptAttributesFromHWND();
237 HWND hWnd
= (HWND
) GetHWND();
238 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
243 GetClassName((HWND
) hWnd
, buf
, 256);
246 GetClassNameW((HWND
) hWnd
, buf
, 256);
248 GetClassNameA((HWND
) hWnd
, buf
, 256);
260 if (style
& ES_MULTILINE
)
261 m_windowStyle
|= wxTE_MULTILINE
;
262 if (style
& ES_PASSWORD
)
263 m_windowStyle
|= wxTE_PASSWORD
;
264 if (style
& ES_READONLY
)
265 m_windowStyle
|= wxTE_READONLY
;
266 if (style
& ES_WANTRETURN
)
267 m_windowStyle
|= wxTE_PROCESS_ENTER
;
270 void wxTextCtrl::SetupColours(void)
272 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
273 SetForegroundColour(GetParent()->GetForegroundColour());
276 wxString
wxTextCtrl::GetValue(void) const
278 int length
= GetWindowTextLength((HWND
) GetHWND());
279 char *s
= new char[length
+1];
280 GetWindowText((HWND
) GetHWND(), s
, length
+1);
286 void wxTextCtrl::SetValue(const wxString
& value
)
288 // If newlines are denoted by just 10, must stick 13 in front.
290 int len
= value
.Length();
292 for (i
= 0; i
< len
; i
++)
294 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
299 char *tmp
= new char[len
+ singletons
+ 1];
301 for (i
= 0; i
< len
; i
++)
303 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
312 SetWindowText((HWND
) GetHWND(), tmp
);
316 SetWindowText((HWND
) GetHWND(), (const char *)value
);
319 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
321 int currentX
, currentY
;
322 GetPosition(¤tX
, ¤tY
);
328 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
330 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
333 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
335 int cx
; // button font dimensions
338 wxGetCharSize(GetHWND(), &cx
, &cy
, & GetFont());
340 int control_width
, control_height
, control_x
, control_y
;
342 // If we're prepared to use the existing size, then...
343 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
348 // Deal with default size (using -1 values)
350 w1
= DEFAULT_ITEM_WIDTH
;
357 // Calculations may have made text size too small
358 if (control_height
<= 0)
359 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
361 if (control_width
<= 0)
362 control_width
= DEFAULT_ITEM_WIDTH
;
364 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
365 (int)control_width
, (int)control_height
, TRUE
);
368 // Clipboard operations
369 void wxTextCtrl::Copy(void)
371 HWND hWnd
= (HWND
) GetHWND();
372 SendMessage(hWnd
, WM_COPY
, 0, 0L);
375 void wxTextCtrl::Cut(void)
377 HWND hWnd
= (HWND
) GetHWND();
378 SendMessage(hWnd
, WM_CUT
, 0, 0L);
381 void wxTextCtrl::Paste(void)
383 HWND hWnd
= (HWND
) GetHWND();
384 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
387 void wxTextCtrl::SetEditable(bool editable
)
389 HWND hWnd
= (HWND
) GetHWND();
390 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
393 void wxTextCtrl::SetInsertionPoint(long pos
)
395 HWND hWnd
= (HWND
) GetHWND();
397 #if defined(__WIN95__)
403 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
404 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
409 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
410 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
413 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
416 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
419 void wxTextCtrl::SetInsertionPointEnd(void)
421 long pos
= GetLastPosition();
422 SetInsertionPoint(pos
);
425 long wxTextCtrl::GetInsertionPoint(void) const
427 #if defined(__WIN95__)
433 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
438 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
442 long wxTextCtrl::GetLastPosition(void) const
444 HWND hWnd
= (HWND
) GetHWND();
446 // Will always return a number > 0 (according to docs)
447 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
449 // This gets the char index for the _beginning_ of the last line
450 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
452 // Get number of characters in the last line. We'll add this to the character
453 // index for the last line, 1st position.
454 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
456 return (long)(charIndex
+ lineLength
);
459 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
461 HWND hWnd
= (HWND
) GetHWND();
462 long fromChar
= from
;
465 // Set selection and remove it
467 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
469 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
471 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
473 // Now replace with 'value', by pasting.
474 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
476 // Paste into edit control
477 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
480 void wxTextCtrl::Remove(long from
, long to
)
482 HWND hWnd
= (HWND
) GetHWND();
483 long fromChar
= from
;
486 // Cut all selected text
488 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
490 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
492 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
495 void wxTextCtrl::SetSelection(long from
, long to
)
497 HWND hWnd
= (HWND
) GetHWND();
498 long fromChar
= from
;
500 // if from and to are both -1, it means
501 // (in wxWindows) that all text should be selected.
502 // This translates into Windows convention
503 if ((from
== -1) && (to
== -1))
510 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
511 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
513 // WPARAM is 0: selection is scrolled into view
514 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
518 bool wxTextCtrl::LoadFile(const wxString
& file
)
520 if (!wxFileExists(WXSTRINGCAST file
))
527 // ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
528 ifstream
input(WXSTRINGCAST file
, ios::in
);
532 // Previously a SETSEL/REPLACESEL call-pair were done to insert
533 // line by line into the control. Apart from being very slow this
534 // was limited to 32K of text by the external interface presenting
535 // positions as signed shorts. Now load in one chunk...
536 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
538 struct stat stat_buf
;
539 if (stat(file
, &stat_buf
) < 0)
541 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
542 // This may need to be a bigger buffer than the file size suggests,
543 // if it's a UNIX file. Give it an extra 1000 just in case.
544 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
547 while (!input
.eof() && input
.peek() != EOF
)
549 input
.getline(wxBuffer
, 500);
550 int len
= strlen(wxBuffer
);
552 wxBuffer
[len
+1] = 10;
554 strcpy(tmp_buffer
+pos
, wxBuffer
);
555 pos
+= strlen(wxBuffer
);
559 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
560 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
561 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
569 // If file is null, try saved file name first
570 // Returns TRUE if succeeds.
571 bool wxTextCtrl::SaveFile(const wxString
& file
)
573 wxString
theFile(file
);
575 theFile
= m_fileName
;
578 m_fileName
= theFile
;
580 ofstream
output((char*) (const char*) theFile
);
584 // This will only save 64K max
585 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
586 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
587 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
588 char *pstr
= tmp_buffer
;
590 // Convert \r\n to just \n
599 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
604 void wxTextCtrl::WriteText(const wxString
& text
)
607 int len
= text
.Length();
608 char *newtext
= new char[(len
*2)+1];
618 newtext
[j
] = text
[i
];
623 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
627 void wxTextCtrl::Clear(void)
629 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
630 SetWindowText((HWND
) GetHWND(), "");
633 bool wxTextCtrl::IsModified(void) const
635 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
638 // Makes 'unmodified'
639 void wxTextCtrl::DiscardEdits(void)
641 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
645 * Some of the following functions are yet to be implemented
649 int wxTextCtrl::GetNumberOfLines(void) const
651 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
654 long wxTextCtrl::XYToPosition(long x
, long y
) const
656 HWND hWnd
= (HWND
) GetHWND();
658 // This gets the char index for the _beginning_ of this line
659 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
660 return (long)(x
+ charIndex
);
663 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
665 HWND hWnd
= (HWND
) GetHWND();
667 // This gets the line number containing the character
668 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
669 // This gets the char index for the _beginning_ of this line
670 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
671 // The X position must therefore be the different between pos and charIndex
672 *x
= (long)(pos
- charIndex
);
676 void wxTextCtrl::ShowPosition(long pos
)
678 HWND hWnd
= (HWND
) GetHWND();
680 // To scroll to a position, we pass the number of lines and characters
681 // to scroll *by*. This means that we need to:
682 // (1) Find the line position of the current line.
683 // (2) Find the line position of pos.
684 // (3) Scroll by (pos - current).
685 // For now, ignore the horizontal scrolling.
687 // Is this where scrolling is relative to - the line containing the caret?
688 // Or is the first visible line??? Try first visible line.
689 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
691 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
693 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
695 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
698 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
699 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
702 if (linesToScroll
!= 0)
703 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
706 int wxTextCtrl::GetLineLength(long lineNo
) const
708 long charIndex
= XYToPosition(0, lineNo
);
709 HWND hWnd
= (HWND
) GetHWND();
710 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
714 wxString
wxTextCtrl::GetLineText(long lineNo
) const
716 HWND hWnd
= (HWND
) GetHWND();
717 *(WORD
*)wxBuffer
= 512;
718 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
719 wxBuffer
[noChars
] = 0;
720 return wxString(wxBuffer
);
727 void wxTextCtrl::Command(wxCommandEvent
& event
)
729 SetValue (event
.GetString());
730 ProcessCommand (event
);
733 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
735 // By default, load the first file into the text window.
736 if (event
.GetNumberOfFiles() > 0)
738 LoadFile(event
.GetFiles()[0]);
742 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
743 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
745 //=========================================================================
746 // Called then the buffer is full (gcc 2.6.3)
747 // or when "endl" is output (Borland 4.5)
748 //=========================================================================
749 // Class declaration using multiple inheritance doesn't work properly for
750 // Borland. See note in textctrl.h.
751 #ifndef NO_TEXT_WINDOW_STREAM
752 int wxTextCtrl::overflow(int c
)
754 // Make sure there is a holding area
755 // this is not needed in <iostream> usage as it automagically allocates
756 // it, but does someone want to emulate it for safety's sake?
758 if ( allocate()==EOF
)
760 wxLogError("Streambuf allocation failed");
765 // Verify that there are no characters in get area
766 if ( gptr() && gptr() < egptr() )
768 wxError("Who's trespassing my get area?","Internal error");
775 // Make sure there is a put area
778 /* This doesn't seem to be fatal so comment out error message */
779 // wxError("Put area not opened","Internal error");
782 setp( base(), base() );
784 setp( pbase(), pbase() );
788 // Determine how many characters have been inserted but no consumed
789 int plen
= pptr() - pbase();
791 // Now Jerry relies on the fact that the buffer is at least 2 chars
792 // long, but the holding area "may be as small as 1" ???
793 // And we need an additional \0, so let's keep this inefficient but
796 // If c!=EOF, it is a character that must also be comsumed
797 int xtra
= c
==EOF
? 0 : 1;
799 // Write temporary C-string to wxTextWindow
801 char *txt
= new char[plen
+xtra
+1];
802 memcpy(txt
, pbase(), plen
);
803 txt
[plen
] = (char)c
; // append c
804 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
805 // If the put area already contained \0, output will be truncated there
811 setp(pbase(), epptr());
813 #if defined(__WATCOMC__)
815 #elif defined(zapeof) // HP-UX (all cfront based?)
818 return c
!=EOF
? c
: 0; // this should make everybody happy
822 int len = pptr() - pbase();
823 char *txt = new char[len+1];
824 strncpy(txt, pbase(), len);
827 setp(pbase(), epptr());
833 //=========================================================================
834 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
835 //=========================================================================
836 int wxTextCtrl::sync(void)
838 // Verify that there are no characters in get area
839 if ( gptr() && gptr() < egptr() )
841 wxError("Who's trespassing my get area?","Internal error");
845 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
849 int len = pptr() - pbase();
850 char *txt = new char[len+1];
851 strncpy(txt, pbase(), len);
854 setp(pbase(), epptr());
860 //=========================================================================
861 // Should not be called by a "ostream". Used by a "istream"
862 //=========================================================================
863 int wxTextCtrl::underflow(void)
869 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
875 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
878 str
.Printf("%.2f", f
);
883 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
886 str
.Printf("%.2f", d
);
891 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
899 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
902 str
.Printf("%ld", i
);
907 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
917 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
918 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
923 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
924 return (WXHBRUSH
) hbrush
;
928 if (GetParent()->GetTransparentBackground())
929 SetBkMode((HDC
) pDC
, TRANSPARENT
);
931 SetBkMode((HDC
) pDC
, OPAQUE
);
933 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
934 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
936 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
938 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
939 // has a zero usage count.
940 // NOT NOW - will be cleaned up at end of app.
941 // backgroundBrush->RealizeResource();
942 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
945 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
947 // Fix by Marcel Rasche to allow Alt-Ctrl insertion of special characters
948 switch(event
.KeyCode())
958 char c
=(char)event
.KeyCode();
963 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
965 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
966 event
.SetEventObject( this );
967 if ( GetEventHandler()->ProcessEvent(event
) )
970 else if ( event
.KeyCode() == WXK_TAB
) {
971 wxNavigationKeyEvent event
;
972 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
973 event
.SetWindowChange(FALSE
);
974 event
.SetEventObject(this);
976 if ( GetEventHandler()->ProcessEvent(event
) )
983 long wxTextCtrl::MSWGetDlgCode()
985 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
986 if ( m_windowStyle
& wxPROCESS_ENTER
)
987 lRc
|= DLGC_WANTMESSAGE
;
988 else if ( m_windowStyle
& wxTE_MULTILINE
)
989 lRc
|= DLGC_WANTMESSAGE
;
994 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
996 if ( m_windowStyle
& wxTE_MULTILINE
)
998 // No flicker - only problem is we probably can't change the background
1002 ::GetClientRect((HWND) GetHWND(), &rect);
1004 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1005 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1007 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1008 ::DeleteObject(hBrush);
1009 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1012 // wxWindow::OnEraseBackground(event);
1015 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1019 wxDebugMsg("Edit control %d: ", (int)id);
1023 wxDebugMsg("EN_SETFOCUS\n");
1026 wxDebugMsg("EN_KILLFOCUS\n");
1029 wxDebugMsg("EN_CHANGE\n");
1032 wxDebugMsg("EN_UPDATE\n");
1035 wxDebugMsg("EN_ERRSPACE\n");
1038 wxDebugMsg("EN_MAXTEXT\n");
1041 wxDebugMsg("EN_HSCROLL\n");
1044 wxDebugMsg("EN_VSCROLL\n");
1047 wxDebugMsg("Unknown EDIT notification\n");
1056 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1059 event
.SetEventObject( this );
1060 GetEventHandler()->ProcessEvent(event
);
1066 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1067 wxString
val(GetValue());
1068 if ( !val
.IsNull() )
1069 event
.m_commandString
= WXSTRINGCAST val
;
1070 event
.SetEventObject( this );
1071 ProcessCommand(event
);
1075 // the other notification messages are not processed
1090 // For Rich Edit controls. Do we need it?
1092 #if defined(__WIN95__)
1093 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1095 wxCommandEvent
event(0, m_windowId
);
1097 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1098 switch ( hdr1
->code
)
1100 // Insert case code here
1102 return wxControl::MSWNotify(wParam
, lParam
);
1106 event
.SetEventObject( this );
1107 event
.SetEventType(eventType
);
1109 if ( !GetEventHandler()->ProcessEvent(event
) )