]> git.saurik.com Git - wxWidgets.git/blame - src/os2/textctrl.cpp
Add ability to have a wxMenuBar as a common menu
[wxWidgets.git] / src / os2 / textctrl.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: textctrl.cpp
3// Purpose: wxTextCtrl
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d90895ac
DW
12// ----------------------------------------------------------------------------
13// headers
14// ----------------------------------------------------------------------------
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifndef WX_PRECOMP
20 #include "wx/textctrl.h"
19193a2c 21 #include "wx/scrolwin.h"
d90895ac
DW
22 #include "wx/settings.h"
23 #include "wx/brush.h"
24 #include "wx/utils.h"
25 #include "wx/log.h"
0e320a79
DW
26#endif
27
d90895ac
DW
28#if wxUSE_CLIPBOARD
29 #include "wx/app.h"
30 #include "wx/clipbrd.h"
31#endif
0e320a79 32
d90895ac
DW
33#include "wx/textfile.h"
34
35#include "wx/os2/private.h"
36
37#include <string.h>
38#include <stdlib.h>
39#include <sys/types.h>
0e320a79 40
d90895ac
DW
41#if wxUSE_IOSTREAMH
42# include <fstream.h>
0e320a79 43#else
d90895ac 44# include <fstream>
0e320a79
DW
45#endif
46
19193a2c 47#if !defined(MLE_INDEX)
a92d9721
SN
48#define MLE_INDEX 0
49#define MLE_RGB 1
50#endif
51
d90895ac
DW
52
53// ----------------------------------------------------------------------------
54// event tables and other macros
55// ----------------------------------------------------------------------------
56
0e320a79
DW
57IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
58
59BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
d90895ac
DW
60 EVT_CHAR(wxTextCtrl::OnChar)
61 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
62
0e320a79
DW
63 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
64 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
65 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
66 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
67 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
68
69 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
70 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
71 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
72 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
73 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
74END_EVENT_TABLE()
0e320a79 75
d90895ac
DW
76
77// ============================================================================
78// implementation
79// ============================================================================
80
81// ----------------------------------------------------------------------------
82// creation
83// ----------------------------------------------------------------------------
84
0e320a79 85wxTextCtrl::wxTextCtrl()
0e320a79 86{
0e320a79
DW
87}
88
2b5f62a0
VZ
89wxTextCtrl::~wxTextCtrl()
90{
91}
92
3bd418ca
DW
93bool wxTextCtrl::Create(
94 wxWindow* pParent
95, wxWindowID vId
96, const wxString& rsValue
97, const wxPoint& rPos
98, const wxSize& rSize
99, long lStyle
3bd418ca 100, const wxValidator& rValidator
3bd418ca
DW
101, const wxString& rsName
102)
103{
39c26ef2
DW
104 HWND hParent;
105 int nTempy;
cfcebdb1 106
3bd418ca
DW
107 //
108 // Base initialization
109 //
110 if ( !CreateBase( pParent
111 ,vId
112 ,rPos
113 ,rSize
114 ,lStyle
3bd418ca 115 ,rValidator
3bd418ca
DW
116 ,rsName
117 ))
d90895ac 118 return FALSE;
0e320a79 119
45bfc84b 120 wxPoint vPos = rPos; // The OS/2 position
5d44b24e 121 SWP vSwp;
45bfc84b 122
3bd418ca 123 if (pParent )
45bfc84b 124 {
3bd418ca 125 pParent->AddChild(this);
45bfc84b 126 }
0e320a79 127
3bd418ca 128 m_windowStyle = lStyle;
70a2c656 129 m_bIsMLE = FALSE;
d90895ac 130
3bd418ca
DW
131 long lSstyle = WS_VISIBLE | WS_TABSTOP;
132
133 //
134 // Single and multiline edit fields are two different controls in PM
135 //
d90895ac
DW
136 if ( m_windowStyle & wxTE_MULTILINE )
137 {
9c88ff79 138 lSstyle |= MLS_BORDER | MLS_WORDWRAP;
3bd418ca 139 m_bIsMLE = TRUE;
d90895ac 140
d90895ac 141 if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
3bd418ca
DW
142 lSstyle |= MLS_VSCROLL;
143 if (m_windowStyle & wxHSCROLL)
144 lSstyle |= MLS_HSCROLL;
145 if (m_windowStyle & wxTE_READONLY)
146 lSstyle |= MLS_READONLY;
d90895ac 147 }
0e320a79 148 else
3bd418ca 149 {
987da0d4 150 lSstyle |= ES_LEFT | ES_AUTOSCROLL | ES_MARGIN;
3bd418ca
DW
151
152 if (m_windowStyle & wxHSCROLL)
153 lSstyle |= ES_AUTOSCROLL;
154 if (m_windowStyle & wxTE_READONLY)
155 lSstyle |= ES_READONLY;
156 if (m_windowStyle & wxTE_PASSWORD) // hidden input
157 lSstyle |= ES_UNREADABLE;
158 }
5d44b24e 159
3bd418ca
DW
160 if (m_bIsMLE)
161 {
162 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
163 ,WC_MLE // Window class
164 ,(PSZ)rsValue.c_str() // Initial Text
165 ,(ULONG)lSstyle // Style flags
716ed225
DW
166 ,(LONG)0 // X pos of origin
167 ,(LONG)0 // Y pos of origin
168 ,(LONG)0 // field width
169 ,(LONG)0 // field height
3bd418ca
DW
170 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
171 ,HWND_TOP // initial z position
172 ,(ULONG)vId // Window identifier
173 ,NULL // no control data
174 ,NULL // no Presentation parameters
175 );
176 }
177 else
178 {
179 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
180 ,WC_ENTRYFIELD // Window class
181 ,(PSZ)rsValue.c_str() // Initial Text
182 ,(ULONG)lSstyle // Style flags
716ed225
DW
183 ,(LONG)0 // X pos of origin
184 ,(LONG)0 // Y pos of origin
185 ,(LONG)0 // field width
186 ,(LONG)0 // field height
3bd418ca
DW
187 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
188 ,HWND_TOP // initial z position
189 ,(ULONG)vId // Window identifier
190 ,NULL // no control data
191 ,NULL // no Presentation parameters
192 );
193 }
194
195 if (m_hWnd == 0)
196 {
197 return FALSE;
198 }
199
d90895ac
DW
200 SubclassWin(GetHWND());
201
3bd418ca
DW
202 //
203 // Set font, position, size and initial value
204 //
70a2c656 205 wxFont* pTextFont = new wxFont( 8
2c1e8f2e
DW
206 ,wxMODERN
207 ,wxNORMAL
208 ,wxNORMAL
209 );
210 SetFont(*pTextFont);
3bd418ca
DW
211 if (!rsValue.IsEmpty())
212 {
213 SetValue(rsValue);
214 }
215 SetupColours();
5d44b24e
DW
216 //
217 // If X and/or Y are not zero the difference is the compensation value
218 // for margins for OS/2 controls.
219 //
220 ::WinQueryWindowPos(m_hWnd, &vSwp);
221 SetXComp(vSwp.x);
222 SetYComp(vSwp.y);
70a2c656
DW
223 SetSize( vPos.x - GetXComp()
224 ,vPos.y - GetYComp()
3bd418ca
DW
225 ,rSize.x
226 ,rSize.y
227 );
b3260bce 228 delete pTextFont;
0e320a79 229 return TRUE;
3bd418ca 230} // end of wxTextCtrl::Create
0e320a79 231
3bd418ca 232//
d90895ac 233// Make sure the window style (etc.) reflects the HWND style (roughly)
3bd418ca 234//
d90895ac
DW
235void wxTextCtrl::AdoptAttributesFromHWND()
236{
3bd418ca
DW
237 HWND hWnd = GetHwnd();
238 LONG lStyle = ::WinQueryWindowULong(hWnd, QWL_STYLE);
d90895ac 239
3bd418ca 240 wxWindow::AdoptAttributesFromHWND();
d90895ac 241
3bd418ca
DW
242 if (m_bIsMLE)
243 {
244 m_windowStyle |= wxTE_MULTILINE;
245 if (lStyle & MLS_READONLY)
246 m_windowStyle |= wxTE_READONLY;
247 }
248 else
249 {
250 if (lStyle & ES_UNREADABLE)
251 m_windowStyle |= wxTE_PASSWORD;
252 if (lStyle & ES_READONLY)
253 m_windowStyle |= wxTE_READONLY;
254 }
c4955899 255} // end of wxTextCtrl::AdoptAttributesFromHWND
d90895ac 256
b9b1d6c8
DW
257WXDWORD wxTextCtrl::OS2GetStyle(
258 long lStyle
259, WXDWORD* pdwExstyle
260) const
261{
262 //
263 // Default border for the text controls is the sunken one
264 //
265 if ((lStyle & wxBORDER_MASK) == wxBORDER_DEFAULT )
266 {
267 lStyle |= wxBORDER_SUNKEN;
268 }
269
270 long dwStyle = wxControl::OS2GetStyle( lStyle
271 ,pdwExstyle
272 );
273
274 dwStyle = WS_VISIBLE | WS_TABSTOP;
275
276 //
277 // Single and multiline edit fields are two different controls in PM
278 //
279 if ( m_windowStyle & wxTE_MULTILINE )
280 {
281 dwStyle |= MLS_BORDER | MLS_WORDWRAP;
282 if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
283 dwStyle |= MLS_VSCROLL;
284 if (m_windowStyle & wxHSCROLL)
285 dwStyle |= MLS_HSCROLL;
286 if (m_windowStyle & wxTE_READONLY)
287 dwStyle |= MLS_READONLY;
288 }
289 else
290 {
291 dwStyle |= ES_LEFT | ES_AUTOSCROLL | ES_MARGIN;
292 if (m_windowStyle & wxHSCROLL)
293 dwStyle |= ES_AUTOSCROLL;
294 if (m_windowStyle & wxTE_READONLY)
295 dwStyle |= ES_READONLY;
296 if (m_windowStyle & wxTE_PASSWORD) // hidden input
297 dwStyle |= ES_UNREADABLE;
298 }
299 return dwStyle;
300} // end of wxTextCtrl::OS2GetStyle
301
302void wxTextCtrl::SetWindowStyleFlag(
303 long lStyle
304)
305{
306 wxControl::SetWindowStyleFlag(lStyle);
307} // end of wxTextCtrl::SetWindowStyleFlag
308
d90895ac
DW
309void wxTextCtrl::SetupColours()
310{
c4955899
DW
311 wxColour vBkgndColour;
312
a756f210 313 vBkgndColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
c4955899 314 SetBackgroundColour(vBkgndColour);
d90895ac 315 SetForegroundColour(GetParent()->GetForegroundColour());
9c88ff79
DW
316 if (m_bIsMLE)
317 {
318 ::WinSendMsg( GetHwnd()
319 ,MLM_SETTEXTCOLOR
320 ,(MPARAM)GetParent()->GetForegroundColour().GetPixel()
321 ,(MPARAM)MLE_RGB
322 );
323 }
c4955899 324} // end of wxTextCtrl::SetupColours
d90895ac
DW
325
326// ----------------------------------------------------------------------------
327// set/get the controls text
328// ----------------------------------------------------------------------------
329
0e320a79
DW
330wxString wxTextCtrl::GetValue() const
331{
c4955899
DW
332 wxString sStr = wxGetWindowText(GetHWND());
333 char* zStr = (char*)sStr.c_str();
d90895ac 334
c4955899
DW
335 for ( ; *zStr; zStr++ )
336 {
337 //
338 // this will replace \r\n with just \n
339 //
340 if (*zStr == '\n')
341 *zStr = '\0';
342 if (*zStr == '\r')
343 *zStr = '\n';
344 }
c4955899
DW
345 return sStr;
346} // end of wxTextCtrl::GetValue
0e320a79 347
c4955899
DW
348void wxTextCtrl::SetValue(
349 const wxString& rsValue
350)
0e320a79 351{
c4955899
DW
352 //
353 // If the text is long enough, it's faster to just set it instead of first
354 // comparing it with the old one (chances are that it will be different
355 // anyhow, this comparison is there to avoid flicker for small single-line
356 // edit controls mostly)
357 //
358 if ((rsValue.length() > 0x400) || (rsValue != GetValue()))
359 {
360 ::WinSetWindowText(GetHwnd(), rsValue.c_str());
361 AdjustSpaceLimit();
362 }
363} // end of wxTextCtrl::SetValue
d90895ac 364
c4955899
DW
365void wxTextCtrl::WriteText(
366 const wxString& rsValue
367)
368{
b3260bce
DW
369 if (m_bIsMLE)
370 ::WinSendMsg(GetHwnd(), MLM_INSERT, MPARAM((PCHAR)rsValue.c_str()), MPARAM(0));
371 else
372 ::WinSetWindowText(GetHwnd(), rsValue.c_str());
d90895ac 373 AdjustSpaceLimit();
c4955899 374} // end of wxTextCtrl::WriteText
0e320a79 375
c4955899
DW
376void wxTextCtrl::AppendText(
377 const wxString& rsText
378)
d90895ac 379{
d90895ac 380 SetInsertionPointEnd();
c4955899
DW
381 WriteText(rsText);
382} // end of wxTextCtrl::AppendText
d90895ac
DW
383
384void wxTextCtrl::Clear()
385{
c4955899
DW
386 ::WinSetWindowText(GetHwnd(), "");
387} // end of wxTextCtrl::Clear
d90895ac 388
a086de98
DW
389bool wxTextCtrl::EmulateKeyPress(
390 const wxKeyEvent& rEvent
391)
392{
393 SetFocus();
394 return(wxTextCtrlBase::EmulateKeyPress(rEvent));
395} // end of wxTextCtrl::EmulateKeyPress
396
d90895ac 397// ----------------------------------------------------------------------------
0e320a79 398// Clipboard operations
d90895ac
DW
399// ----------------------------------------------------------------------------
400
0e320a79
DW
401void wxTextCtrl::Copy()
402{
d90895ac
DW
403 if (CanCopy())
404 {
405 HWND hWnd = GetHwnd();
3bd418ca
DW
406 if (m_bIsMLE)
407 ::WinSendMsg(hWnd, MLM_COPY, 0, 0);
408 else
409 ::WinSendMsg(hWnd, EM_COPY, 0, 0);
d90895ac 410 }
3bd418ca 411} // end of wxTextCtrl::Copy
0e320a79
DW
412
413void wxTextCtrl::Cut()
414{
d90895ac
DW
415 if (CanCut())
416 {
417 HWND hWnd = GetHwnd();
3bd418ca
DW
418
419 if (m_bIsMLE)
420 ::WinSendMsg(hWnd, MLM_CUT, 0, 0);
421 else
422 ::WinSendMsg(hWnd, EM_CUT, 0, 0);
d90895ac 423 }
c4955899 424} // end of wxTextCtrl::Cut
0e320a79
DW
425
426void wxTextCtrl::Paste()
427{
d90895ac
DW
428 if (CanPaste())
429 {
c4955899
DW
430 HWND hWnd = GetHwnd();
431
432 ::WinSendMsg(hWnd, EM_PASTE, 0, 0);
d90895ac 433 }
c4955899 434} // end of wxTextCtrl::Paste
d90895ac
DW
435
436bool wxTextCtrl::CanCopy() const
437{
c4955899 438 //
d90895ac 439 // Can copy if there's a selection
c4955899
DW
440 //
441 long lFrom = 0L;
442 long lTo = 0L;
443
444 GetSelection(&lFrom, &lTo);
445 return (lFrom != lTo);
446} // end of wxTextCtrl::CanCopy
d90895ac
DW
447
448bool wxTextCtrl::CanCut() const
449{
c4955899 450 //
d90895ac 451 // Can cut if there's a selection
c4955899
DW
452 //
453 long lFrom = 0L;
454 long lTo = 0L;
455
456 GetSelection(&lFrom, &lTo);
457 return (lFrom != lTo);
458} // end of wxTextCtrl::CanCut
d90895ac
DW
459
460bool wxTextCtrl::CanPaste() const
461{
3bd418ca
DW
462 bool bIsTextAvailable = FALSE;
463
d90895ac
DW
464 if (!IsEditable())
465 return FALSE;
466
3bd418ca
DW
467 //
468 // Check for straight text on clipboard
469 //
470 if (::WinOpenClipbrd(vHabmain))
d90895ac 471 {
3bd418ca
DW
472 bIsTextAvailable = (::WinQueryClipbrdData(vHabmain, CF_TEXT) != 0);
473 ::WinCloseClipbrd(vHabmain);
d90895ac 474 }
3bd418ca
DW
475 return bIsTextAvailable;
476} // end of wxTextCtrl::CanPaste
0e320a79 477
d90895ac
DW
478// ----------------------------------------------------------------------------
479// Accessors
480// ----------------------------------------------------------------------------
481
c4955899
DW
482void wxTextCtrl::SetEditable(
483 bool bEditable
484)
0e320a79 485{
c4955899
DW
486 HWND hWnd = GetHwnd();
487
488 if (m_bIsMLE)
489 ::WinSendMsg(hWnd, MLM_SETREADONLY, MPFROMLONG(!bEditable), (MPARAM)0);
490 else
491 ::WinSendMsg(hWnd, EM_SETREADONLY, MPFROMLONG(!bEditable), (MPARAM)0);
492} // end of wxTextCtrl::SetEditable
0e320a79 493
c4955899
DW
494void wxTextCtrl::SetInsertionPoint(
495 long lPos
496)
0e320a79 497{
c4955899
DW
498 HWND hWnd = GetHwnd();
499
500 if (m_bIsMLE)
501 ::WinSendMsg(hWnd, MLM_SETSEL, (MPARAM)lPos, (MPARAM)lPos);
502 else
503 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lPos, (USHORT)lPos), (MPARAM)0);
504} // end of wxTextCtrl::SetInsertionPoint
0e320a79
DW
505
506void wxTextCtrl::SetInsertionPointEnd()
507{
c4955899
DW
508 long lPos = GetLastPosition();
509
6e348b12
DW
510 //
511 // We must not do anything if the caret is already there because calling
512 // SetInsertionPoint() thaws the controls if Freeze() had been called even
513 // if it doesn't actually move the caret anywhere and so the simple fact of
514 // doing it results in horrible flicker when appending big amounts of text
515 // to the control in a few chunks (see DoAddText() test in the text sample)
516 //
517 if (GetInsertionPoint() == GetLastPosition())
518 return;
c4955899
DW
519 SetInsertionPoint(lPos);
520} // end of wxTextCtrl::SetInsertionPointEnd
0e320a79
DW
521
522long wxTextCtrl::GetInsertionPoint() const
523{
3bd418ca
DW
524 WXDWORD dwPos = 0L;
525
526 if (m_bIsMLE)
527 dwPos = (WXDWORD)::WinSendMsg(GetHwnd(), MLM_QUERYSEL, (MPARAM)MLFQS_MINSEL, 0);
528 else
529 {
530 dwPos = (WXDWORD)::WinSendMsg(GetHwnd(), EM_QUERYSEL, 0, 0);
531 dwPos = SHORT1FROMMP((MPARAM)dwPos); // the first 16 bit value is the min pos
532 }
533 return (dwPos & 0xFFFF);
534} // end of wxTextCtrl::GetInsertionPoint
0e320a79
DW
535
536long wxTextCtrl::GetLastPosition() const
537{
3bd418ca
DW
538 HWND hWnd = GetHwnd();
539 long lCharIndex;
540 long lLineLength;
0e320a79 541
3bd418ca
DW
542 if (m_bIsMLE)
543 {
544 lCharIndex = 0;
d90895ac 545
3bd418ca
DW
546 //
547 // This just gets the total text length. The last will be this value
548 //
549 lLineLength = (long)::WinSendMsg(hWnd, MLM_QUERYTEXTLENGTH, 0, 0);
550 }
551 else
552 {
553 WNDPARAMS vParams;
554
555 lCharIndex = 0;
556 vParams.fsStatus = WPM_CCHTEXT;
557 if (::WinSendMsg( GetHwnd()
558 ,WM_QUERYWINDOWPARAMS
559 ,&vParams
560 ,0
561 ))
562 {
563 lLineLength = (long)vParams.cchText;
564 }
565 else
566 lLineLength = 0;
567 }
568 return(lCharIndex + lLineLength);
569} // end of wxTextCtrl::GetLastPosition
0e320a79 570
d90895ac
DW
571// If the return values from and to are the same, there is no
572// selection.
c4955899
DW
573void wxTextCtrl::GetSelection(
574 long* plFrom
575, long* plTo
576) const
0e320a79 577{
c4955899 578 WXDWORD dwPos;
0e320a79 579
c4955899
DW
580 if (m_bIsMLE)
581 dwPos = (WXDWORD)::WinSendMsg(GetHwnd(), MLM_QUERYSEL, (MPARAM)MLFQS_MINSEL, 0);
582 else
583 {
584 dwPos = (WXDWORD)::WinSendMsg(GetHwnd(), EM_QUERYSEL, 0, 0);
585 }
586 *plFrom = SHORT1FROMMP((MPARAM)dwPos); // the first 16 bit value is the min pos
587 *plTo = SHORT2FROMMP((MPARAM)dwPos); // the first 16 bit value is the min pos
588} // end of wxTextCtrl::GetSelection
0e320a79 589
d90895ac
DW
590bool wxTextCtrl::IsEditable() const
591{
c4955899
DW
592 if (m_bIsMLE)
593 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY, 0, 0)));
594 else
595 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY, 0, 0)));
596} // end of wxTextCtrl::IsEditable
0e320a79 597
d90895ac
DW
598// ----------------------------------------------------------------------------
599// Editing
600// ----------------------------------------------------------------------------
601
c4955899
DW
602void wxTextCtrl::Replace(
603 long lFrom
604, long lTo
605, const wxString& rsValue
606)
0e320a79 607{
d90895ac 608#if wxUSE_CLIPBOARD
c4955899
DW
609 HWND hWnd = GetHwnd();
610 long lFromChar = lFrom;
611 long lToChar = lTo;
0e320a79 612
c4955899 613 //
d90895ac 614 // Set selection and remove it
c4955899
DW
615 //
616 if (m_bIsMLE)
617 {
618 ::WinSendMsg(hWnd, MLM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
619 ::WinSendMsg(hWnd, MLM_CUT, 0, 0);
620 }
621 else
622 {
623 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
624 ::WinSendMsg(hWnd, EM_CUT, 0, 0);
625 }
0e320a79 626
c4955899 627 //
d90895ac 628 // Now replace with 'value', by pasting.
c4955899
DW
629 //
630 wxSetClipboardData(wxDF_TEXT, (wxObject *) (const wxChar *)rsValue, 0, 0);
0e320a79 631
d90895ac 632 // Paste into edit control
c4955899
DW
633 if (m_bIsMLE)
634 ::WinSendMsg(hWnd, MLM_PASTE, (MPARAM)0, (MPARAM)0);
635 else
636 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0);
d90895ac
DW
637#else
638 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
639#endif
c4955899 640} // end of wxTextCtrl::Replace
0e320a79 641
c4955899
DW
642void wxTextCtrl::Remove(
643 long lFrom
644, long lTo
645)
0e320a79 646{
c4955899
DW
647 HWND hWnd = GetHwnd();
648 long lFromChar = lFrom;
649 long lToChar = lTo;
d90895ac 650
c4955899
DW
651 if (m_bIsMLE)
652 {
653 ::WinSendMsg(hWnd, MLM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
654 ::WinSendMsg(hWnd, MLM_CUT, 0, 0);
655 }
656 else
657 {
658 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
659 ::WinSendMsg(hWnd, EM_CUT, 0, 0);
660 }
661} // end of wxTextCtrl::Remove
0e320a79 662
c4955899
DW
663void wxTextCtrl::SetSelection(
664 long lFrom
665, long lTo
666)
0e320a79 667{
c4955899
DW
668 HWND hWnd = GetHwnd();
669 long lFromChar = lFrom;
670 long lToChar = lTo;
d90895ac 671
c4955899
DW
672 //
673 // If from and to are both -1, it means (in wxWindows) that all text should
d90895ac 674 // be selected. Translate into Windows convention
c4955899
DW
675 //
676 if ((lFrom == -1L) && (lTo == -1L))
d90895ac 677 {
c4955899
DW
678 lFromChar = 0L;
679 lToChar = -1L;
d90895ac 680 }
c4955899
DW
681 if (m_bIsMLE)
682 ::WinSendMsg(hWnd, MLM_SETSEL, (MPARAM)lFromChar, (MPARAM)lToChar);
683 else
684 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar), (MPARAM)0);
685} // end of wxTextCtrl::SetSelection
d90895ac 686
c4955899
DW
687bool wxTextCtrl::LoadFile(
688 const wxString& rsFile
689)
0e320a79 690{
c4955899 691 if ( wxTextCtrlBase::LoadFile(rsFile) )
d90895ac 692 {
c4955899
DW
693 //
694 // Update the size limit if needed
695 //
d90895ac 696 AdjustSpaceLimit();
d90895ac
DW
697 return TRUE;
698 }
d90895ac 699 return FALSE;
c4955899 700} // end of wxTextCtrl::LoadFile
0e320a79
DW
701
702bool wxTextCtrl::IsModified() const
703{
c4955899
DW
704 bool bRc;
705
706 if (m_bIsMLE)
707 bRc = (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED, 0, 0));
708 else
709 bRc = (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED, 0, 0));
710 return bRc;
711} // end of wxTextCtrl::IsModified
0e320a79 712
3bd418ca 713//
0e320a79 714// Makes 'unmodified'
3bd418ca 715//
0e320a79
DW
716void wxTextCtrl::DiscardEdits()
717{
3bd418ca
DW
718 if (m_bIsMLE)
719 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED, MPFROMLONG(FALSE), 0);
720 else
721 //
722 // EM controls do not have a SETCHANGED but issuing a query should reset it
723 //
724 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED, 0, 0);
725} // end of wxTextCtrl::DiscardEdits
0e320a79
DW
726
727int wxTextCtrl::GetNumberOfLines() const
728{
c4955899 729 int nNumLines;
0e320a79 730
c4955899
DW
731 if (m_bIsMLE)
732 nNumLines = (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT, 0, 0);
733 else
734 nNumLines = 1;
735 return nNumLines;
736} // end of wxTextCtrl::GetNumberOfLines
d90895ac 737
c4955899
DW
738long wxTextCtrl::XYToPosition(
739 long lX
740, long lY
741) const
742{
743 HWND hWnd = GetHwnd();
744 long lCharIndex = 0L;
745 long lLen;
0e320a79 746
c4955899
DW
747 if (m_bIsMLE)
748 {
749 lLen = (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH, 0, 0);
750 lCharIndex = ((lLen * lY) + lX);
751 }
752 else
753 lCharIndex = lX;
754 return lCharIndex;
755} // end of wxTextCtrl::XYToPosition
756
757bool wxTextCtrl::PositionToXY(
758 long lPos
759, long* plX
760, long* plY
761) const
0e320a79 762{
c4955899
DW
763 HWND hWnd = GetHwnd();
764 long nLineNo = -1;
765 long lCharIndex = 0;
d90895ac 766
c4955899
DW
767 if (m_bIsMLE)
768 nLineNo = (long)::WinSendMsg(hWnd, MLM_LINEFROMCHAR, (MPARAM)lPos, 0);
769 else
770 nLineNo = 0;
d90895ac 771
c4955899 772 if (nLineNo == -1)
d90895ac
DW
773 {
774 // no such line
775 return FALSE;
776 }
777
c4955899 778 //
d90895ac 779 // This gets the char index for the _beginning_ of this line
c4955899
DW
780 //
781 long lLineWidth;
782
783 if (m_bIsMLE)
784 {
785 lLineWidth = (long)::WinSendMsg(hWnd, MLM_QUERYLINELENGTH, (MPARAM)0, (MPARAM)0);
786 lCharIndex = (nLineNo + 1) * lLineWidth;
787 }
788 else
789 {
790 WNDPARAMS vParams;
791
792 vParams.fsStatus = WPM_CCHTEXT;
793 if (::WinSendMsg( hWnd
794 ,WM_QUERYWINDOWPARAMS
795 ,&vParams
796 ,0
797 ))
798 {
799 lCharIndex = vParams.cchText;
800 }
801 else
802 lCharIndex = 32;
803 }
804
805 if (lCharIndex == -1)
d90895ac
DW
806 {
807 return FALSE;
808 }
809
c4955899
DW
810 //
811 // The X position must therefore be the difference between pos and charIndex
812 //
813 if (plX)
814 *plX = lPos - lCharIndex;
815 if (plY)
816 *plY = nLineNo;
d90895ac
DW
817
818 return TRUE;
c4955899 819} // end of wxTextCtrl::PositionToXY
0e320a79 820
c4955899
DW
821void wxTextCtrl::ShowPosition(
822 long lPos
823)
0e320a79 824{
c4955899
DW
825 HWND hWnd = GetHwnd();
826 long lCurrentLineLineNo = 0L;
d90895ac
DW
827
828 // To scroll to a position, we pass the number of lines and characters
829 // to scroll *by*. This means that we need to:
830 // (1) Find the line position of the current line.
831 // (2) Find the line position of pos.
832 // (3) Scroll by (pos - current).
833 // For now, ignore the horizontal scrolling.
834
c4955899 835 //
d90895ac
DW
836 // Is this where scrolling is relative to - the line containing the caret?
837 // Or is the first visible line??? Try first visible line.
c4955899
DW
838 //
839 if (m_bIsMLE)
840 {
841 //
842 // In PM this is the actual char position
843 //
844 lCurrentLineLineNo = (long)::WinSendMsg(hWnd, MLM_QUERYFIRSTCHAR, (MPARAM)0, (MPARAM)0);
d90895ac 845
c4955899
DW
846 //
847 // This will cause a scroll to the selected position
848 //
849 ::WinSendMsg(hWnd, MLM_SETSEL, (MPARAM)lCurrentLineLineNo, (MPARAM)lCurrentLineLineNo);
850 }
851} // end of wxTextCtrl::ShowPosition
0e320a79 852
3bd418ca
DW
853int wxTextCtrl::GetLineLength(
854 long lLineNo
855) const
0e320a79 856{
3bd418ca 857 long lLen = 0L;
d90895ac 858
3bd418ca
DW
859 if (m_bIsMLE)
860 lLen = (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH, 0, 0);
861 else
862 {
863 WNDPARAMS vParams;
864
865 vParams.fsStatus = WPM_CCHTEXT;
866 if (::WinSendMsg( GetHwnd()
867 ,WM_QUERYWINDOWPARAMS
868 ,&vParams
869 ,0
870 ))
871 {
872 lLen = vParams.cchText;
873 }
874 else
875 lLen = 32;
876 }
877 return lLen;
c4955899 878} // end ofwxTextCtrl::GetLineLength
0e320a79 879
c4955899
DW
880wxString wxTextCtrl::GetLineText(
881 long lLineNo
882) const
0e320a79 883{
c4955899
DW
884 long lLen = (long)GetLineLength((long)lLineNo) + 1;
885 wxString sStr;
886 char* zBuf;
0e320a79 887
c4955899
DW
888 //
889 // There must be at least enough place for the length WORD in the
890 // buffer
891 //
892 lLen += sizeof(WORD);
893 zBuf = new char[lLen];
894 if (m_bIsMLE)
895 {
896 long lIndex;
897 long lBuflen;
898 long lCopied;
0e320a79 899
c4955899
DW
900 lLen = (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH, 0, 0);
901 lIndex = lLen * lLineNo;
0e320a79 902
c4955899
DW
903 ::WinSendMsg(GetHwnd(), MLM_SETSEL, (MPARAM)lIndex, (MPARAM)lIndex);
904 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT, MPFROMP(zBuf), MPFROMSHORT((USHORT)sizeof(zBuf)));
905 lBuflen = (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH, MPFROMLONG(lIndex), MPFROMLONG(-1));
906 lCopied = (long)::WinSendMsg(GetHwnd(), MLM_EXPORT, MPFROMP(&lIndex), MPFROMP(&lBuflen));
907 zBuf[lCopied] = '\0';
908 }
909 else
910 {
911 WNDPARAMS vParams;
912
913 vParams.fsStatus = WPM_CCHTEXT;
914 if (::WinSendMsg( GetHwnd()
915 ,WM_QUERYWINDOWPARAMS
916 ,&vParams
917 ,0
918 ))
919 memcpy(zBuf, vParams.pszText, vParams.cchText);
920 zBuf[vParams.cchText] = '\0';
921 }
922 sStr = zBuf;
923 delete [] zBuf;
924 return sStr;
925} // end of wxTextCtrl::GetLineText
0e320a79 926
d90895ac 927// ----------------------------------------------------------------------------
0e320a79 928// Undo/redo
d90895ac
DW
929// ----------------------------------------------------------------------------
930
0e320a79
DW
931void wxTextCtrl::Undo()
932{
d90895ac
DW
933 if (CanUndo())
934 {
c4955899
DW
935 if (m_bIsMLE)
936 ::WinSendMsg(GetHwnd(), MLM_UNDO, 0, 0);
937 // Simple entryfields cannot be undone
d90895ac 938 }
c4955899 939} // end of wxTextCtrl::Undo
0e320a79
DW
940
941void wxTextCtrl::Redo()
942{
d90895ac
DW
943 if (CanRedo())
944 {
c4955899
DW
945 if (m_bIsMLE)
946 ::WinSendMsg(GetHwnd(), MLM_UNDO, 0, 0);
947 // Simple entryfields cannot be undone
d90895ac 948 }
c4955899 949} // end of wxTextCtrl::Redo
0e320a79
DW
950
951bool wxTextCtrl::CanUndo() const
952{
3bd418ca
DW
953 bool bOk;
954
955 if (m_bIsMLE)
956 bOk = (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO, 0, 0) != 0);
957 else
958 bOk = FALSE; // can't undo regular edit fields in PM
959 return bOk;
960} // end of wxTextCtrl::CanUndo
0e320a79
DW
961
962bool wxTextCtrl::CanRedo() const
963{
3bd418ca
DW
964 bool bOk;
965
966 if (m_bIsMLE)
967 bOk = (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO, 0, 0) != 0);
968 else
969 bOk = FALSE; // can't undo regular edit fields in PM
970 return bOk;
971} // end of wxTextCtrl::CanRedo
0e320a79 972
d90895ac
DW
973// ----------------------------------------------------------------------------
974// implemenation details
975// ----------------------------------------------------------------------------
0e320a79 976
c4955899
DW
977void wxTextCtrl::Command(
978 wxCommandEvent& rEvent
979)
0e320a79 980{
c4955899
DW
981 SetValue(rEvent.GetString());
982 ProcessCommand (rEvent);
983} // end of wxTextCtrl::Command
0e320a79 984
c4955899
DW
985void wxTextCtrl::OnDropFiles(
986 wxDropFilesEvent& rEvent
987)
0e320a79
DW
988{
989 // By default, load the first file into the text window.
c4955899 990 if (rEvent.GetNumberOfFiles() > 0)
0e320a79 991 {
c4955899 992 LoadFile(rEvent.GetFiles()[0]);
0e320a79 993 }
c4955899
DW
994} // end of wxTextCtrl::OnDropFiles
995
996WXHBRUSH wxTextCtrl::OnCtlColor(
997 WXHDC hWxDC
998, WXHWND hWnd
999, WXUINT uCtlColor
1000, WXUINT uMessage
1001, WXWPARAM wParam
1002, WXLPARAM lParam
1003)
d90895ac 1004{
c4955899
DW
1005 HPS hPS = (HPS)hWxDC;
1006 wxBrush* pBrush = NULL;
1007 wxColour vColBack = GetBackgroundColour();
1008 wxColour vColFore = GetForegroundColour();
1009 wxBrush* pBackgroundBrush = wxTheBrushList->FindOrCreateBrush( GetBackgroundColour()
1010 ,wxSOLID
1011 );
1012
1013 if (m_bUseCtl3D)
1014 {
1015 HBRUSH hBrush = NULLHANDLE;
0e320a79 1016
c4955899
DW
1017 return hBrush;
1018 }
1019 if (GetParent()->GetTransparentBackground())
1020 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
1021 else
1022 ::GpiSetBackMix(hPS, BM_OVERPAINT);
1023 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE) == 0)
a756f210 1024 vColBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
c4955899
DW
1025 ::GpiSetBackColor(hPS, vColBack.GetPixel());
1026 ::GpiSetColor(hPS, vColFore.GetPixel());
1027 return (WXHBRUSH)pBackgroundBrush->GetResourceHandle();
1028} // end of wxTextCtrl::OnCtlColor
1029
54ffa107
DW
1030bool wxTextCtrl::OS2ShouldPreProcessMessage(
1031 WXMSG* pMsg
1032)
1033{
1034 return wxControl::OS2ShouldPreProcessMessage(pMsg);
1035} // end of wxTextCtrl::OS2ShouldPreProcessMessage
1036
c4955899
DW
1037void wxTextCtrl::OnChar(
1038 wxKeyEvent& rEvent
1039)
0e320a79 1040{
c4955899 1041 switch (rEvent.KeyCode())
d90895ac 1042 {
d90895ac
DW
1043 case WXK_RETURN:
1044 if ( !(m_windowStyle & wxTE_MULTILINE) )
1045 {
c4955899
DW
1046 wxCommandEvent vEvent(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
1047
1048 vEvent.SetEventObject(this);
1049 if ( GetEventHandler()->ProcessEvent(vEvent))
d90895ac
DW
1050 return;
1051 }
1052 //else: multiline controls need Enter for themselves
1053
1054 break;
1055
1056 case WXK_TAB:
1057 // always produce navigation event - even if we process TAB
1058 // ourselves the fact that we got here means that the user code
1059 // decided to skip processing of this TAB - probably to let it
1060 // do its default job.
1061 //
1062 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1063 // handled by Windows
1064 {
c4955899 1065 wxNavigationKeyEvent vEventNav;
d90895ac 1066
c4955899
DW
1067 vEventNav.SetDirection(!rEvent.ShiftDown());
1068 vEventNav.SetWindowChange(FALSE);
1069 vEventNav.SetEventObject(this);
1070
1071 if ( GetEventHandler()->ProcessEvent(vEventNav) )
d90895ac
DW
1072 return;
1073 }
1074 break;
d90895ac 1075 }
c4955899
DW
1076 rEvent.Skip();
1077} // end of wxTextCtrl::OnChar
0e320a79 1078
c4955899
DW
1079bool wxTextCtrl::OS2Command(
1080 WXUINT uParam
1081, WXWORD WXUNUSED(vId)
1082)
0e320a79 1083{
c4955899 1084 switch (uParam)
d90895ac 1085 {
d90895ac
DW
1086 case EN_SETFOCUS:
1087 case EN_KILLFOCUS:
1088 {
c4955899
DW
1089 wxFocusEvent vEvent( uParam == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
1090 : wxEVT_SET_FOCUS
1091 ,m_windowId
1092 );
1093
1094 vEvent.SetEventObject(this);
1095 GetEventHandler()->ProcessEvent(vEvent);
d90895ac
DW
1096 }
1097 break;
1098
1099 case EN_CHANGE:
1100 {
c4955899
DW
1101 wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED
1102 ,m_windowId
1103 );
1104
1105 InitCommandEvent(vEvent);
1106 vEvent.SetString((char*)GetValue().c_str());
1107 ProcessCommand(vEvent);
d90895ac
DW
1108 }
1109 break;
1110
c4955899
DW
1111 case EN_OVERFLOW:
1112 //
1113 // The text size limit has been hit - increase it
1114 //
d90895ac
DW
1115 AdjustSpaceLimit();
1116 break;
1117
c4955899
DW
1118 case EN_SCROLL:
1119 case EN_INSERTMODETOGGLE:
1120 case EN_MEMERROR:
1121 return FALSE;
d90895ac
DW
1122 default:
1123 return FALSE;
1124 }
1125
c4955899
DW
1126 //
1127 // Processed
1128 //
d90895ac 1129 return TRUE;
c4955899 1130} // end of wxTextCtrl::OS2Command
0e320a79 1131
d90895ac 1132void wxTextCtrl::AdjustSpaceLimit()
0e320a79 1133{
3bd418ca
DW
1134 unsigned int uLen = 0;
1135 unsigned int uLimit = 0;
d90895ac 1136
3bd418ca
DW
1137 uLen = ::WinQueryWindowTextLength(GetHwnd());
1138 if (m_bIsMLE)
1139 {
1140 uLimit = (unsigned int)::WinSendMsg( GetHwnd()
1141 ,MLM_QUERYTEXTLIMIT
1142 ,0
1143 ,0
1144 );
1145 }
1146 else
1147 {
1148 ENTRYFDATA* pEfd;
1149 WNDPARAMS vParams;
1150
1151 vParams.fsStatus = WPM_CBCTLDATA;
1152 vParams.cbCtlData = sizeof(ENTRYFDATA);
1153
1154 if (::WinSendMsg( GetHwnd()
1155 ,WM_QUERYWINDOWPARAMS
1156 ,&vParams
1157 ,0
1158 ))
1159 {
1160 pEfd = (ENTRYFDATA*)vParams.pCtlData;
1161 uLimit = (unsigned int)pEfd->cchEditLimit;
1162 }
d90895ac 1163 else
3bd418ca 1164 uLimit = 32; //PM's default
d90895ac 1165 }
3bd418ca
DW
1166 if (uLen >= uLimit)
1167 {
1168 uLimit = uLen + 0x8000; // 32Kb
1169 if (uLimit > 0xffff)
1170 {
1171 uLimit = 0L;
1172 }
1173 if (m_bIsMLE)
1174 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT, MPFROMLONG(uLimit), 0);
1175 else
1176 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT, MPFROMLONG(uLimit), 0);
1177 }
1178} // end of wxTextCtrl::AdjustSpaceLimit
0e320a79 1179
d90895ac 1180bool wxTextCtrl::AcceptsFocus() const
0e320a79 1181{
c4955899 1182 //
57ff8a87
DW
1183 // We don't want focus if we can't be edited unless we're a multiline
1184 // control because then it might be still nice to get focus from keyboard
1185 // to be able to scroll it without mouse
c4955899 1186 //
57ff8a87 1187 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
c4955899 1188} // end of wxTextCtrl::Command
0e320a79 1189
e78c4d50 1190wxSize wxTextCtrl::DoGetBestSize() const
0e320a79 1191{
c4955899
DW
1192 int nCx;
1193 int nCy;
0e320a79 1194
c4955899 1195 wxGetCharSize(GetHWND(), &nCx, &nCy, (wxFont*)&GetFont());
d90895ac 1196
c4955899 1197 int wText = DEFAULT_ITEM_WIDTH;
987da0d4 1198 int hText = (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * .8);
c4955899
DW
1199
1200 if (m_windowStyle & wxTE_MULTILINE)
d90895ac 1201 {
239c2e96 1202 hText *= wxMax(GetNumberOfLines(), 5);
d90895ac
DW
1203 }
1204 //else: for single line control everything is ok
d90895ac 1205 return wxSize(wText, hText);
c4955899 1206} // end of wxTextCtrl::DoGetBestSize
0e320a79 1207
d90895ac
DW
1208// ----------------------------------------------------------------------------
1209// standard handlers for standard edit menu events
1210// ----------------------------------------------------------------------------
1211
c4955899
DW
1212void wxTextCtrl::OnCut(
1213 wxCommandEvent& rEvent
1214)
0e320a79
DW
1215{
1216 Cut();
c4955899 1217} // end of wxTextCtrl::OnCut
0e320a79 1218
c4955899
DW
1219void wxTextCtrl::OnCopy(
1220 wxCommandEvent& rEvent
1221)
0e320a79
DW
1222{
1223 Copy();
c4955899 1224} // end of wxTextCtrl::OnCopy
0e320a79 1225
c4955899
DW
1226void wxTextCtrl::OnPaste(
1227 wxCommandEvent& rEvent
1228)
0e320a79
DW
1229{
1230 Paste();
c4955899 1231} // end of wxTextCtrl::OnPaste
0e320a79 1232
c4955899
DW
1233void wxTextCtrl::OnUndo(
1234 wxCommandEvent& rEvent
1235)
0e320a79
DW
1236{
1237 Undo();
c4955899 1238} // end of wxTextCtrl::OnUndo
0e320a79 1239
c4955899
DW
1240void wxTextCtrl::OnRedo(
1241 wxCommandEvent& rEvent
1242)
0e320a79
DW
1243{
1244 Redo();
c4955899 1245} // end of wxTextCtrl::OnRedo
0e320a79 1246
2b5f62a0
VZ
1247void wxTextCtrl::OnDelete(
1248 wxCommandEvent& rEvent
1249)
1250{
1251 long lFrom;
1252 long lTo;
1253
1254 GetSelection( &lFrom
1255 ,&lTo
1256 );
1257 if (lFrom != -1 && lTo != -1)
1258 Remove( lFrom
1259 ,lTo
1260 );
1261} // end of wxTextCtrl::OnDelete
1262
1263void wxTextCtrl::OnSelectAll(
1264 wxCommandEvent& rEvent
1265)
1266{
1267 SetSelection(-1, -1);
1268} // end of wxTextCtrl::OnSelectAll
1269
c4955899
DW
1270void wxTextCtrl::OnUpdateCut(
1271 wxUpdateUIEvent& rEvent
1272)
0e320a79 1273{
c4955899
DW
1274 rEvent.Enable(CanCut());
1275} // end of wxTextCtrl::OnUpdateCut
0e320a79 1276
c4955899
DW
1277void wxTextCtrl::OnUpdateCopy(
1278 wxUpdateUIEvent& rEvent
1279)
0e320a79 1280{
c4955899
DW
1281 rEvent.Enable(CanCopy());
1282} // end of wxTextCtrl::OnUpdateCopy
0e320a79 1283
c4955899
DW
1284void wxTextCtrl::OnUpdatePaste(
1285 wxUpdateUIEvent& rEvent
1286)
0e320a79 1287{
c4955899
DW
1288 rEvent.Enable(CanPaste());
1289} // end of wxTextCtrl::OnUpdatePaste
0e320a79 1290
c4955899
DW
1291void wxTextCtrl::OnUpdateUndo(
1292 wxUpdateUIEvent& rEvent
1293)
0e320a79 1294{
c4955899
DW
1295 rEvent.Enable(CanUndo());
1296} // end of wxTextCtrl::OnUpdateUndo
1297
1298void wxTextCtrl::OnUpdateRedo(
1299 wxUpdateUIEvent& rEvent
1300)
1301{
1302 rEvent.Enable(CanRedo());
1303} // end of wxTextCtrl::OnUpdateRedo
0e320a79 1304
2b5f62a0
VZ
1305void wxTextCtrl::OnUpdateDelete(
1306 wxUpdateUIEvent& rEvent
1307)
1308{
1309 long lFrom;
1310 long lTo;
1311
1312 GetSelection( &lFrom
1313 ,&lTo
1314 );
1315 rEvent.Enable( lFrom != -1L && lTo != -1L && lFrom != lTo && IsEditable()) ;
1316} // end of wxTextCtrl::OnUpdateDelete
1317
1318void wxTextCtrl::OnUpdateSelectAll(
1319 wxUpdateUIEvent& rEvent
1320)
1321{
1322 rEvent.Enable(GetLastPosition() > 0);
1323} // end of wxTextCtrl::OnUpdateSelectAll
1324
c4955899
DW
1325bool wxTextCtrl::SetBackgroundColour(
1326 const wxColour& rColour
1327)
0e320a79 1328{
c4955899
DW
1329 if (m_bIsMLE)
1330 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR, (MPARAM)rColour.GetPixel(), MLE_INDEX);
1331 return TRUE;
1332} // end of wxTextCtrl::SetBackgroundColour
1333
1334bool wxTextCtrl::SetForegroundColour(
1335 const wxColour& rColour
1336)
1337{
1338 if (m_bIsMLE)
1339 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR, (MPARAM)rColour.GetPixel(), MLE_INDEX);
1340 return TRUE;
1341} // end of wxTextCtrl::SetForegroundColour
d90895ac 1342
39c26ef2
DW
1343bool wxTextCtrl::SetStyle(
1344 long lStart
1345, long lEnd
1346, const wxTextAttr& rStyle
1347)
1348{
1349 HWND hWnd = GetHwnd();
1350
1351 if (lStart > lEnd)
1352 {
1353 long lTmp = lStart;
1354
1355 lStart = lEnd;
1356 lEnd = lTmp;
1357 }
1358
1359 //
1360 // We can only change the format of the selection, so select the range we
1361 // want and restore the old selection later
1362 //
1363 long lStartOld;
1364 long lEndOld;
1365
1366 GetSelection( &lStartOld
1367 ,&lEndOld
1368 );
1369
1370 //
1371 // But do we really have to change the selection?
1372 //
1373 bool bChangeSel = lStart != lStartOld ||
1374 lEnd != lEndOld;
1375
1376 if (bChangeSel)
1377 {
1378 if (m_bIsMLE)
1379 ::WinSendMsg(hWnd, MLM_SETSEL, MPFROM2SHORT((USHORT)lStart, (USHORT)lEnd), 0);
1380 else
1381 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lStart, (USHORT)lEnd), 0);
1382 }
1383
1384 //
1385 // TODO:: finish this part
1386 //
1387 return TRUE;
1388} // end of wxTextCtrl::SetStyle
1389