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