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