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>
53 #if defined(__BORLANDC__) && !defined(__WIN32__)
59 #define farmalloc malloc
66 #if defined(__WIN95__) && !defined(__GNUWIN32__)
70 #if !USE_SHARED_LIBRARY
71 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
73 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
74 EVT_CHAR(wxTextCtrl::OnChar
)
75 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
76 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground
)
82 wxTextCtrl::wxTextCtrl(void)
83 #ifndef NO_TEXT_WINDOW_STREAM
91 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
92 const wxString
& value
,
94 const wxSize
& size
, long style
,
95 const wxValidator
& validator
,
100 SetValidator(validator
);
101 if (parent
) parent
->AddChild(this);
103 m_windowStyle
= style
;
105 // Should this be taken from the system colours?
106 // SetBackgroundColour(wxColour(255, 255, 255));
108 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
110 SetForegroundColour(parent
->GetForegroundColour()) ;
113 m_windowId
= (int)NewControlId();
123 WXHGLOBAL m_globalHandle
= 0;
125 // Obscure method from the MS Developer's Network Disk for
126 // using global memory instead of the local heap, which
127 // runs out far too soon. Solves the problem with
128 // failing to appear.
130 // Doesn't seem to work for Win95, so removing.
132 // if ((wxGetOsVersion() != wxWINDOWS_NT) && (wxGetOsVersion() != wxWIN95))
133 // m_globalHandle = (WXHGLOBAL) GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
137 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
138 if (m_windowStyle
& wxTE_MULTILINE
)
139 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
141 msStyle
|= ES_AUTOHSCROLL
;
143 if (m_windowStyle
& wxTE_READONLY
)
144 msStyle
|= ES_READONLY
;
146 if (m_windowStyle
& wxHSCROLL
)
147 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
148 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
149 msStyle
|= ES_PASSWORD
;
151 char *windowClass
= "EDIT";
152 #if defined(__WIN95__)
153 if ( m_windowStyle
& wxTE_MULTILINE
)
155 msStyle
|= ES_AUTOVSCROLL
;
157 windowClass
= "RichEdit" ;
164 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
166 // If we're in Win95, and we want a simple 2D border,
167 // then make it an EDIT control instead.
168 #if defined(__WIN95__)
169 if (m_windowStyle
& wxSIMPLE_BORDER
)
171 windowClass
= "EDIT";
176 // Even with extended styles, need to combine with WS_BORDER
177 // for them to look right.
178 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
179 msStyle
|= WS_BORDER
;
181 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, windowClass
, NULL
,
183 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
184 m_globalHandle
? (HINSTANCE
) m_globalHandle
: wxGetInstance(), NULL
);
186 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create text ctrl" );
191 Ctl3dSubclassCtl((HWND
)m_hWnd
);
196 #if defined(__WIN95__)
199 // Have to enable events
200 ::SendMessage((HWND
)m_hWnd
, EM_SETEVENTMASK
, 0,
201 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
205 SubclassWin(GetHWND());
207 if ( parent
->GetFont().Ok() && parent
->GetFont().Ok() )
209 SetFont(parent
->GetFont());
213 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
216 SetSize(x
, y
, width
, height
);
218 // Causes a crash for Symantec C++ and WIN32 for some reason
219 #if !(defined(__SC__) && defined(__WIN32__))
220 if ( !value
.IsEmpty() )
229 // Make sure the window style (etc.) reflects the HWND style (roughly)
230 void wxTextCtrl::AdoptAttributesFromHWND(void)
232 wxWindow::AdoptAttributesFromHWND();
234 HWND hWnd
= (HWND
) GetHWND();
235 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
240 GetClassName((HWND
) hWnd
, buf
, 256);
243 GetClassNameW((HWND
) hWnd
, buf
, 256);
245 GetClassNameA((HWND
) hWnd
, buf
, 256);
257 if (style
& ES_MULTILINE
)
258 m_windowStyle
|= wxTE_MULTILINE
;
259 if (style
& ES_PASSWORD
)
260 m_windowStyle
|= wxTE_PASSWORD
;
261 if (style
& ES_READONLY
)
262 m_windowStyle
|= wxTE_READONLY
;
263 if (style
& ES_WANTRETURN
)
264 m_windowStyle
|= wxTE_PROCESS_ENTER
;
267 void wxTextCtrl::SetupColours(void)
269 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
270 SetForegroundColour(GetParent()->GetForegroundColour());
273 wxString
wxTextCtrl::GetValue(void) const
275 int length
= GetWindowTextLength((HWND
) GetHWND());
276 char *s
= new char[length
+1];
277 GetWindowText((HWND
) GetHWND(), s
, length
+1);
283 void wxTextCtrl::SetValue(const wxString
& value
)
285 // If newlines are denoted by just 10, must stick 13 in front.
287 int len
= value
.Length();
289 for (i
= 0; i
< len
; i
++)
291 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
296 char *tmp
= new char[len
+ singletons
+ 1];
298 for (i
= 0; i
< len
; i
++)
300 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
309 SetWindowText((HWND
) GetHWND(), tmp
);
313 SetWindowText((HWND
) GetHWND(), (const char *)value
);
316 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
318 int currentX
, currentY
;
319 GetPosition(¤tX
, ¤tY
);
325 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
327 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
330 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
332 int cx
; // button font dimensions
335 wxGetCharSize(GetHWND(), &cx
, &cy
, & GetFont());
337 int control_width
, control_height
, control_x
, control_y
;
339 // If we're prepared to use the existing size, then...
340 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
345 // Deal with default size (using -1 values)
347 w1
= DEFAULT_ITEM_WIDTH
;
354 // Calculations may have made text size too small
355 if (control_height
<= 0)
356 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
358 if (control_width
<= 0)
359 control_width
= DEFAULT_ITEM_WIDTH
;
361 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
362 (int)control_width
, (int)control_height
, TRUE
);
365 // Clipboard operations
366 void wxTextCtrl::Copy(void)
368 HWND hWnd
= (HWND
) GetHWND();
369 SendMessage(hWnd
, WM_COPY
, 0, 0L);
372 void wxTextCtrl::Cut(void)
374 HWND hWnd
= (HWND
) GetHWND();
375 SendMessage(hWnd
, WM_CUT
, 0, 0L);
378 void wxTextCtrl::Paste(void)
380 HWND hWnd
= (HWND
) GetHWND();
381 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
384 void wxTextCtrl::SetEditable(bool editable
)
386 HWND hWnd
= (HWND
) GetHWND();
387 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
390 void wxTextCtrl::SetInsertionPoint(long pos
)
392 HWND hWnd
= (HWND
) GetHWND();
394 #if defined(__WIN95__)
400 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
401 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
406 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
407 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
410 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
413 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
416 void wxTextCtrl::SetInsertionPointEnd(void)
418 long pos
= GetLastPosition();
419 SetInsertionPoint(pos
);
422 long wxTextCtrl::GetInsertionPoint(void) const
424 #if defined(__WIN95__)
430 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
435 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
439 long wxTextCtrl::GetLastPosition(void) const
441 HWND hWnd
= (HWND
) GetHWND();
443 // Will always return a number > 0 (according to docs)
444 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
446 // This gets the char index for the _beginning_ of the last line
447 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
449 // Get number of characters in the last line. We'll add this to the character
450 // index for the last line, 1st position.
451 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
453 return (long)(charIndex
+ lineLength
);
456 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
458 HWND hWnd
= (HWND
) GetHWND();
459 long fromChar
= from
;
462 // Set selection and remove it
464 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
466 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
468 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
470 // Now replace with 'value', by pasting.
471 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const char *)value
, 0, 0);
473 // Paste into edit control
474 SendMessage(hWnd
, WM_PASTE
, (WPARAM
)0, (LPARAM
)0L);
477 void wxTextCtrl::Remove(long from
, long to
)
479 HWND hWnd
= (HWND
) GetHWND();
480 long fromChar
= from
;
483 // Cut all selected text
485 SendMessage(hWnd
, EM_SETSEL
, fromChar
, toChar
);
487 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
489 SendMessage(hWnd
, WM_CUT
, (WPARAM
)0, (LPARAM
)0);
492 void wxTextCtrl::SetSelection(long from
, long to
)
494 HWND hWnd
= (HWND
) GetHWND();
495 long fromChar
= from
;
497 // if from and to are both -1, it means
498 // (in wxWindows) that all text should be selected.
499 // This translates into Windows convention
500 if ((from
== -1) && (to
== -1))
507 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)fromChar
, (LPARAM
)toChar
);
508 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
510 // WPARAM is 0: selection is scrolled into view
511 SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)MAKELONG(fromChar
, toChar
));
515 bool wxTextCtrl::LoadFile(const wxString
& file
)
517 if (!FileExists(WXSTRINGCAST file
))
524 // ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
525 ifstream
input(WXSTRINGCAST file
, ios::in
);
529 // Previously a SETSEL/REPLACESEL call-pair were done to insert
530 // line by line into the control. Apart from being very slow this
531 // was limited to 32K of text by the external interface presenting
532 // positions as signed shorts. Now load in one chunk...
533 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
535 struct stat stat_buf
;
536 if (stat(file
, &stat_buf
) < 0)
538 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
539 // This may need to be a bigger buffer than the file size suggests,
540 // if it's a UNIX file. Give it an extra 1000 just in case.
541 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
544 while (!input
.eof() && input
.peek() != EOF
)
546 input
.getline(wxBuffer
, 500);
547 int len
= strlen(wxBuffer
);
549 wxBuffer
[len
+1] = 10;
551 strcpy(tmp_buffer
+pos
, wxBuffer
);
552 pos
+= strlen(wxBuffer
);
556 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
557 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
558 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
566 // If file is null, try saved file name first
567 // Returns TRUE if succeeds.
568 bool wxTextCtrl::SaveFile(const wxString
& file
)
570 wxString
theFile(file
);
572 theFile
= m_fileName
;
575 m_fileName
= theFile
;
577 ofstream
output((char*) (const char*) theFile
);
581 // This will only save 64K max
582 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
583 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
584 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
585 char *pstr
= tmp_buffer
;
587 // Convert \r\n to just \n
596 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
601 void wxTextCtrl::WriteText(const wxString
& text
)
604 int len
= text
.Length();
605 char *newtext
= new char[(len
*2)+1];
615 newtext
[j
] = text
[i
];
620 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
624 void wxTextCtrl::Clear(void)
626 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
627 SetWindowText((HWND
) GetHWND(), "");
630 bool wxTextCtrl::IsModified(void) const
632 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
635 // Makes 'unmodified'
636 void wxTextCtrl::DiscardEdits(void)
638 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
642 * Some of the following functions are yet to be implemented
646 int wxTextCtrl::GetNumberOfLines(void) const
648 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
651 long wxTextCtrl::XYToPosition(long x
, long y
) const
653 HWND hWnd
= (HWND
) GetHWND();
655 // This gets the char index for the _beginning_ of this line
656 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
657 return (long)(x
+ charIndex
);
660 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
662 HWND hWnd
= (HWND
) GetHWND();
664 // This gets the line number containing the character
665 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
666 // This gets the char index for the _beginning_ of this line
667 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
668 // The X position must therefore be the different between pos and charIndex
669 *x
= (long)(pos
- charIndex
);
673 void wxTextCtrl::ShowPosition(long pos
)
675 HWND hWnd
= (HWND
) GetHWND();
677 // To scroll to a position, we pass the number of lines and characters
678 // to scroll *by*. This means that we need to:
679 // (1) Find the line position of the current line.
680 // (2) Find the line position of pos.
681 // (3) Scroll by (pos - current).
682 // For now, ignore the horizontal scrolling.
684 // Is this where scrolling is relative to - the line containing the caret?
685 // Or is the first visible line??? Try first visible line.
686 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
688 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
690 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
692 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
695 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
696 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
699 if (linesToScroll
!= 0)
700 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
703 int wxTextCtrl::GetLineLength(long lineNo
) const
705 long charIndex
= XYToPosition(0, lineNo
);
706 HWND hWnd
= (HWND
) GetHWND();
707 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
711 wxString
wxTextCtrl::GetLineText(long lineNo
) const
713 HWND hWnd
= (HWND
) GetHWND();
714 *(WORD
*)wxBuffer
= 512;
715 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
716 wxBuffer
[noChars
] = 0;
717 return wxString(wxBuffer
);
724 void wxTextCtrl::Command(wxCommandEvent
& event
)
726 SetValue (event
.GetString());
727 ProcessCommand (event
);
730 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
732 // By default, load the first file into the text window.
733 if (event
.GetNumberOfFiles() > 0)
735 LoadFile(event
.GetFiles()[0]);
739 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
740 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
742 //=========================================================================
743 // Called then the buffer is full (gcc 2.6.3)
744 // or when "endl" is output (Borland 4.5)
745 //=========================================================================
746 // Class declaration using multiple inheritance doesn't work properly for
747 // Borland. See note in wb_text.h.
748 #ifndef NO_TEXT_WINDOW_STREAM
749 int wxTextCtrl::overflow(int c
)
751 // Make sure there is a holding area
752 // this is not needed in <iostream> usage as it automagically allocates
753 // it, but does someone want to emulate it for safety's sake?
755 if ( allocate()==EOF
)
757 wxError("Streambuf allocation failed","Internal error");
762 // Verify that there are no characters in get area
763 if ( gptr() && gptr() < egptr() )
765 wxError("Who's trespassing my get area?","Internal error");
772 // Make sure there is a put area
775 /* This doesn't seem to be fatal so comment out error message */
776 // wxError("Put area not opened","Internal error");
779 setp( base(), base() );
781 setp( pbase(), pbase() );
785 // Determine how many characters have been inserted but no consumed
786 int plen
= pptr() - pbase();
788 // Now Jerry relies on the fact that the buffer is at least 2 chars
789 // long, but the holding area "may be as small as 1" ???
790 // And we need an additional \0, so let's keep this inefficient but
793 // If c!=EOF, it is a character that must also be comsumed
794 int xtra
= c
==EOF
? 0 : 1;
796 // Write temporary C-string to wxTextWindow
798 char *txt
= new char[plen
+xtra
+1];
799 memcpy(txt
, pbase(), plen
);
800 txt
[plen
] = (char)c
; // append c
801 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
802 // If the put area already contained \0, output will be truncated there
808 setp(pbase(), epptr());
810 #if defined(__WATCOMC__)
812 #elif defined(zapeof) // HP-UX (all cfront based?)
815 return c
!=EOF
? c
: 0; // this should make everybody happy
819 int len = pptr() - pbase();
820 char *txt = new char[len+1];
821 strncpy(txt, pbase(), len);
824 setp(pbase(), epptr());
830 //=========================================================================
831 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
832 //=========================================================================
833 int wxTextCtrl::sync(void)
835 // Verify that there are no characters in get area
836 if ( gptr() && gptr() < egptr() )
838 wxError("Who's trespassing my get area?","Internal error");
842 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
846 int len = pptr() - pbase();
847 char *txt = new char[len+1];
848 strncpy(txt, pbase(), len);
851 setp(pbase(), epptr());
857 //=========================================================================
858 // Should not be called by a "ostream". Used by a "istream"
859 //=========================================================================
860 int wxTextCtrl::underflow(void)
866 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
872 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
875 str
.Printf("%.2f", f
);
880 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
883 str
.Printf("%.2f", d
);
888 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
896 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
899 str
.Printf("%ld", i
);
904 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
914 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
915 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
920 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
921 return (WXHBRUSH
) hbrush
;
925 if (GetParent()->GetTransparentBackground())
926 SetBkMode((HDC
) pDC
, TRANSPARENT
);
928 SetBkMode((HDC
) pDC
, OPAQUE
);
930 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
931 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
933 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
935 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
936 // has a zero usage count.
937 // NOT NOW - will be cleaned up at end of app.
938 // backgroundBrush->RealizeResource();
939 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
942 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
944 // Fix by Marcel Rasche to allow Alt-Ctrl insertion of special characters
945 switch(event
.KeyCode())
955 char c
=(char)event
.KeyCode();
960 if ( (event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
962 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
963 event
.SetEventObject( this );
964 if ( GetEventHandler()->ProcessEvent(event
) )
967 else if ( event
.KeyCode() == WXK_TAB
) {
968 wxNavigationKeyEvent event
;
969 event
.SetDirection(!(::GetKeyState(VK_SHIFT
) & 0x100));
970 event
.SetWindowChange(FALSE
);
971 event
.SetEventObject(this);
973 if ( GetEventHandler()->ProcessEvent(event
) )
980 long wxTextCtrl::MSWGetDlgCode()
982 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
983 if ( m_windowStyle
& wxPROCESS_ENTER
)
984 lRc
|= DLGC_WANTMESSAGE
;
985 else if ( m_windowStyle
& wxTE_MULTILINE
)
986 lRc
|= DLGC_WANTMESSAGE
;
991 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
993 if ( m_windowStyle
& wxTE_MULTILINE
)
995 // No flicker - only problem is we probably can't change the background
999 ::GetClientRect((HWND) GetHWND(), &rect);
1001 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1002 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1004 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1005 ::DeleteObject(hBrush);
1006 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1009 // wxWindow::OnEraseBackground(event);
1012 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1016 wxDebugMsg("Edit control %d: ", (int)id);
1020 wxDebugMsg("EN_SETFOCUS\n");
1023 wxDebugMsg("EN_KILLFOCUS\n");
1026 wxDebugMsg("EN_CHANGE\n");
1029 wxDebugMsg("EN_UPDATE\n");
1032 wxDebugMsg("EN_ERRSPACE\n");
1035 wxDebugMsg("EN_MAXTEXT\n");
1038 wxDebugMsg("EN_HSCROLL\n");
1041 wxDebugMsg("EN_VSCROLL\n");
1044 wxDebugMsg("Unknown EDIT notification\n");
1053 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1056 event
.SetEventObject( this );
1057 GetEventHandler()->ProcessEvent(event
);
1063 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1064 wxString
val(GetValue());
1065 if ( !val
.IsNull() )
1066 event
.m_commandString
= WXSTRINGCAST val
;
1067 event
.SetEventObject( this );
1068 ProcessCommand(event
);
1072 // the other notification messages are not processed
1087 // For Rich Edit controls. Do we need it?
1089 #if defined(__WIN95__)
1090 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1092 wxCommandEvent
event(0, m_windowId
);
1094 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1095 switch ( hdr1
->code
)
1097 // Insert case code here
1099 return wxControl::MSWNotify(wParam
, lParam
);
1103 event
.SetEventObject( this );
1104 event
.SetEventType(eventType
);
1106 if ( !GetEventHandler()->ProcessEvent(event
) )