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