]> git.saurik.com Git - wxWidgets.git/blame - src/msw/textctrl.cpp
fixed an over-optimisation
[wxWidgets.git] / src / msw / textctrl.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: textctrl.cpp
3// Purpose: wxTextCtrl
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c085e333 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "textctrl.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/textctrl.h"
25#include "wx/settings.h"
2432b92d
JS
26#include "wx/brush.h"
27#include "wx/utils.h"
28#include "wx/log.h"
2bda0e17
KB
29#endif
30
47d67540 31#if wxUSE_CLIPBOARD
2bda0e17
KB
32#include "wx/app.h"
33#include "wx/clipbrd.h"
34#endif
35
36#include "wx/msw/private.h"
37
38#include <windows.h>
39#include <stdlib.h>
fbc535ff
JS
40
41#if wxUSE_IOSTREAMH
3f4a0c5b 42# include <fstream.h>
fbc535ff 43#else
3f4a0c5b 44# include <fstream>
fbc535ff 45#endif
2bda0e17
KB
46
47#include <sys/types.h>
17dff81c 48#ifndef __MWERKS__
2bda0e17 49#include <sys/stat.h>
17dff81c
SC
50#else
51#include <stat.h>
52#endif
2bda0e17
KB
53#if defined(__BORLANDC__) && !defined(__WIN32__)
54#include <alloc.h>
55#else
ce3ed50d 56#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
2bda0e17
KB
57#include <malloc.h>
58#endif
59#define farmalloc malloc
60#define farfree free
61#endif
62#include <windowsx.h>
63
64#include <string.h>
65
57c208c5 66#if wxUSE_RICHEDIT && !defined(__GNUWIN32__)
cd471848 67 #include <richedit.h>
2bda0e17
KB
68#endif
69
70#if !USE_SHARED_LIBRARY
e702ff0f 71
2bda0e17
KB
72IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
73
74BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
c085e333
VZ
75 EVT_CHAR(wxTextCtrl::OnChar)
76 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
77 EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground)
e702ff0f
JS
78
79 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
80 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
81 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
82 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
83 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
84
85 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
86 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
87 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
88 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
89 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
2bda0e17 90END_EVENT_TABLE()
e702ff0f 91
cd471848 92#endif // USE_SHARED_LIBRARY
2bda0e17
KB
93
94// Text item
cd471848 95wxTextCtrl::wxTextCtrl()
2bda0e17 96#ifndef NO_TEXT_WINDOW_STREAM
cd471848 97 : streambuf()
2bda0e17
KB
98#endif
99{
cd471848 100#if wxUSE_RICHEDIT
2bda0e17 101 m_isRich = FALSE;
cd471848 102#endif
2bda0e17
KB
103}
104
debe6624 105bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
c085e333
VZ
106 const wxString& value,
107 const wxPoint& pos,
108 const wxSize& size, long style,
109 const wxValidator& validator,
110 const wxString& name)
2bda0e17 111{
2bda0e17
KB
112 SetName(name);
113 SetValidator(validator);
114 if (parent) parent->AddChild(this);
115
116 m_windowStyle = style;
117
118 // Should this be taken from the system colours?
119// SetBackgroundColour(wxColour(255, 255, 255));
120
121 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
122
fd71308f 123 SetForegroundColour(parent->GetForegroundColour()) ;
2bda0e17
KB
124
125 if ( id == -1 )
c085e333 126 m_windowId = (int)NewControlId();
2bda0e17 127 else
c085e333 128 m_windowId = id;
2bda0e17
KB
129
130 int x = pos.x;
131 int y = pos.y;
132 int width = size.x;
133 int height = size.y;
134
2bda0e17
KB
135 long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
136 if (m_windowStyle & wxTE_MULTILINE)
cd471848 137 {
5fb9fcfc
VZ
138 wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
139 "wxTE_PROCESS_ENTER style is ignored for multiline controls" );
140
cd471848
VZ
141 msStyle |= ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL ; // WS_BORDER
142 m_windowStyle |= wxTE_PROCESS_ENTER;
143 }
2bda0e17
KB
144 else
145 msStyle |= ES_AUTOHSCROLL ;
146
147 if (m_windowStyle & wxTE_READONLY)
148 msStyle |= ES_READONLY;
149
150 if (m_windowStyle & wxHSCROLL)
151 msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL) ;
152 if (m_windowStyle & wxTE_PASSWORD) // hidden input
153 msStyle |= ES_PASSWORD;
154
cd471848
VZ
155 const char *windowClass = "EDIT";
156
57c208c5 157#if wxUSE_RICHEDIT
2bda0e17 158 if ( m_windowStyle & wxTE_MULTILINE )
2bda0e17 159 {
c085e333
VZ
160 msStyle |= ES_AUTOVSCROLL;
161 m_isRich = TRUE;
162 windowClass = "RichEdit" ;
2bda0e17
KB
163 }
164 else
c085e333 165 m_isRich = FALSE;
cd471848 166#endif
2bda0e17
KB
167
168 bool want3D;
169 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
170
171 // If we're in Win95, and we want a simple 2D border,
172 // then make it an EDIT control instead.
57c208c5 173#if wxUSE_RICHEDIT
2bda0e17
KB
174 if (m_windowStyle & wxSIMPLE_BORDER)
175 {
176 windowClass = "EDIT";
cd471848 177 m_isRich = FALSE;
2bda0e17
KB
178 }
179#endif
180
181 // Even with extended styles, need to combine with WS_BORDER
182 // for them to look right.
c085e333 183 if ( want3D || wxStyleHasBorder(m_windowStyle) )
2bda0e17
KB
184 msStyle |= WS_BORDER;
185
c085e333 186 m_hWnd = (WXHWND)::CreateWindowEx(exStyle, windowClass, NULL,
2bda0e17
KB
187 msStyle,
188 0, 0, 0, 0, (HWND) ((wxWindow*)parent)->GetHWND(), (HMENU)m_windowId,
cd471848 189 wxGetInstance(), NULL);
2bda0e17 190
c085e333
VZ
191 wxCHECK_MSG( m_hWnd, FALSE, "Failed to create text ctrl" );
192
1f112209 193#if wxUSE_CTL3D
2bda0e17
KB
194 if ( want3D )
195 {
c085e333
VZ
196 Ctl3dSubclassCtl((HWND)m_hWnd);
197 m_useCtl3D = TRUE;
2bda0e17
KB
198 }
199#endif
200
57c208c5 201#if wxUSE_RICHEDIT
2bda0e17
KB
202 if (m_isRich)
203 {
c085e333
VZ
204 // Have to enable events
205 ::SendMessage((HWND)m_hWnd, EM_SETEVENTMASK, 0,
206 ENM_CHANGE | ENM_DROPFILES | ENM_SELCHANGE | ENM_UPDATE);
2bda0e17
KB
207 }
208#endif
209
210 SubclassWin(GetHWND());
211
c0ed460c 212 if ( parent->GetFont().Ok() && parent->GetFont().Ok() )
2bda0e17 213 {
c0ed460c 214 SetFont(parent->GetFont());
2bda0e17
KB
215 }
216 else
217 {
c085e333 218 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
2bda0e17
KB
219 }
220
221 SetSize(x, y, width, height);
222
223 // Causes a crash for Symantec C++ and WIN32 for some reason
224#if !(defined(__SC__) && defined(__WIN32__))
c085e333
VZ
225 if ( !value.IsEmpty() )
226 {
227 SetValue(value);
228 }
2bda0e17
KB
229#endif
230
231 return TRUE;
232}
233
234// Make sure the window style (etc.) reflects the HWND style (roughly)
cd471848 235void wxTextCtrl::AdoptAttributesFromHWND()
2bda0e17 236{
c085e333 237 wxWindow::AdoptAttributesFromHWND();
2bda0e17 238
c085e333
VZ
239 HWND hWnd = (HWND) GetHWND();
240 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
2bda0e17 241
cd471848
VZ
242 // retrieve the style to see whether this is an edit or richedit ctrl
243#if wxUSE_RICHEDIT
244 char buf[256];
2bda0e17
KB
245
246#ifndef __WIN32__
c085e333 247 GetClassName((HWND) hWnd, buf, 256);
2bda0e17
KB
248#else
249#ifdef UNICODE
c085e333 250 GetClassNameW((HWND) hWnd, buf, 256);
57c208c5
JS
251#else
252#ifdef __TWIN32__
253 GetClassName((HWND) hWnd, buf, 256);
2bda0e17 254#else
c085e333 255 GetClassNameA((HWND) hWnd, buf, 256);
2bda0e17 256#endif
57c208c5 257#endif
2bda0e17
KB
258#endif
259
c085e333
VZ
260 wxString str(buf);
261 str.UpperCase();
262
263 if (str == "EDIT")
264 m_isRich = FALSE;
265 else
266 m_isRich = TRUE;
cd471848 267#endif
c085e333
VZ
268
269 if (style & ES_MULTILINE)
270 m_windowStyle |= wxTE_MULTILINE;
271 if (style & ES_PASSWORD)
272 m_windowStyle |= wxTE_PASSWORD;
273 if (style & ES_READONLY)
274 m_windowStyle |= wxTE_READONLY;
275 if (style & ES_WANTRETURN)
276 m_windowStyle |= wxTE_PROCESS_ENTER;
2bda0e17
KB
277}
278
cd471848 279void wxTextCtrl::SetupColours()
2bda0e17
KB
280{
281 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
fd71308f 282 SetForegroundColour(GetParent()->GetForegroundColour());
2bda0e17
KB
283}
284
cd471848 285wxString wxTextCtrl::GetValue() const
2bda0e17
KB
286{
287 int length = GetWindowTextLength((HWND) GetHWND());
288 char *s = new char[length+1];
289 GetWindowText((HWND) GetHWND(), s, length+1);
290 wxString str(s);
291 delete[] s;
c085e333 292 return str;
2bda0e17
KB
293}
294
295void wxTextCtrl::SetValue(const wxString& value)
296{
297 // If newlines are denoted by just 10, must stick 13 in front.
298 int singletons = 0;
299 int len = value.Length();
300 int i;
301 for (i = 0; i < len; i ++)
302 {
303 if ((i > 0) && (value[i] == 10) && (value[i-1] != 13))
304 singletons ++;
305 }
306 if (singletons > 0)
307 {
308 char *tmp = new char[len + singletons + 1];
309 int j = 0;
310 for (i = 0; i < len; i ++)
311 {
312 if ((i > 0) && (value[i] == 10) && (value[i-1] != 13))
313 {
314 tmp[j] = 13;
315 j ++;
316 }
317 tmp[j] = value[i];
318 j ++;
319 }
320 tmp[j] = 0;
321 SetWindowText((HWND) GetHWND(), tmp);
322 delete[] tmp;
323 }
324 else
325 SetWindowText((HWND) GetHWND(), (const char *)value);
326}
327
bfc6fde4 328void wxTextCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17
KB
329{
330 int currentX, currentY;
331 GetPosition(&currentX, &currentY);
332 int x1 = x;
333 int y1 = y;
334 int w1 = width;
335 int h1 = height;
336
337 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
338 x1 = currentX;
339 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
340 y1 = currentY;
341
81d66cf3
JS
342 AdjustForParentClientOrigin(x1, y1, sizeFlags);
343
2bda0e17
KB
344 int cx; // button font dimensions
345 int cy;
346
ce3ed50d 347 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
2bda0e17 348
1c4a764c 349 int control_width, control_height, control_x, control_y;
2bda0e17
KB
350
351 // If we're prepared to use the existing size, then...
352 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
353 {
354 GetSize(&w1, &h1);
355 }
356
357 // Deal with default size (using -1 values)
358 if (w1<=0)
359 w1 = DEFAULT_ITEM_WIDTH;
360
1c4a764c
VZ
361 control_x = x1;
362 control_y = y1;
363 control_width = w1;
364 control_height = h1;
2bda0e17
KB
365
366 // Calculations may have made text size too small
367 if (control_height <= 0)
1c4a764c 368 control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17
KB
369
370 if (control_width <= 0)
1c4a764c 371 control_width = DEFAULT_ITEM_WIDTH;
2bda0e17
KB
372
373 MoveWindow((HWND) GetHWND(), (int)control_x, (int)control_y,
374 (int)control_width, (int)control_height, TRUE);
2bda0e17
KB
375}
376
377// Clipboard operations
cd471848 378void wxTextCtrl::Copy()
2bda0e17 379{
e702ff0f
JS
380 if (CanCopy())
381 {
382 HWND hWnd = (HWND) GetHWND();
383 SendMessage(hWnd, WM_COPY, 0, 0L);
384 }
2bda0e17
KB
385}
386
cd471848 387void wxTextCtrl::Cut()
2bda0e17 388{
e702ff0f
JS
389 if (CanCut())
390 {
391 HWND hWnd = (HWND) GetHWND();
392 SendMessage(hWnd, WM_CUT, 0, 0L);
393 }
2bda0e17
KB
394}
395
cd471848 396void wxTextCtrl::Paste()
2bda0e17 397{
e702ff0f
JS
398 if (CanPaste())
399 {
400 HWND hWnd = (HWND) GetHWND();
401 SendMessage(hWnd, WM_PASTE, 0, 0L);
402 }
2bda0e17
KB
403}
404
debe6624 405void wxTextCtrl::SetEditable(bool editable)
2bda0e17
KB
406{
407 HWND hWnd = (HWND) GetHWND();
408 SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
409}
410
debe6624 411void wxTextCtrl::SetInsertionPoint(long pos)
2bda0e17
KB
412{
413 HWND hWnd = (HWND) GetHWND();
414#ifdef __WIN32__
57c208c5 415#if wxUSE_RICHEDIT
2bda0e17
KB
416 if ( m_isRich)
417 {
418 CHARRANGE range;
419 range.cpMin = pos;
420 range.cpMax = pos;
421 SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM) &range);
422 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
423 }
424 else
425#endif
426 {
427 SendMessage(hWnd, EM_SETSEL, pos, pos);
428 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
429 }
430#else
431 SendMessage(hWnd, EM_SETSEL, 0, MAKELPARAM(pos, pos));
432#endif
433 char *nothing = "";
434 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
435}
436
cd471848 437void wxTextCtrl::SetInsertionPointEnd()
2bda0e17
KB
438{
439 long pos = GetLastPosition();
440 SetInsertionPoint(pos);
441}
442
cd471848 443long wxTextCtrl::GetInsertionPoint() const
2bda0e17 444{
57c208c5 445#if wxUSE_RICHEDIT
2bda0e17
KB
446 if (m_isRich)
447 {
448 CHARRANGE range;
449 range.cpMin = 0;
450 range.cpMax = 0;
451 SendMessage((HWND) GetHWND(), EM_EXGETSEL, 0, (LPARAM) &range);
452 return range.cpMin;
453 }
454#endif
455
456 DWORD Pos=(DWORD)SendMessage((HWND) GetHWND(), EM_GETSEL, 0, 0L);
457 return Pos&0xFFFF;
458}
459
cd471848 460long wxTextCtrl::GetLastPosition() const
2bda0e17
KB
461{
462 HWND hWnd = (HWND) GetHWND();
463
464 // Will always return a number > 0 (according to docs)
465 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
466
467 // This gets the char index for the _beginning_ of the last line
468 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
39136494 469
2bda0e17
KB
470 // Get number of characters in the last line. We'll add this to the character
471 // index for the last line, 1st position.
472 int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
473
474 return (long)(charIndex + lineLength);
475}
476
debe6624 477void wxTextCtrl::Replace(long from, long to, const wxString& value)
2bda0e17 478{
acbd13a3 479#if wxUSE_CLIPBOARD
2bda0e17
KB
480 HWND hWnd = (HWND) GetHWND();
481 long fromChar = from;
482 long toChar = to;
39136494 483
2bda0e17
KB
484 // Set selection and remove it
485#ifdef __WIN32__
486 SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
487#else
488 SendMessage(hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar));
489#endif
490 SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
491
492 // Now replace with 'value', by pasting.
b3324be2 493 wxSetClipboardData(wxDF_TEXT, (wxObject *) (const char *)value, 0, 0);
2bda0e17
KB
494
495 // Paste into edit control
496 SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
acbd13a3
JS
497#else
498 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
499#endif
2bda0e17
KB
500}
501
debe6624 502void wxTextCtrl::Remove(long from, long to)
2bda0e17
KB
503{
504 HWND hWnd = (HWND) GetHWND();
505 long fromChar = from;
506 long toChar = to;
39136494 507
2bda0e17
KB
508 // Cut all selected text
509#ifdef __WIN32__
510 SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
511#else
512 SendMessage(hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar));
513#endif
514 SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
515}
516
debe6624 517void wxTextCtrl::SetSelection(long from, long to)
2bda0e17
KB
518{
519 HWND hWnd = (HWND) GetHWND();
520 long fromChar = from;
521 long toChar = to;
522 // if from and to are both -1, it means
523 // (in wxWindows) that all text should be selected.
524 // This translates into Windows convention
525 if ((from == -1) && (to == -1))
526 {
527 fromChar = 0;
528 toChar = -1;
529 }
39136494 530
2bda0e17
KB
531#ifdef __WIN32__
532 SendMessage(hWnd, EM_SETSEL, (WPARAM)fromChar, (LPARAM)toChar);
533 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
534#else
535 // WPARAM is 0: selection is scrolled into view
536 SendMessage(hWnd, EM_SETSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar));
537#endif
538}
539
540bool wxTextCtrl::LoadFile(const wxString& file)
541{
2432b92d 542 if (!wxFileExists(WXSTRINGCAST file))
2bda0e17
KB
543 return FALSE;
544
b823f5a1 545 m_fileName = file;
2bda0e17
KB
546
547 Clear();
548
fbc535ff
JS
549// ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
550 ifstream input(WXSTRINGCAST file, ios::in);
2bda0e17
KB
551
552 if (!input.bad())
553 {
554 // Previously a SETSEL/REPLACESEL call-pair were done to insert
555 // line by line into the control. Apart from being very slow this
556 // was limited to 32K of text by the external interface presenting
557 // positions as signed shorts. Now load in one chunk...
558 // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
559
ce3ed50d
JS
560#ifdef __SALFORDC__
561 struct _stat stat_buf;
562 if (stat((char*) (const char*) file, &stat_buf) < 0)
563 return FALSE;
564#else
2bda0e17
KB
565 struct stat stat_buf;
566 if (stat(file, &stat_buf) < 0)
567 return FALSE;
ce3ed50d
JS
568#endif
569
2bda0e17
KB
570// char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
571 // This may need to be a bigger buffer than the file size suggests,
572 // if it's a UNIX file. Give it an extra 1000 just in case.
573 char *tmp_buffer = (char*)farmalloc((size_t)(stat_buf.st_size+1+1000));
574 long no_lines = 0;
575 long pos = 0;
576 while (!input.eof() && input.peek() != EOF)
577 {
578 input.getline(wxBuffer, 500);
c085e333
VZ
579 int len = strlen(wxBuffer);
580 wxBuffer[len] = 13;
581 wxBuffer[len+1] = 10;
582 wxBuffer[len+2] = 0;
583 strcpy(tmp_buffer+pos, wxBuffer);
584 pos += strlen(wxBuffer);
585 no_lines++;
2bda0e17
KB
586 }
587
588// SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
589 SetWindowText((HWND) GetHWND(), tmp_buffer);
590 SendMessage((HWND) GetHWND(), EM_SETMODIFY, FALSE, 0L);
591 farfree(tmp_buffer);
592
593 return TRUE;
594 }
595 return FALSE;
596}
597
598// If file is null, try saved file name first
599// Returns TRUE if succeeds.
600bool wxTextCtrl::SaveFile(const wxString& file)
601{
cd471848 602 wxString theFile(file);
2bda0e17 603
cd471848
VZ
604 if (theFile == "")
605 theFile = m_fileName;
606
607 if (theFile == "")
608 return FALSE;
609
610 m_fileName = theFile;
611
612 ofstream output((char*) (const char*) theFile);
613 if (output.bad())
614 return FALSE;
2bda0e17
KB
615
616 // This will only save 64K max
617 unsigned long nbytes = SendMessage((HWND) GetHWND(), WM_GETTEXTLENGTH, 0, 0);
618 char *tmp_buffer = (char*)farmalloc((size_t)(nbytes+1));
619 SendMessage((HWND) GetHWND(), WM_GETTEXT, (WPARAM)(nbytes+1), (LPARAM)tmp_buffer);
620 char *pstr = tmp_buffer;
621
cd471848
VZ
622 // Convert \r\n to just \n
623 while (*pstr)
624 {
625 if (*pstr != '\r')
626 output << *pstr;
627 pstr++;
628 }
2bda0e17
KB
629
630 farfree(tmp_buffer);
631 SendMessage((HWND) GetHWND(), EM_SETMODIFY, FALSE, 0L);
632
633 return TRUE;
634}
635
636void wxTextCtrl::WriteText(const wxString& text)
637{
638 // Covert \n to \r\n
639 int len = text.Length();
640 char *newtext = new char[(len*2)+1];
641 int i = 0;
642 int j = 0;
643 while (i < len)
644 {
645 if (text[i] == '\n')
646 {
647 newtext[j] = '\r';
648 j ++;
649 }
650 newtext[j] = text[i];
651 i ++;
652 j ++;
653 }
654 newtext[j] = 0;
655 SendMessage((HWND) GetHWND(), EM_REPLACESEL, 0, (LPARAM)newtext);
656 delete[] newtext;
657}
658
5fb9fcfc
VZ
659void wxTextCtrl::AppendText(const wxString& text)
660{
661 SetInsertionPointEnd();
662 WriteText(text);
663}
664
cd471848 665void wxTextCtrl::Clear()
2bda0e17 666{
2bda0e17
KB
667 SetWindowText((HWND) GetHWND(), "");
668}
669
cd471848 670bool wxTextCtrl::IsModified() const
2bda0e17
KB
671{
672 return (SendMessage((HWND) GetHWND(), EM_GETMODIFY, 0, 0) != 0);
673}
674
675// Makes 'unmodified'
cd471848 676void wxTextCtrl::DiscardEdits()
2bda0e17
KB
677{
678 SendMessage((HWND) GetHWND(), EM_SETMODIFY, FALSE, 0L);
679}
680
681/*
682 * Some of the following functions are yet to be implemented
683 *
684 */
39136494 685
cd471848 686int wxTextCtrl::GetNumberOfLines() const
2bda0e17
KB
687{
688 return (int)SendMessage((HWND) GetHWND(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
689}
690
debe6624 691long wxTextCtrl::XYToPosition(long x, long y) const
2bda0e17
KB
692{
693 HWND hWnd = (HWND) GetHWND();
694
695 // This gets the char index for the _beginning_ of this line
696 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
697 return (long)(x + charIndex);
698}
699
debe6624 700void wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
2bda0e17
KB
701{
702 HWND hWnd = (HWND) GetHWND();
703
704 // This gets the line number containing the character
705 int lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0);
706 // This gets the char index for the _beginning_ of this line
707 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
708 // The X position must therefore be the different between pos and charIndex
709 *x = (long)(pos - charIndex);
710 *y = (long)lineNo;
711}
712
debe6624 713void wxTextCtrl::ShowPosition(long pos)
2bda0e17
KB
714{
715 HWND hWnd = (HWND) GetHWND();
716
717 // To scroll to a position, we pass the number of lines and characters
718 // to scroll *by*. This means that we need to:
719 // (1) Find the line position of the current line.
720 // (2) Find the line position of pos.
721 // (3) Scroll by (pos - current).
722 // For now, ignore the horizontal scrolling.
723
724 // Is this where scrolling is relative to - the line containing the caret?
725 // Or is the first visible line??? Try first visible line.
726// int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
727
728 int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
729
730 int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
39136494 731
2bda0e17
KB
732 int linesToScroll = specifiedLineLineNo - currentLineLineNo;
733
2bda0e17 734 if (linesToScroll != 0)
de4d7713 735 (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
2bda0e17
KB
736}
737
debe6624 738int wxTextCtrl::GetLineLength(long lineNo) const
2bda0e17
KB
739{
740 long charIndex = XYToPosition(0, lineNo);
741 HWND hWnd = (HWND) GetHWND();
742 int len = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0);
743 return len;
744}
745
debe6624 746wxString wxTextCtrl::GetLineText(long lineNo) const
2bda0e17
KB
747{
748 HWND hWnd = (HWND) GetHWND();
749 *(WORD *)wxBuffer = 512;
750 int noChars = (int)SendMessage(hWnd, EM_GETLINE, (WPARAM)lineNo, (LPARAM)wxBuffer);
751 wxBuffer[noChars] = 0;
c085e333 752 return wxString(wxBuffer);
2bda0e17
KB
753}
754
ca8b28f2
JS
755bool wxTextCtrl::CanCopy() const
756{
757 // Can copy if there's a selection
758 long from, to;
759 GetSelection(& from, & to);
760 return (from != to) ;
761}
762
763bool wxTextCtrl::CanCut() const
764{
765 // Can cut if there's a selection
766 long from, to;
767 GetSelection(& from, & to);
768 return (from != to) ;
769}
770
771bool wxTextCtrl::CanPaste() const
772{
b80ec6db
JS
773#if wxUSE_RICHEDIT
774 if (m_isRich)
775 {
776 int dataFormat = 0; // 0 == any format
777 return (::SendMessage( (HWND) GetHWND(), EM_CANPASTE, (WPARAM) (UINT) dataFormat, 0) != 0);
778 }
779#endif
780 if (!IsEditable())
781 return FALSE;
782
783 // Standard edit control: check for straight text on clipboard
784 bool isTextAvailable = FALSE;
785 if (::OpenClipboard((HWND) wxTheApp->GetTopWindow()->GetHWND()))
786 {
787 isTextAvailable = (::IsClipboardFormatAvailable(CF_TEXT) != 0);
788 ::CloseClipboard();
789 }
790 return isTextAvailable;
ca8b28f2
JS
791}
792
793// Undo/redo
794void wxTextCtrl::Undo()
795{
796 if (CanUndo())
797 {
798 ::SendMessage((HWND) GetHWND(), EM_UNDO, 0, 0);
799 }
800}
801
802void wxTextCtrl::Redo()
803{
804 if (CanRedo())
805 {
806 // Same as Undo, since Undo undoes the undo, i.e. a redo.
807 ::SendMessage((HWND) GetHWND(), EM_UNDO, 0, 0);
808 }
809}
810
811bool wxTextCtrl::CanUndo() const
812{
813 return (::SendMessage((HWND) GetHWND(), EM_CANUNDO, 0, 0) != 0);
814}
815
816bool wxTextCtrl::CanRedo() const
817{
818 return (::SendMessage((HWND) GetHWND(), EM_CANUNDO, 0, 0) != 0);
819}
820
821// If the return values from and to are the same, there is no
822// selection.
823void wxTextCtrl::GetSelection(long* from, long* to) const
824{
825#if wxUSE_RICHEDIT
826 if (m_isRich)
827 {
828 CHARRANGE charRange;
829 ::SendMessage((HWND) GetHWND(), EM_EXGETSEL, 0, (LPARAM) (CHARRANGE*) & charRange);
830
831 *from = charRange.cpMin;
832 *to = charRange.cpMax;
833
834 return;
835 }
836#endif
837 DWORD dwStart, dwEnd;
b80ec6db
JS
838 WPARAM wParam = (WPARAM) (DWORD*) & dwStart; // receives starting position
839 LPARAM lParam = (LPARAM) (DWORD*) & dwEnd; // receives ending position
ca8b28f2
JS
840
841 ::SendMessage((HWND) GetHWND(), EM_GETSEL, wParam, lParam);
842
843 *from = dwStart;
844 *to = dwEnd;
845}
846
847bool wxTextCtrl::IsEditable() const
848{
849 long style = ::GetWindowLong((HWND) GetHWND(), GWL_STYLE);
850 return ((style & ES_READONLY) == 0);
851}
39136494 852
2bda0e17
KB
853void wxTextCtrl::Command(wxCommandEvent & event)
854{
855 SetValue (event.GetString());
856 ProcessCommand (event);
857}
858
859void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
860{
861 // By default, load the first file into the text window.
862 if (event.GetNumberOfFiles() > 0)
863 {
864 LoadFile(event.GetFiles()[0]);
865 }
866}
867
868// The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
869// AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
870
871//=========================================================================
39136494 872// Called then the buffer is full (gcc 2.6.3)
2bda0e17
KB
873// or when "endl" is output (Borland 4.5)
874//=========================================================================
875// Class declaration using multiple inheritance doesn't work properly for
3f1af920 876// Borland. See note in textctrl.h.
2bda0e17
KB
877#ifndef NO_TEXT_WINDOW_STREAM
878int wxTextCtrl::overflow(int c)
879{
880 // Make sure there is a holding area
7cf98a65
UU
881 // this is not needed in <iostream> usage as it automagically allocates
882 // it, but does someone want to emulate it for safety's sake?
883#if wxUSE_IOSTREAMH
2bda0e17
KB
884 if ( allocate()==EOF )
885 {
2432b92d 886 wxLogError("Streambuf allocation failed");
2bda0e17
KB
887 return EOF;
888 }
7cf98a65 889#endif
39136494 890
2bda0e17
KB
891 // Verify that there are no characters in get area
892 if ( gptr() && gptr() < egptr() )
893 {
894 wxError("Who's trespassing my get area?","Internal error");
895 return EOF;
896 }
897
898 // Reset get area
899 setg(0,0,0);
900
901 // Make sure there is a put area
902 if ( ! pptr() )
903 {
904/* This doesn't seem to be fatal so comment out error message */
905// wxError("Put area not opened","Internal error");
7cf98a65
UU
906
907#if wxUSE_IOSTREAMH
908 setp( base(), base() );
909#else
910 setp( pbase(), pbase() );
911#endif
2bda0e17
KB
912 }
913
914 // Determine how many characters have been inserted but no consumed
915 int plen = pptr() - pbase();
916
917 // Now Jerry relies on the fact that the buffer is at least 2 chars
918 // long, but the holding area "may be as small as 1" ???
919 // And we need an additional \0, so let's keep this inefficient but
920 // safe copy.
921
922 // If c!=EOF, it is a character that must also be comsumed
923 int xtra = c==EOF? 0 : 1;
924
925 // Write temporary C-string to wxTextWindow
926 {
927 char *txt = new char[plen+xtra+1];
928 memcpy(txt, pbase(), plen);
929 txt[plen] = (char)c; // append c
930 txt[plen+xtra] = '\0'; // append '\0' or overwrite c
931 // If the put area already contained \0, output will be truncated there
5fb9fcfc 932 AppendText(txt);
2bda0e17
KB
933 delete[] txt;
934 }
935
936 // Reset put area
937 setp(pbase(), epptr());
938
939#if defined(__WATCOMC__)
940 return __NOT_EOF;
941#elif defined(zapeof) // HP-UX (all cfront based?)
942 return zapeof(c);
943#else
944 return c!=EOF ? c : 0; // this should make everybody happy
945#endif
946
947/* OLD CODE
948 int len = pptr() - pbase();
949 char *txt = new char[len+1];
950 strncpy(txt, pbase(), len);
951 txt[len] = '\0';
952 (*this) << txt;
953 setp(pbase(), epptr());
954 delete[] txt;
955 return EOF;
956*/
957}
958
959//=========================================================================
960// called then "endl" is output (gcc) or then explicit sync is done (Borland)
961//=========================================================================
cd471848 962int wxTextCtrl::sync()
2bda0e17
KB
963{
964 // Verify that there are no characters in get area
965 if ( gptr() && gptr() < egptr() )
966 {
967 wxError("Who's trespassing my get area?","Internal error");
968 return EOF;
969 }
970
971 if ( pptr() && pptr() > pbase() ) return overflow(EOF);
972
973 return 0;
974/* OLD CODE
975 int len = pptr() - pbase();
976 char *txt = new char[len+1];
977 strncpy(txt, pbase(), len);
978 txt[len] = '\0';
979 (*this) << txt;
980 setp(pbase(), epptr());
981 delete[] txt;
982 return 0;
983*/
984}
985
986//=========================================================================
987// Should not be called by a "ostream". Used by a "istream"
988//=========================================================================
cd471848 989int wxTextCtrl::underflow()
2bda0e17
KB
990{
991 return EOF;
992}
993#endif
994
995wxTextCtrl& wxTextCtrl::operator<<(const wxString& s)
996{
5fb9fcfc
VZ
997 AppendText(s);
998 return *this;
2bda0e17
KB
999}
1000
debe6624 1001wxTextCtrl& wxTextCtrl::operator<<(float f)
2bda0e17 1002{
b823f5a1
JS
1003 wxString str;
1004 str.Printf("%.2f", f);
5fb9fcfc 1005 AppendText(str);
b823f5a1 1006 return *this;
2bda0e17
KB
1007}
1008
debe6624 1009wxTextCtrl& wxTextCtrl::operator<<(double d)
2bda0e17 1010{
b823f5a1
JS
1011 wxString str;
1012 str.Printf("%.2f", d);
5fb9fcfc 1013 AppendText(str);
b823f5a1 1014 return *this;
2bda0e17
KB
1015}
1016
debe6624 1017wxTextCtrl& wxTextCtrl::operator<<(int i)
2bda0e17 1018{
b823f5a1
JS
1019 wxString str;
1020 str.Printf("%d", i);
5fb9fcfc 1021 AppendText(str);
b823f5a1 1022 return *this;
2bda0e17
KB
1023}
1024
debe6624 1025wxTextCtrl& wxTextCtrl::operator<<(long i)
2bda0e17 1026{
b823f5a1
JS
1027 wxString str;
1028 str.Printf("%ld", i);
5fb9fcfc 1029 AppendText(str);
b823f5a1 1030 return *this;
2bda0e17
KB
1031}
1032
1033wxTextCtrl& wxTextCtrl::operator<<(const char c)
1034{
b823f5a1 1035 char buf[2];
2bda0e17 1036
b823f5a1
JS
1037 buf[0] = c;
1038 buf[1] = 0;
5fb9fcfc 1039 AppendText(buf);
b823f5a1 1040 return *this;
2bda0e17
KB
1041}
1042
debe6624 1043WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
c085e333 1044 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 1045{
1f112209 1046#if wxUSE_CTL3D
2bda0e17
KB
1047 if ( m_useCtl3D )
1048 {
1049 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
1050 return (WXHBRUSH) hbrush;
1051 }
1052#endif
1053
1054 if (GetParent()->GetTransparentBackground())
1055 SetBkMode((HDC) pDC, TRANSPARENT);
1056 else
1057 SetBkMode((HDC) pDC, OPAQUE);
1058
1059 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1060 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
1061
1062 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
1063
1064 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
1065 // has a zero usage count.
1066 // NOT NOW - will be cleaned up at end of app.
1067// backgroundBrush->RealizeResource();
1068 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
1069}
1070
1071void wxTextCtrl::OnChar(wxKeyEvent& event)
1072{
cd471848
VZ
1073 switch( event.KeyCode() )
1074 {
cd471848 1075 case WXK_RETURN:
39136494 1076 if ( !(m_windowStyle & wxTE_MULTILINE) )
cd471848
VZ
1077 {
1078 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
1079 event.SetEventObject( this );
1080 if ( GetEventHandler()->ProcessEvent(event) )
1081 return;
1082 }
5fb9fcfc
VZ
1083 //else: multiline controls need Enter for themselves
1084
1085 break;
4d91c1d1 1086
cd471848 1087 case WXK_TAB:
5fb9fcfc
VZ
1088 // only produce navigation event if we don't process TAB ourself or
1089 // if it's a Shift-Tab keypress (we assume nobody will ever need
1090 // this key combo for himself)
1091 //
1092 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1093 // handled by Windows
1094 if ( event.ShiftDown() || !(m_windowStyle & wxTE_PROCESS_TAB) )
cd471848 1095 {
5fb9fcfc
VZ
1096 wxNavigationKeyEvent eventNav;
1097 eventNav.SetDirection(!event.ShiftDown());
1098 eventNav.SetWindowChange(FALSE);
1099 eventNav.SetEventObject(this);
39136494 1100
5fb9fcfc 1101 if ( GetEventHandler()->ProcessEvent(eventNav) )
cd471848
VZ
1102 return;
1103 }
341c92a8 1104 break;
4d91c1d1
VZ
1105
1106 default:
1107 event.Skip();
39136494 1108 return;
cd471848 1109 }
39136494 1110
cd471848
VZ
1111 // don't just call event.Skip() because this will cause TABs and ENTERs
1112 // be passed upwards and we don't always want this - instead process it
1113 // right here
2a47d3c1
JS
1114 Default();
1115// event.Skip();
2bda0e17
KB
1116}
1117
ae29de83 1118long wxTextCtrl::MSWGetDlgCode()
2bda0e17 1119{
cd471848
VZ
1120 // we always want the characters and the arrows
1121 long lRc = DLGC_WANTCHARS | DLGC_WANTARROWS;
1122
1123 // we may have several different cases:
1124 // 1. normal case: both TAB and ENTER are used for dialog navigation
1125 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
1126 // control in the dialog
1127 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
1128 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
1129 // the next control
1130 if ( m_windowStyle & wxTE_PROCESS_ENTER )
1131 lRc |= DLGC_WANTMESSAGE;
1132 if ( m_windowStyle & wxTE_PROCESS_TAB )
1133 lRc |= DLGC_WANTTAB;
39136494 1134
cd471848 1135 return lRc;
ae29de83
VZ
1136}
1137
2bda0e17
KB
1138void wxTextCtrl::OnEraseBackground(wxEraseEvent& event)
1139{
1140 if ( m_windowStyle & wxTE_MULTILINE )
1141 {
1142 // No flicker - only problem is we probably can't change the background
1143 Default();
1144/*
1145 RECT rect;
1146 ::GetClientRect((HWND) GetHWND(), &rect);
1147
1148 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
1149 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
1150
1151 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
1152 ::DeleteObject(hBrush);
1153 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
1154*/
1155 }
1156// wxWindow::OnEraseBackground(event);
1157}
1158
debe6624 1159bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
2bda0e17
KB
1160{
1161/*
1162 // Debugging
1163 wxDebugMsg("Edit control %d: ", (int)id);
1164 switch (param)
1165 {
1166 case EN_SETFOCUS:
1167 wxDebugMsg("EN_SETFOCUS\n");
1168 break;
1169 case EN_KILLFOCUS:
1170 wxDebugMsg("EN_KILLFOCUS\n");
1171 break;
1172 case EN_CHANGE:
1173 wxDebugMsg("EN_CHANGE\n");
1174 break;
1175 case EN_UPDATE:
1176 wxDebugMsg("EN_UPDATE\n");
1177 break;
1178 case EN_ERRSPACE:
1179 wxDebugMsg("EN_ERRSPACE\n");
1180 break;
1181 case EN_MAXTEXT:
1182 wxDebugMsg("EN_MAXTEXT\n");
1183 break;
1184 case EN_HSCROLL:
1185 wxDebugMsg("EN_HSCROLL\n");
1186 break;
1187 case EN_VSCROLL:
1188 wxDebugMsg("EN_VSCROLL\n");
1189 break;
1190 default:
1191 wxDebugMsg("Unknown EDIT notification\n");
1192 break;
1193 }
1194*/
2bda0e17
KB
1195 switch (param)
1196 {
1197 case EN_SETFOCUS:
2bda0e17 1198 case EN_KILLFOCUS:
ae29de83
VZ
1199 {
1200 wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
1201 : wxEVT_SET_FOCUS,
1202 m_windowId);
1203 event.SetEventObject( this );
02800301 1204 GetEventHandler()->ProcessEvent(event);
ae29de83 1205 }
2bda0e17 1206 break;
ae29de83 1207
2bda0e17 1208 case EN_CHANGE:
ae29de83
VZ
1209 {
1210 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
1211 wxString val(GetValue());
1212 if ( !val.IsNull() )
1213 event.m_commandString = WXSTRINGCAST val;
1214 event.SetEventObject( this );
1215 ProcessCommand(event);
1216 }
2bda0e17 1217 break;
ae29de83
VZ
1218
1219 // the other notification messages are not processed
1220 case EN_UPDATE:
2bda0e17 1221 case EN_ERRSPACE:
2bda0e17 1222 case EN_MAXTEXT:
2bda0e17 1223 case EN_HSCROLL:
2bda0e17 1224 case EN_VSCROLL:
2bda0e17 1225 default:
ae29de83 1226 return FALSE;
2bda0e17 1227 }
2bda0e17 1228
ae29de83
VZ
1229 // processed
1230 return TRUE;
2bda0e17
KB
1231}
1232
1233
1234// For Rich Edit controls. Do we need it?
1235#if 0
57c208c5 1236#if wxUSE_RICHEDIT
a23fd0e1 1237bool wxTextCtrl::MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 1238{
c085e333
VZ
1239 wxCommandEvent event(0, m_windowId);
1240 int eventType = 0;
1241 NMHDR *hdr1 = (NMHDR *) lParam;
1242 switch ( hdr1->code )
1243 {
1244 // Insert case code here
1245 default :
a23fd0e1 1246 return wxControl::MSWOnNotify(wParam, lParam);
c085e333
VZ
1247 break;
1248 }
1249
1250 event.SetEventObject( this );
1251 event.SetEventType(eventType);
1252
02800301 1253 if ( !GetEventHandler()->ProcessEvent(event) )
c085e333
VZ
1254 return FALSE;
1255
1256 return TRUE;
2bda0e17
KB
1257}
1258#endif
1259#endif
1260
e702ff0f
JS
1261void wxTextCtrl::OnCut(wxCommandEvent& event)
1262{
1263 Cut();
1264}
1265
1266void wxTextCtrl::OnCopy(wxCommandEvent& event)
1267{
1268 Copy();
1269}
1270
1271void wxTextCtrl::OnPaste(wxCommandEvent& event)
1272{
1273 Paste();
1274}
1275
1276void wxTextCtrl::OnUndo(wxCommandEvent& event)
1277{
1278 Undo();
1279}
1280
1281void wxTextCtrl::OnRedo(wxCommandEvent& event)
1282{
1283 Redo();
1284}
1285
1286void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
1287{
1288 event.Enable( CanCut() );
1289}
1290
1291void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
1292{
1293 event.Enable( CanCopy() );
1294}
1295
1296void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
1297{
1298 event.Enable( CanPaste() );
1299}
1300
1301void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
1302{
1303 event.Enable( CanUndo() );
1304}
1305
1306void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
1307{
1308 event.Enable( CanRedo() );
1309}
1310