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