1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textctrl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/textctrl.h"
25 #include "wx/settings.h"
30 #include "wx/clipbrd.h"
33 #include "wx/msw/private.h"
39 #include <sys/types.h>
41 #if defined(__BORLANDC__) && !defined(__WIN32__)
47 #define farmalloc malloc
54 #if defined(__WIN95__) && !defined(__GNUWIN32__)
58 #if !USE_SHARED_LIBRARY
59 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
61 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
62 EVT_CHAR(wxTextCtrl::OnChar
)
63 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
64 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
70 wxTextCtrl::wxTextCtrl(void)
71 #ifndef NO_TEXT_WINDOW_STREAM
79 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
80 const wxString
& value
,
82 const wxSize
& size
, long style
,
83 const wxValidator
& validator
,
88 SetValidator(validator
);
89 if (parent
) parent
->AddChild(this);
91 m_windowStyle
= style
;
93 // Should this be taken from the system colours?
94 // SetBackgroundColour(wxColour(255, 255, 255));
96 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
98 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
101 m_windowId
= (int)NewControlId();
111 WXHGLOBAL m_globalHandle
= 0;
113 // Obscure method from the MS Developer's Network Disk for
114 // using global memory instead of the local heap, which
115 // runs out far too soon. Solves the problem with
116 // failing to appear.
118 // Doesn't seem to work for Win95, so removing.
120 // if ((wxGetOsVersion() != wxWINDOWS_NT) && (wxGetOsVersion() != wxWIN95))
121 // m_globalHandle = (WXHGLOBAL) GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
124 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
125 if (m_windowStyle
& wxTE_MULTILINE
)
126 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
128 msStyle
|= ES_AUTOHSCROLL
;
130 if (m_windowStyle
& wxTE_READONLY
)
131 msStyle
|= ES_READONLY
;
133 if (m_windowStyle
& wxHSCROLL
)
134 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
135 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
136 msStyle
|= ES_PASSWORD
;
138 char *windowClass
= "EDIT";
139 #if defined(__WIN95__)
140 if ( m_windowStyle
& wxTE_MULTILINE
)
145 msStyle
|= ES_AUTOVSCROLL
;
147 windowClass
= "RichEdit" ;
153 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
155 // If we're in Win95, and we want a simple 2D border,
156 // then make it an EDIT control instead.
157 #if defined(__WIN95__)
158 if (m_windowStyle
& wxSIMPLE_BORDER
)
160 windowClass
= "EDIT";
165 // Even with extended styles, need to combine with WS_BORDER
166 // for them to look right.
167 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
168 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
169 msStyle
|= WS_BORDER
;
171 HWND edit
= CreateWindowEx(exStyle
, windowClass
, NULL
,
173 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
174 m_globalHandle
? (HINSTANCE
) m_globalHandle
: wxGetInstance(), NULL
);
179 Ctl3dSubclassCtl(edit
);
184 m_hWnd
= (WXHWND
)edit
;
186 #if defined(__WIN95__)
189 // Have to enable events
190 ::SendMessage(edit
, EM_SETEVENTMASK
, 0, ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
194 SubclassWin(GetHWND());
196 if ( parent
->GetFont() && parent
->GetFont()->Ok() )
198 SetFont(* parent
->GetFont());
202 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
205 SetSize(x
, y
, width
, height
);
207 // Causes a crash for Symantec C++ and WIN32 for some reason
208 #if !(defined(__SC__) && defined(__WIN32__))
210 SetWindowText(edit
, (const char *)value
);
216 // Make sure the window style (etc.) reflects the HWND style (roughly)
217 void wxTextCtrl::AdoptAttributesFromHWND(void)
219 wxWindow::AdoptAttributesFromHWND();
221 HWND hWnd
= (HWND
) GetHWND();
222 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
227 GetClassName((HWND
) hWnd
, buf
, 256);
230 GetClassNameW((HWND
) hWnd
, buf
, 256);
232 GetClassNameA((HWND
) hWnd
, buf
, 256);
244 if (style
& ES_MULTILINE
)
245 m_windowStyle
|= wxTE_MULTILINE
;
246 if (style
& ES_PASSWORD
)
247 m_windowStyle
|= wxTE_PASSWORD
;
248 if (style
& ES_READONLY
)
249 m_windowStyle
|= wxTE_READONLY
;
250 if (style
& ES_WANTRETURN
)
251 m_windowStyle
|= wxTE_PROCESS_ENTER
;
254 void wxTextCtrl::SetupColours(void)
256 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
257 SetForegroundColour(GetParent()->GetDefaultForegroundColour());
260 wxString
wxTextCtrl::GetValue(void) const
262 int length
= GetWindowTextLength((HWND
) GetHWND());
263 char *s
= new char[length
+1];
264 GetWindowText((HWND
) GetHWND(), s
, length
+1);
270 void wxTextCtrl::SetValue(const wxString
& value
)
272 // If newlines are denoted by just 10, must stick 13 in front.
274 int len
= value
.Length();
276 for (i
= 0; i
< len
; i
++)
278 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
283 char *tmp
= new char[len
+ singletons
+ 1];
285 for (i
= 0; i
< len
; i
++)
287 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
296 SetWindowText((HWND
) GetHWND(), tmp
);
300 SetWindowText((HWND
) GetHWND(), (const char *)value
);
303 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
305 int currentX
, currentY
;
306 GetPosition(¤tX
, ¤tY
);
312 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
314 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
317 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
319 int cx
; // button font dimensions
322 wxGetCharSize(GetHWND(), &cx
, &cy
,GetFont());
324 int control_width
, control_height
, control_x
, control_y
;
326 // If we're prepared to use the existing size, then...
327 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
332 // Deal with default size (using -1 values)
334 w1
= DEFAULT_ITEM_WIDTH
;
341 // Calculations may have made text size too small
342 if (control_height
<= 0)
343 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
345 if (control_width
<= 0)
346 control_width
= DEFAULT_ITEM_WIDTH
;
348 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
349 (int)control_width
, (int)control_height
, TRUE
);
352 // Clipboard operations
353 void wxTextCtrl::Copy(void)
355 HWND hWnd
= (HWND
) GetHWND();
356 SendMessage(hWnd
, WM_COPY
, 0, 0L);
359 void wxTextCtrl::Cut(void)
361 HWND hWnd
= (HWND
) GetHWND();
362 SendMessage(hWnd
, WM_CUT
, 0, 0L);
365 void wxTextCtrl::Paste(void)
367 HWND hWnd
= (HWND
) GetHWND();
368 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
371 void wxTextCtrl::SetEditable(bool editable
)
373 HWND hWnd
= (HWND
) GetHWND();
374 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
377 void wxTextCtrl::SetInsertionPoint(long pos
)
379 HWND hWnd
= (HWND
) GetHWND();
381 #if defined(__WIN95__)
387 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
388 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
393 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
394 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
397 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
400 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
403 void wxTextCtrl::SetInsertionPointEnd(void)
405 long pos
= GetLastPosition();
406 SetInsertionPoint(pos
);
409 long wxTextCtrl::GetInsertionPoint(void) const
411 #if defined(__WIN95__)
417 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
422 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
426 long wxTextCtrl::GetLastPosition(void) const
428 HWND hWnd
= (HWND
) GetHWND();
430 // Will always return a number > 0 (according to docs)
431 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
433 // This gets the char index for the _beginning_ of the last line
434 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
436 // Get number of characters in the last line. We'll add this to the character
437 // index for the last line, 1st position.
438 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
440 return (long)(charIndex
+ lineLength
);
443 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
445 HWND hWnd
= (HWND
) GetHWND();
446 long fromChar
= from
;
449 // Set selection and remove it
451 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
453 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
455 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
457 // Now replace with 'value', by pasting.
458 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
460 // Paste into edit control
461 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
464 void wxTextCtrl::Remove(long from
, long to
)
466 HWND hWnd
= (HWND
) GetHWND();
467 long fromChar
= from
;
470 // Cut all selected text
472 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
474 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
476 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
479 void wxTextCtrl::SetSelection(long from
, long to
)
481 HWND hWnd
= (HWND
) GetHWND();
482 long fromChar
= from
;
484 // if from and to are both -1, it means
485 // (in wxWindows) that all text should be selected.
486 // This translates into Windows convention
487 if ((from
== -1) && (to
== -1))
494 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
495 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
497 // WPARAM is 0: selection is scrolled into view
498 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
502 bool wxTextCtrl::LoadFile(const wxString
& file
)
504 if (!FileExists(WXSTRINGCAST file
))
511 ifstream
input(WXSTRINGCAST file
, ios::nocreate
| ios::in
);
515 // Previously a SETSEL/REPLACESEL call-pair were done to insert
516 // line by line into the control. Apart from being very slow this
517 // was limited to 32K of text by the external interface presenting
518 // positions as signed shorts. Now load in one chunk...
519 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
521 struct stat stat_buf
;
522 if (stat(file
, &stat_buf
) < 0)
524 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
525 // This may need to be a bigger buffer than the file size suggests,
526 // if it's a UNIX file. Give it an extra 1000 just in case.
527 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
530 while (!input
.eof() && input
.peek() != EOF
)
532 input
.getline(wxBuffer
, 500);
533 int len
= strlen(wxBuffer
);
535 wxBuffer
[len
+1] = 10;
537 strcpy(tmp_buffer
+pos
, wxBuffer
);
538 pos
+= strlen(wxBuffer
);
542 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
543 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
544 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
552 // If file is null, try saved file name first
553 // Returns TRUE if succeeds.
554 bool wxTextCtrl::SaveFile(const wxString
& file
)
556 wxString
theFile(file
);
558 theFile
= m_fileName
;
561 m_fileName
= theFile
;
563 ofstream
output((char*) (const char*) theFile
);
567 // This will only save 64K max
568 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
569 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
570 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
571 char *pstr
= tmp_buffer
;
573 // Convert \r\n to just \n
582 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
587 void wxTextCtrl::WriteText(const wxString
& text
)
590 int len
= text
.Length();
591 char *newtext
= new char[(len
*2)+1];
601 newtext
[j
] = text
[i
];
606 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
610 void wxTextCtrl::Clear(void)
612 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
613 SetWindowText((HWND
) GetHWND(), "");
616 bool wxTextCtrl::IsModified(void) const
618 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
621 // Makes 'unmodified'
622 void wxTextCtrl::DiscardEdits(void)
624 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
628 * Some of the following functions are yet to be implemented
632 int wxTextCtrl::GetNumberOfLines(void) const
634 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
637 long wxTextCtrl::XYToPosition(long x
, long y
) const
639 HWND hWnd
= (HWND
) GetHWND();
641 // This gets the char index for the _beginning_ of this line
642 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
643 return (long)(x
+ charIndex
);
646 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
648 HWND hWnd
= (HWND
) GetHWND();
650 // This gets the line number containing the character
651 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
652 // This gets the char index for the _beginning_ of this line
653 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
654 // The X position must therefore be the different between pos and charIndex
655 *x
= (long)(pos
- charIndex
);
659 void wxTextCtrl::ShowPosition(long pos
)
661 HWND hWnd
= (HWND
) GetHWND();
663 // To scroll to a position, we pass the number of lines and characters
664 // to scroll *by*. This means that we need to:
665 // (1) Find the line position of the current line.
666 // (2) Find the line position of pos.
667 // (3) Scroll by (pos - current).
668 // For now, ignore the horizontal scrolling.
670 // Is this where scrolling is relative to - the line containing the caret?
671 // Or is the first visible line??? Try first visible line.
672 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
674 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
676 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
678 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
681 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
682 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
685 if (linesToScroll
!= 0)
686 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
689 int wxTextCtrl::GetLineLength(long lineNo
) const
691 long charIndex
= XYToPosition(0, lineNo
);
692 HWND hWnd
= (HWND
) GetHWND();
693 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
697 wxString
wxTextCtrl::GetLineText(long lineNo
) const
699 HWND hWnd
= (HWND
) GetHWND();
700 *(WORD
*)wxBuffer
= 512;
701 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
702 wxBuffer
[noChars
] = 0;
703 return wxString(wxBuffer
);
710 void wxTextCtrl::Command(wxCommandEvent
& event
)
712 SetValue (event
.GetString());
713 ProcessCommand (event
);
716 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
718 // By default, load the first file into the text window.
719 if (event
.GetNumberOfFiles() > 0)
721 LoadFile(event
.GetFiles()[0]);
725 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
726 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
728 //=========================================================================
729 // Called then the buffer is full (gcc 2.6.3)
730 // or when "endl" is output (Borland 4.5)
731 //=========================================================================
732 // Class declaration using multiple inheritance doesn't work properly for
733 // Borland. See note in wb_text.h.
734 #ifndef NO_TEXT_WINDOW_STREAM
735 int wxTextCtrl::overflow(int c
)
737 // Make sure there is a holding area
738 if ( allocate()==EOF
)
740 wxError("Streambuf allocation failed","Internal error");
744 // Verify that there are no characters in get area
745 if ( gptr() && gptr() < egptr() )
747 wxError("Who's trespassing my get area?","Internal error");
754 // Make sure there is a put area
757 /* This doesn't seem to be fatal so comment out error message */
758 // wxError("Put area not opened","Internal error");
759 setp( base(), base() );
762 // Determine how many characters have been inserted but no consumed
763 int plen
= pptr() - pbase();
765 // Now Jerry relies on the fact that the buffer is at least 2 chars
766 // long, but the holding area "may be as small as 1" ???
767 // And we need an additional \0, so let's keep this inefficient but
770 // If c!=EOF, it is a character that must also be comsumed
771 int xtra
= c
==EOF
? 0 : 1;
773 // Write temporary C-string to wxTextWindow
775 char *txt
= new char[plen
+xtra
+1];
776 memcpy(txt
, pbase(), plen
);
777 txt
[plen
] = (char)c
; // append c
778 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
779 // If the put area already contained \0, output will be truncated there
785 setp(pbase(), epptr());
787 #if defined(__WATCOMC__)
789 #elif defined(zapeof) // HP-UX (all cfront based?)
792 return c
!=EOF
? c
: 0; // this should make everybody happy
796 int len = pptr() - pbase();
797 char *txt = new char[len+1];
798 strncpy(txt, pbase(), len);
801 setp(pbase(), epptr());
807 //=========================================================================
808 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
809 //=========================================================================
810 int wxTextCtrl::sync(void)
812 // Verify that there are no characters in get area
813 if ( gptr() && gptr() < egptr() )
815 wxError("Who's trespassing my get area?","Internal error");
819 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
823 int len = pptr() - pbase();
824 char *txt = new char[len+1];
825 strncpy(txt, pbase(), len);
828 setp(pbase(), epptr());
834 //=========================================================================
835 // Should not be called by a "ostream". Used by a "istream"
836 //=========================================================================
837 int wxTextCtrl::underflow(void)
843 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
849 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
852 str
.Printf("%.2f", f
);
857 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
860 str
.Printf("%.2f", d
);
865 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
873 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
876 str
.Printf("%ld", i
);
881 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
891 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
892 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
897 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
898 return (WXHBRUSH
) hbrush
;
902 if (GetParent()->GetTransparentBackground())
903 SetBkMode((HDC
) pDC
, TRANSPARENT
);
905 SetBkMode((HDC
) pDC
, OPAQUE
);
907 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
908 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
910 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
912 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
913 // has a zero usage count.
914 // NOT NOW - will be cleaned up at end of app.
915 // backgroundBrush->RealizeResource();
916 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
919 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
921 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
923 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
924 event
.SetEventObject( this );
925 if ( GetEventHandler()->ProcessEvent(event
) )
928 else if ( event
.KeyCode() == WXK_TAB
) {
929 wxNavigationKeyEvent event
;
930 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
931 event
.SetWindowChange(FALSE
);
932 event
.SetEventObject(this);
934 if ( GetEventHandler()->ProcessEvent(event
) )
941 long wxTextCtrl::MSWGetDlgCode()
943 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
944 if ( m_windowStyle
& wxPROCESS_ENTER
)
945 lRc
|= DLGC_WANTMESSAGE
;
946 else if ( m_windowStyle
& wxTE_MULTILINE
)
947 lRc
|= DLGC_WANTMESSAGE
;
952 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
954 if ( m_windowStyle
& wxTE_MULTILINE
)
956 // No flicker - only problem is we probably can't change the background
960 ::GetClientRect((HWND) GetHWND(), &rect);
962 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
963 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
965 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
966 ::DeleteObject(hBrush);
967 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
970 // wxWindow::OnEraseBackground(event);
973 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
977 wxDebugMsg("Edit control %d: ", (int)id);
981 wxDebugMsg("EN_SETFOCUS\n");
984 wxDebugMsg("EN_KILLFOCUS\n");
987 wxDebugMsg("EN_CHANGE\n");
990 wxDebugMsg("EN_UPDATE\n");
993 wxDebugMsg("EN_ERRSPACE\n");
996 wxDebugMsg("EN_MAXTEXT\n");
999 wxDebugMsg("EN_HSCROLL\n");
1002 wxDebugMsg("EN_VSCROLL\n");
1005 wxDebugMsg("Unknown EDIT notification\n");
1014 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1017 event
.SetEventObject( this );
1018 ProcessEvent(event
);
1024 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1025 wxString
val(GetValue());
1026 if ( !val
.IsNull() )
1027 event
.m_commandString
= WXSTRINGCAST val
;
1028 event
.SetEventObject( this );
1029 ProcessCommand(event
);
1033 // the other notification messages are not processed
1048 // For Rich Edit controls. Do we need it?
1050 #if defined(__WIN95__)
1051 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1053 wxCommandEvent
event(0, m_windowId
);
1055 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1056 switch ( hdr1
->code
)
1058 // Insert case code here
1060 return wxControl::MSWNotify(wParam
, lParam
);
1064 event
.SetEventObject( this );
1065 event
.SetEventType(eventType
);
1067 if ( !ProcessEvent(event
) )