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"
47 #include <sys/types.h>
53 #if defined(__BORLANDC__) && !defined(__WIN32__)
56 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
59 #define farmalloc malloc
66 #if wxUSE_RICHEDIT && !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
)
78 #endif // USE_SHARED_LIBRARY
81 wxTextCtrl::wxTextCtrl()
82 #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();
122 long msStyle
= ES_LEFT
| WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
;
123 if (m_windowStyle
& wxTE_MULTILINE
)
125 wxASSERT_MSG( !(m_windowStyle
& wxTE_PROCESS_ENTER
),
126 "wxTE_PROCESS_ENTER style is ignored for multiline controls" );
128 msStyle
|= ES_MULTILINE
| ES_WANTRETURN
| WS_VSCROLL
; // WS_BORDER
129 m_windowStyle
|= wxTE_PROCESS_ENTER
;
132 msStyle
|= ES_AUTOHSCROLL
;
134 if (m_windowStyle
& wxTE_READONLY
)
135 msStyle
|= ES_READONLY
;
137 if (m_windowStyle
& wxHSCROLL
)
138 msStyle
|= (WS_HSCROLL
| ES_AUTOHSCROLL
) ;
139 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
140 msStyle
|= ES_PASSWORD
;
142 const char *windowClass
= "EDIT";
145 if ( m_windowStyle
& wxTE_MULTILINE
)
147 msStyle
|= ES_AUTOVSCROLL
;
149 windowClass
= "RichEdit" ;
156 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
158 // If we're in Win95, and we want a simple 2D border,
159 // then make it an EDIT control instead.
161 if (m_windowStyle
& wxSIMPLE_BORDER
)
163 windowClass
= "EDIT";
168 // Even with extended styles, need to combine with WS_BORDER
169 // for them to look right.
170 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
171 msStyle
|= WS_BORDER
;
173 m_hWnd
= (WXHWND
)::CreateWindowEx(exStyle
, windowClass
, NULL
,
175 0, 0, 0, 0, (HWND
) ((wxWindow
*)parent
)->GetHWND(), (HMENU
)m_windowId
,
176 wxGetInstance(), NULL
);
178 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create text ctrl" );
183 Ctl3dSubclassCtl((HWND
)m_hWnd
);
191 // Have to enable events
192 ::SendMessage((HWND
)m_hWnd
, EM_SETEVENTMASK
, 0,
193 ENM_CHANGE
| ENM_DROPFILES
| ENM_SELCHANGE
| ENM_UPDATE
);
197 SubclassWin(GetHWND());
199 if ( parent
->GetFont().Ok() && parent
->GetFont().Ok() )
201 SetFont(parent
->GetFont());
205 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
208 SetSize(x
, y
, width
, height
);
210 // Causes a crash for Symantec C++ and WIN32 for some reason
211 #if !(defined(__SC__) && defined(__WIN32__))
212 if ( !value
.IsEmpty() )
221 // Make sure the window style (etc.) reflects the HWND style (roughly)
222 void wxTextCtrl::AdoptAttributesFromHWND()
224 wxWindow::AdoptAttributesFromHWND();
226 HWND hWnd
= (HWND
) GetHWND();
227 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
229 // retrieve the style to see whether this is an edit or richedit ctrl
234 GetClassName((HWND
) hWnd
, buf
, 256);
237 GetClassNameW((HWND
) hWnd
, buf
, 256);
240 GetClassName((HWND
) hWnd
, buf
, 256);
242 GetClassNameA((HWND
) hWnd
, buf
, 256);
256 if (style
& ES_MULTILINE
)
257 m_windowStyle
|= wxTE_MULTILINE
;
258 if (style
& ES_PASSWORD
)
259 m_windowStyle
|= wxTE_PASSWORD
;
260 if (style
& ES_READONLY
)
261 m_windowStyle
|= wxTE_READONLY
;
262 if (style
& ES_WANTRETURN
)
263 m_windowStyle
|= wxTE_PROCESS_ENTER
;
266 void wxTextCtrl::SetupColours()
268 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
269 SetForegroundColour(GetParent()->GetForegroundColour());
272 wxString
wxTextCtrl::GetValue() const
274 int length
= GetWindowTextLength((HWND
) GetHWND());
275 char *s
= new char[length
+1];
276 GetWindowText((HWND
) GetHWND(), s
, length
+1);
282 void wxTextCtrl::SetValue(const wxString
& value
)
284 // If newlines are denoted by just 10, must stick 13 in front.
286 int len
= value
.Length();
288 for (i
= 0; i
< len
; i
++)
290 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
295 char *tmp
= new char[len
+ singletons
+ 1];
297 for (i
= 0; i
< len
; i
++)
299 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
308 SetWindowText((HWND
) GetHWND(), tmp
);
312 SetWindowText((HWND
) GetHWND(), (const char *)value
);
315 void wxTextCtrl::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
317 int currentX
, currentY
;
318 GetPosition(¤tX
, ¤tY
);
324 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
326 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
329 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
331 int cx
; // button font dimensions
334 wxGetCharSize(GetHWND(), &cx
, &cy
, & this->GetFont());
336 int control_width
, control_height
, control_x
, control_y
;
338 // If we're prepared to use the existing size, then...
339 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
344 // Deal with default size (using -1 values)
346 w1
= DEFAULT_ITEM_WIDTH
;
353 // Calculations may have made text size too small
354 if (control_height
<= 0)
355 control_height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
357 if (control_width
<= 0)
358 control_width
= DEFAULT_ITEM_WIDTH
;
360 MoveWindow((HWND
) GetHWND(), (int)control_x
, (int)control_y
,
361 (int)control_width
, (int)control_height
, TRUE
);
364 // Clipboard operations
365 void wxTextCtrl::Copy()
367 HWND hWnd
= (HWND
) GetHWND();
368 SendMessage(hWnd
, WM_COPY
, 0, 0L);
371 void wxTextCtrl::Cut()
373 HWND hWnd
= (HWND
) GetHWND();
374 SendMessage(hWnd
, WM_CUT
, 0, 0L);
377 void wxTextCtrl::Paste()
379 HWND hWnd
= (HWND
) GetHWND();
380 SendMessage(hWnd
, WM_PASTE
, 0, 0L);
383 void wxTextCtrl::SetEditable(bool editable
)
385 HWND hWnd
= (HWND
) GetHWND();
386 SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)!editable
, (LPARAM
)0L);
389 void wxTextCtrl::SetInsertionPoint(long pos
)
391 HWND hWnd
= (HWND
) GetHWND();
399 SendMessage(hWnd
, EM_EXSETSEL
, 0, (LPARAM
) &range
);
400 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
405 SendMessage(hWnd
, EM_SETSEL
, pos
, pos
);
406 SendMessage(hWnd
, EM_SCROLLCARET
, (WPARAM
)0, (LPARAM
)0);
409 SendMessage(hWnd
, EM_SETSEL
, 0, MAKELPARAM(pos
, pos
));
412 SendMessage(hWnd
, EM_REPLACESEL
, 0, (LPARAM
)nothing
);
415 void wxTextCtrl::SetInsertionPointEnd()
417 long pos
= GetLastPosition();
418 SetInsertionPoint(pos
);
421 long wxTextCtrl::GetInsertionPoint() const
429 SendMessage((HWND
) GetHWND(), EM_EXGETSEL
, 0, (LPARAM
) &range
);
434 DWORD Pos
=(DWORD
)SendMessage((HWND
) GetHWND(), EM_GETSEL
, 0, 0L);
438 long wxTextCtrl::GetLastPosition() const
440 HWND hWnd
= (HWND
) GetHWND();
442 // Will always return a number > 0 (according to docs)
443 int noLines
= (int)SendMessage(hWnd
, EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0L);
445 // This gets the char index for the _beginning_ of the last line
446 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)(noLines
-1), (LPARAM
)0L);
448 // Get number of characters in the last line. We'll add this to the character
449 // index for the last line, 1st position.
450 int lineLength
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0L);
452 return (long)(charIndex
+ lineLength
);
455 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);
476 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
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...
539 struct _stat stat_buf
;
540 if (stat((char*) (const char*) file
, &stat_buf
) < 0)
543 struct stat stat_buf
;
544 if (stat(file
, &stat_buf
) < 0)
548 // char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
549 // This may need to be a bigger buffer than the file size suggests,
550 // if it's a UNIX file. Give it an extra 1000 just in case.
551 char *tmp_buffer
= (char*)farmalloc((size_t)(stat_buf
.st_size
+1+1000));
554 while (!input
.eof() && input
.peek() != EOF
)
556 input
.getline(wxBuffer
, 500);
557 int len
= strlen(wxBuffer
);
559 wxBuffer
[len
+1] = 10;
561 strcpy(tmp_buffer
+pos
, wxBuffer
);
562 pos
+= strlen(wxBuffer
);
566 // SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
567 SetWindowText((HWND
) GetHWND(), tmp_buffer
);
568 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
576 // If file is null, try saved file name first
577 // Returns TRUE if succeeds.
578 bool wxTextCtrl::SaveFile(const wxString
& file
)
580 wxString
theFile(file
);
583 theFile
= m_fileName
;
588 m_fileName
= theFile
;
590 ofstream
output((char*) (const char*) theFile
);
594 // This will only save 64K max
595 unsigned long nbytes
= SendMessage((HWND
) GetHWND(), WM_GETTEXTLENGTH
, 0, 0);
596 char *tmp_buffer
= (char*)farmalloc((size_t)(nbytes
+1));
597 SendMessage((HWND
) GetHWND(), WM_GETTEXT
, (WPARAM
)(nbytes
+1), (LPARAM
)tmp_buffer
);
598 char *pstr
= tmp_buffer
;
600 // Convert \r\n to just \n
609 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
614 void wxTextCtrl::WriteText(const wxString
& text
)
617 int len
= text
.Length();
618 char *newtext
= new char[(len
*2)+1];
628 newtext
[j
] = text
[i
];
633 SendMessage((HWND
) GetHWND(), EM_REPLACESEL
, 0, (LPARAM
)newtext
);
637 void wxTextCtrl::AppendText(const wxString
& text
)
639 SetInsertionPointEnd();
643 void wxTextCtrl::Clear()
645 SetWindowText((HWND
) GetHWND(), "");
648 bool wxTextCtrl::IsModified() const
650 return (SendMessage((HWND
) GetHWND(), EM_GETMODIFY
, 0, 0) != 0);
653 // Makes 'unmodified'
654 void wxTextCtrl::DiscardEdits()
656 SendMessage((HWND
) GetHWND(), EM_SETMODIFY
, FALSE
, 0L);
660 * Some of the following functions are yet to be implemented
664 int wxTextCtrl::GetNumberOfLines() const
666 return (int)SendMessage((HWND
) GetHWND(), EM_GETLINECOUNT
, (WPARAM
)0, (LPARAM
)0);
669 long wxTextCtrl::XYToPosition(long x
, long y
) const
671 HWND hWnd
= (HWND
) GetHWND();
673 // This gets the char index for the _beginning_ of this line
674 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)y
, (LPARAM
)0);
675 return (long)(x
+ charIndex
);
678 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
680 HWND hWnd
= (HWND
) GetHWND();
682 // This gets the line number containing the character
683 int lineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0);
684 // This gets the char index for the _beginning_ of this line
685 int charIndex
= (int)SendMessage(hWnd
, EM_LINEINDEX
, (WPARAM
)lineNo
, (LPARAM
)0);
686 // The X position must therefore be the different between pos and charIndex
687 *x
= (long)(pos
- charIndex
);
691 void wxTextCtrl::ShowPosition(long pos
)
693 HWND hWnd
= (HWND
) GetHWND();
695 // To scroll to a position, we pass the number of lines and characters
696 // to scroll *by*. This means that we need to:
697 // (1) Find the line position of the current line.
698 // (2) Find the line position of pos.
699 // (3) Scroll by (pos - current).
700 // For now, ignore the horizontal scrolling.
702 // Is this where scrolling is relative to - the line containing the caret?
703 // Or is the first visible line??? Try first visible line.
704 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
706 int currentLineLineNo
= (int)SendMessage(hWnd
, EM_GETFIRSTVISIBLELINE
, (WPARAM
)0, (LPARAM
)0L);
708 int specifiedLineLineNo
= (int)SendMessage(hWnd
, EM_LINEFROMCHAR
, (WPARAM
)pos
, (LPARAM
)0L);
710 int linesToScroll
= specifiedLineLineNo
- currentLineLineNo
;
713 wxDebugMsg("Caret line: %d; Current visible line: %d; Specified line: %d; lines to scroll: %d\n",
714 currentLineLineNo1, currentLineLineNo, specifiedLineLineNo, linesToScroll);
717 if (linesToScroll
!= 0)
718 (void)SendMessage(hWnd
, EM_LINESCROLL
, (WPARAM
)0, (LPARAM
)MAKELPARAM(linesToScroll
, 0));
721 int wxTextCtrl::GetLineLength(long lineNo
) const
723 long charIndex
= XYToPosition(0, lineNo
);
724 HWND hWnd
= (HWND
) GetHWND();
725 int len
= (int)SendMessage(hWnd
, EM_LINELENGTH
, (WPARAM
)charIndex
, (LPARAM
)0);
729 wxString
wxTextCtrl::GetLineText(long lineNo
) const
731 HWND hWnd
= (HWND
) GetHWND();
732 *(WORD
*)wxBuffer
= 512;
733 int noChars
= (int)SendMessage(hWnd
, EM_GETLINE
, (WPARAM
)lineNo
, (LPARAM
)wxBuffer
);
734 wxBuffer
[noChars
] = 0;
735 return wxString(wxBuffer
);
742 void wxTextCtrl::Command(wxCommandEvent
& event
)
744 SetValue (event
.GetString());
745 ProcessCommand (event
);
748 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
750 // By default, load the first file into the text window.
751 if (event
.GetNumberOfFiles() > 0)
753 LoadFile(event
.GetFiles()[0]);
757 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
758 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
760 //=========================================================================
761 // Called then the buffer is full (gcc 2.6.3)
762 // or when "endl" is output (Borland 4.5)
763 //=========================================================================
764 // Class declaration using multiple inheritance doesn't work properly for
765 // Borland. See note in textctrl.h.
766 #ifndef NO_TEXT_WINDOW_STREAM
767 int wxTextCtrl::overflow(int c
)
769 // Make sure there is a holding area
770 // this is not needed in <iostream> usage as it automagically allocates
771 // it, but does someone want to emulate it for safety's sake?
773 if ( allocate()==EOF
)
775 wxLogError("Streambuf allocation failed");
780 // Verify that there are no characters in get area
781 if ( gptr() && gptr() < egptr() )
783 wxError("Who's trespassing my get area?","Internal error");
790 // Make sure there is a put area
793 /* This doesn't seem to be fatal so comment out error message */
794 // wxError("Put area not opened","Internal error");
797 setp( base(), base() );
799 setp( pbase(), pbase() );
803 // Determine how many characters have been inserted but no consumed
804 int plen
= pptr() - pbase();
806 // Now Jerry relies on the fact that the buffer is at least 2 chars
807 // long, but the holding area "may be as small as 1" ???
808 // And we need an additional \0, so let's keep this inefficient but
811 // If c!=EOF, it is a character that must also be comsumed
812 int xtra
= c
==EOF
? 0 : 1;
814 // Write temporary C-string to wxTextWindow
816 char *txt
= new char[plen
+xtra
+1];
817 memcpy(txt
, pbase(), plen
);
818 txt
[plen
] = (char)c
; // append c
819 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
820 // If the put area already contained \0, output will be truncated there
826 setp(pbase(), epptr());
828 #if defined(__WATCOMC__)
830 #elif defined(zapeof) // HP-UX (all cfront based?)
833 return c
!=EOF
? c
: 0; // this should make everybody happy
837 int len = pptr() - pbase();
838 char *txt = new char[len+1];
839 strncpy(txt, pbase(), len);
842 setp(pbase(), epptr());
848 //=========================================================================
849 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
850 //=========================================================================
851 int wxTextCtrl::sync()
853 // Verify that there are no characters in get area
854 if ( gptr() && gptr() < egptr() )
856 wxError("Who's trespassing my get area?","Internal error");
860 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
864 int len = pptr() - pbase();
865 char *txt = new char[len+1];
866 strncpy(txt, pbase(), len);
869 setp(pbase(), epptr());
875 //=========================================================================
876 // Should not be called by a "ostream". Used by a "istream"
877 //=========================================================================
878 int wxTextCtrl::underflow()
884 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
890 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
893 str
.Printf("%.2f", f
);
898 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
901 str
.Printf("%.2f", d
);
906 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
914 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
917 str
.Printf("%ld", i
);
922 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
932 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
933 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
938 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
939 return (WXHBRUSH
) hbrush
;
943 if (GetParent()->GetTransparentBackground())
944 SetBkMode((HDC
) pDC
, TRANSPARENT
);
946 SetBkMode((HDC
) pDC
, OPAQUE
);
948 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
949 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
951 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
953 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
954 // has a zero usage count.
955 // NOT NOW - will be cleaned up at end of app.
956 // backgroundBrush->RealizeResource();
957 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
960 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
962 switch( event
.KeyCode() )
964 // Fix by Marcel Rasche to allow Alt-Ctrl insertion of special characters
973 char c
= (char)event
.KeyCode();
979 wxASSERT_MSG( m_windowStyle
& wxTE_PROCESS_ENTER
,
980 "this text ctrl should never receive return" );
981 if ( m_windowStyle
& wxTE_MULTILINE
== 0 )
983 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
984 event
.SetEventObject( this );
985 if ( GetEventHandler()->ProcessEvent(event
) )
988 //else: multiline controls need Enter for themselves
993 // only produce navigation event if we don't process TAB ourself or
994 // if it's a Shift-Tab keypress (we assume nobody will ever need
995 // this key combo for himself)
997 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
998 // handled by Windows
999 if ( event
.ShiftDown() || !(m_windowStyle
& wxTE_PROCESS_TAB
) )
1001 wxNavigationKeyEvent eventNav
;
1002 eventNav
.SetDirection(!event
.ShiftDown());
1003 eventNav
.SetWindowChange(FALSE
);
1004 eventNav
.SetEventObject(this);
1006 if ( GetEventHandler()->ProcessEvent(eventNav
) )
1011 // don't just call event.Skip() because this will cause TABs and ENTERs
1012 // be passed upwards and we don't always want this - instead process it
1017 long wxTextCtrl::MSWGetDlgCode()
1019 // we always want the characters and the arrows
1020 long lRc
= DLGC_WANTCHARS
| DLGC_WANTARROWS
;
1022 // we may have several different cases:
1023 // 1. normal case: both TAB and ENTER are used for dialog navigation
1024 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
1025 // control in the dialog
1026 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
1027 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
1029 if ( m_windowStyle
& wxTE_PROCESS_ENTER
)
1030 lRc
|= DLGC_WANTMESSAGE
;
1031 if ( m_windowStyle
& wxTE_PROCESS_TAB
)
1032 lRc
|= DLGC_WANTTAB
;
1037 void wxTextCtrl::OnEraseBackground(wxEraseEvent
& event
)
1039 if ( m_windowStyle
& wxTE_MULTILINE
)
1041 // No flicker - only problem is we probably can't change the background
1045 ::GetClientRect((HWND) GetHWND(), &rect);
1047 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1048 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1050 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1051 ::DeleteObject(hBrush);
1052 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1055 // wxWindow::OnEraseBackground(event);
1058 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
1062 wxDebugMsg("Edit control %d: ", (int)id);
1066 wxDebugMsg("EN_SETFOCUS\n");
1069 wxDebugMsg("EN_KILLFOCUS\n");
1072 wxDebugMsg("EN_CHANGE\n");
1075 wxDebugMsg("EN_UPDATE\n");
1078 wxDebugMsg("EN_ERRSPACE\n");
1081 wxDebugMsg("EN_MAXTEXT\n");
1084 wxDebugMsg("EN_HSCROLL\n");
1087 wxDebugMsg("EN_VSCROLL\n");
1090 wxDebugMsg("Unknown EDIT notification\n");
1099 wxFocusEvent
event(param
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1102 event
.SetEventObject( this );
1103 GetEventHandler()->ProcessEvent(event
);
1109 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, m_windowId
);
1110 wxString
val(GetValue());
1111 if ( !val
.IsNull() )
1112 event
.m_commandString
= WXSTRINGCAST val
;
1113 event
.SetEventObject( this );
1114 ProcessCommand(event
);
1118 // the other notification messages are not processed
1133 // For Rich Edit controls. Do we need it?
1136 bool wxTextCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
1138 wxCommandEvent
event(0, m_windowId
);
1140 NMHDR
*hdr1
= (NMHDR
*) lParam
;
1141 switch ( hdr1
->code
)
1143 // Insert case code here
1145 return wxControl::MSWNotify(wParam
, lParam
);
1149 event
.SetEventObject( this );
1150 event
.SetEventType(eventType
);
1152 if ( !GetEventHandler()->ProcessEvent(event
) )