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