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