]> git.saurik.com Git - wxWidgets.git/blame - src/os2/textctrl.cpp
Fixed remaining int vs. long warnings.
[wxWidgets.git] / src / os2 / textctrl.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: textctrl.cpp
3// Purpose: wxTextCtrl
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
d90895ac
DW
12// ----------------------------------------------------------------------------
13// headers
14// ----------------------------------------------------------------------------
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifndef WX_PRECOMP
20 #include "wx/textctrl.h"
21 #include "wx/settings.h"
22 #include "wx/brush.h"
23 #include "wx/utils.h"
24 #include "wx/log.h"
0e320a79
DW
25#endif
26
d90895ac
DW
27#if wxUSE_CLIPBOARD
28 #include "wx/app.h"
29 #include "wx/clipbrd.h"
30#endif
0e320a79 31
d90895ac
DW
32#include "wx/textfile.h"
33
34#include "wx/os2/private.h"
35
36#include <string.h>
37#include <stdlib.h>
38#include <sys/types.h>
0e320a79 39
d90895ac
DW
40#if wxUSE_IOSTREAMH
41# include <fstream.h>
0e320a79 42#else
d90895ac 43# include <fstream>
0e320a79
DW
44#endif
45
d90895ac
DW
46
47// ----------------------------------------------------------------------------
48// event tables and other macros
49// ----------------------------------------------------------------------------
50
0e320a79
DW
51IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
52
53BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
d90895ac
DW
54 EVT_CHAR(wxTextCtrl::OnChar)
55 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
56
0e320a79
DW
57 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
58 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
59 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
60 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
61 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
62
63 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
64 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
65 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
66 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
67 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
68END_EVENT_TABLE()
0e320a79 69
d90895ac
DW
70
71// ============================================================================
72// implementation
73// ============================================================================
74
75// ----------------------------------------------------------------------------
76// creation
77// ----------------------------------------------------------------------------
78
0e320a79 79wxTextCtrl::wxTextCtrl()
0e320a79 80{
0e320a79
DW
81}
82
83bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
d90895ac
DW
84 const wxString& value,
85 const wxPoint& pos,
86 const wxSize& size,
87 long style,
5d4b632b 88#if wxUSE_VALIDATORS
d90895ac 89 const wxValidator& validator,
5d4b632b 90#endif
d90895ac
DW
91 const wxString& name)
92{
93 // base initialization
94 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
95 return FALSE;
0e320a79 96
d90895ac
DW
97 // Validator was set in CreateBase
98 //SetValidator(validator);
99 if ( parent )
100 parent->AddChild(this);
0e320a79 101
d90895ac
DW
102 // set colours
103 SetupColours();
104
105 // translate wxWin style flags to MSW ones, checking for consistency while
106 // doing it
107// TODO:
108/*
109 long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
110 if ( m_windowStyle & wxTE_MULTILINE )
111 {
112 wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
113 wxT("wxTE_PROCESS_ENTER style is ignored for multiline "
114 "text controls (they always process it)") );
115
116 msStyle |= ES_MULTILINE | ES_WANTRETURN;
117 if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
118 msStyle |= WS_VSCROLL;
119 m_windowStyle |= wxTE_PROCESS_ENTER;
120 }
0e320a79 121 else
d90895ac
DW
122 msStyle |= ES_AUTOHSCROLL;
123
124 if (m_windowStyle & wxHSCROLL)
125 msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
126
127 if (m_windowStyle & wxTE_READONLY)
128 msStyle |= ES_READONLY;
129
130 if (m_windowStyle & wxHSCROLL)
131 msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
132 if (m_windowStyle & wxTE_PASSWORD) // hidden input
133 msStyle |= ES_PASSWORD;
134
135 // we always want the characters and the arrows
136 m_lDlgCode = DLGC_WANTCHARS | DLGC_WANTARROWS;
137
138 // we may have several different cases:
139 // 1. normal case: both TAB and ENTER are used for dialog navigation
140 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
141 // control in the dialog
142 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
143 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
144 // the next control
145 if ( m_windowStyle & wxTE_PROCESS_ENTER )
146 m_lDlgCode |= DLGC_WANTMESSAGE;
147 if ( m_windowStyle & wxTE_PROCESS_TAB )
148 m_lDlgCode |= DLGC_WANTTAB;
149
150 // do create the control - either an EDIT or RICHEDIT
151 const wxChar *windowClass = wxT("EDIT");
152
153 bool want3D;
154 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
155
156 // Even with extended styles, need to combine with WS_BORDER for them to
157 // look right.
158 if ( want3D || wxStyleHasBorder(m_windowStyle) )
159 msStyle |= WS_BORDER;
160
161 // NB: don't use pos and size as CreateWindowEx arguments because they
162 // might be -1 in which case we should use the default values (and
163 // SetSize called below takes care of it)
164 m_hWnd = (WXHWND)::CreateWindowEx(exStyle,
165 windowClass,
166 NULL,
167 msStyle,
168 0, 0, 0, 0,
169 GetHwndOf(parent),
170 (HMENU)m_windowId,
171 wxGetInstance(),
172 NULL);
173
174 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create text ctrl") );
175*/
176 SubclassWin(GetHWND());
177
178 // set font, position, size and initial value
179 wxFont& fontParent = parent->GetFont();
180 if ( fontParent.Ok() )
181 {
182 SetFont(fontParent);
183 }
184 else
185 {
186 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
187 }
188
189 SetSize(pos.x, pos.y, size.x, size.y);
0e320a79
DW
190
191 return TRUE;
192}
193
d90895ac
DW
194// Make sure the window style (etc.) reflects the HWND style (roughly)
195void wxTextCtrl::AdoptAttributesFromHWND()
196{
197 wxWindow::AdoptAttributesFromHWND();
198
199 HWND hWnd = GetHwnd();
200 // TODO:
201 /*
202 long style = GetWindowLong(hWnd, GWL_STYLE);
203
204 if (style & ES_MULTILINE)
205 m_windowStyle |= wxTE_MULTILINE;
206 if (style & ES_PASSWORD)
207 m_windowStyle |= wxTE_PASSWORD;
208 if (style & ES_READONLY)
209 m_windowStyle |= wxTE_READONLY;
210 if (style & ES_WANTRETURN)
211 m_windowStyle |= wxTE_PROCESS_ENTER;
212 */
213}
214
215void wxTextCtrl::SetupColours()
216{
217 // FIXME why is bg colour not inherited from parent?
218 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
219 SetForegroundColour(GetParent()->GetForegroundColour());
220}
221
222// ----------------------------------------------------------------------------
223// set/get the controls text
224// ----------------------------------------------------------------------------
225
0e320a79
DW
226wxString wxTextCtrl::GetValue() const
227{
d90895ac 228 return wxGetWindowText(GetHWND());
0e320a79
DW
229}
230
231void wxTextCtrl::SetValue(const wxString& value)
232{
d90895ac
DW
233// TODO:
234/*
235 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
236
237 SetWindowText(GetHwnd(), valueDos);
238
239 AdjustSpaceLimit();
240*/
0e320a79
DW
241}
242
d90895ac 243void wxTextCtrl::WriteText(const wxString& value)
0e320a79 244{
d90895ac
DW
245// TODO:
246/*
247 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
248
249 SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)valueDos.c_str());
250
251 AdjustSpaceLimit();
252*/
0e320a79
DW
253}
254
d90895ac
DW
255void wxTextCtrl::AppendText(const wxString& text)
256{
257// TODO:
258/*
259 SetInsertionPointEnd();
260 WriteText(text);
261*/
262}
263
264void wxTextCtrl::Clear()
265{
266// SetWindowText(GetHwnd(), wxT(""));
267}
268
269// ----------------------------------------------------------------------------
0e320a79 270// Clipboard operations
d90895ac
DW
271// ----------------------------------------------------------------------------
272
0e320a79
DW
273void wxTextCtrl::Copy()
274{
d90895ac
DW
275 if (CanCopy())
276 {
277 HWND hWnd = GetHwnd();
278// SendMessage(hWnd, WM_COPY, 0, 0L);
279 }
0e320a79
DW
280}
281
282void wxTextCtrl::Cut()
283{
d90895ac
DW
284 if (CanCut())
285 {
286 HWND hWnd = GetHwnd();
287// SendMessage(hWnd, WM_CUT, 0, 0L);
288 }
0e320a79
DW
289}
290
291void wxTextCtrl::Paste()
292{
d90895ac
DW
293 if (CanPaste())
294 {
295 HWND hWnd = GetHwnd();
296// SendMessage(hWnd, WM_PASTE, 0, 0L);
297 }
298}
299
300bool wxTextCtrl::CanCopy() const
301{
302 // Can copy if there's a selection
9dea36ef
DW
303 long from = 0L;
304 long to = 0L;
d90895ac
DW
305// GetSelection(& from, & to);
306 return (from != to);
307}
308
309bool wxTextCtrl::CanCut() const
310{
311 // Can cut if there's a selection
9dea36ef
DW
312 long from = 0L;
313 long to = 0L;
d90895ac
DW
314// GetSelection(& from, & to);
315 return (from != to);
316}
317
318bool wxTextCtrl::CanPaste() const
319{
320 if (!IsEditable())
321 return FALSE;
322
323 // Standard edit control: check for straight text on clipboard
324 bool isTextAvailable = FALSE;
325//TODO:
326/*
327 if ( ::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
328 {
329 isTextAvailable = (::IsClipboardFormatAvailable(CF_TEXT) != 0);
330 ::CloseClipboard();
331 }
332*/
333 return isTextAvailable;
0e320a79
DW
334}
335
d90895ac
DW
336// ----------------------------------------------------------------------------
337// Accessors
338// ----------------------------------------------------------------------------
339
0e320a79
DW
340void wxTextCtrl::SetEditable(bool editable)
341{
d90895ac
DW
342 HWND hWnd = GetHwnd();
343// SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
0e320a79
DW
344}
345
346void wxTextCtrl::SetInsertionPoint(long pos)
347{
d90895ac
DW
348// TODO:
349/*
350 HWND hWnd = GetHwnd();
351 {
352 SendMessage(hWnd, EM_SETSEL, pos, pos);
353 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
354 }
355 static const char *nothing = "";
356 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
357*/
0e320a79
DW
358}
359
360void wxTextCtrl::SetInsertionPointEnd()
361{
d90895ac
DW
362// TODO:
363/*
0e320a79
DW
364 long pos = GetLastPosition();
365 SetInsertionPoint(pos);
d90895ac 366*/
0e320a79
DW
367}
368
369long wxTextCtrl::GetInsertionPoint() const
370{
d90895ac
DW
371// TODO:
372/*
373 DWORD Pos = (DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
374 return Pos & 0xFFFF;
375*/
0e320a79
DW
376 return 0;
377}
378
379long wxTextCtrl::GetLastPosition() const
380{
d90895ac 381 HWND hWnd = GetHwnd();
0e320a79 382
d90895ac
DW
383// TODO:
384/*
385 // Will always return a number > 0 (according to docs)
386 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
0e320a79 387
d90895ac
DW
388 // This gets the char index for the _beginning_ of the last line
389 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
0e320a79 390
d90895ac
DW
391 // Get number of characters in the last line. We'll add this to the character
392 // index for the last line, 1st position.
393 int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
394
395 return (long)(charIndex + lineLength);
396*/
397 return 0L;
0e320a79
DW
398}
399
d90895ac
DW
400// If the return values from and to are the same, there is no
401// selection.
402void wxTextCtrl::GetSelection(long* from, long* to) const
0e320a79 403{
d90895ac
DW
404 DWORD dwStart, dwEnd;
405 MPARAM wParam = (MPARAM) (DWORD*) & dwStart; // receives starting position
406 MPARAM lParam = (MPARAM) (DWORD*) & dwEnd; // receives ending position
0e320a79 407
d90895ac 408// ::SendMessage(GetHwnd(), EM_GETSEL, wParam, lParam);
0e320a79 409
d90895ac
DW
410 *from = dwStart;
411 *to = dwEnd;
412}
0e320a79 413
d90895ac
DW
414bool wxTextCtrl::IsEditable() const
415{
416// TODO:
417/*
418 long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
0e320a79 419
d90895ac
DW
420 return ((style & ES_READONLY) == 0);
421*/
0e320a79
DW
422 return FALSE;
423}
424
d90895ac
DW
425// ----------------------------------------------------------------------------
426// Editing
427// ----------------------------------------------------------------------------
428
429void wxTextCtrl::Replace(long from, long to, const wxString& value)
0e320a79 430{
d90895ac
DW
431#if wxUSE_CLIPBOARD
432 HWND hWnd = GetHwnd();
433 long fromChar = from;
434 long toChar = to;
0e320a79 435
d90895ac
DW
436 // Set selection and remove it
437// SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
438// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79 439
d90895ac
DW
440 // Now replace with 'value', by pasting.
441 wxSetClipboardData(wxDF_TEXT, (wxObject *) (const wxChar *)value, 0, 0);
0e320a79 442
d90895ac
DW
443 // Paste into edit control
444// SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
445#else
446 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
447#endif
0e320a79
DW
448}
449
d90895ac 450void wxTextCtrl::Remove(long from, long to)
0e320a79 451{
d90895ac
DW
452 HWND hWnd = GetHwnd();
453 long fromChar = from;
454 long toChar = to;
455
456 // Cut all selected text
457// SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
458// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79
DW
459}
460
d90895ac 461void wxTextCtrl::SetSelection(long from, long to)
0e320a79 462{
d90895ac
DW
463 HWND hWnd = GetHwnd();
464 long fromChar = from;
465 long toChar = to;
466
467 // if from and to are both -1, it means (in wxWindows) that all text should
468 // be selected. Translate into Windows convention
469 if ((from == -1) && (to == -1))
470 {
471 fromChar = 0;
472 toChar = -1;
473 }
474
475// SendMessage(hWnd, EM_SETSEL, (WPARAM)fromChar, (LPARAM)toChar);
476// SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
0e320a79
DW
477}
478
d90895ac 479bool wxTextCtrl::LoadFile(const wxString& file)
0e320a79 480{
d90895ac
DW
481// TODO:
482/*
483 if ( wxTextCtrlBase::LoadFile(file) )
484 {
485 // update the size limit if needed
486 AdjustSpaceLimit();
487
488 return TRUE;
489 }
490*/
491 return FALSE;
0e320a79
DW
492}
493
494bool wxTextCtrl::IsModified() const
495{
d90895ac 496// return (SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0);
0e320a79
DW
497 return FALSE;
498}
499
500// Makes 'unmodified'
501void wxTextCtrl::DiscardEdits()
502{
d90895ac 503// SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L);
0e320a79
DW
504}
505
506int wxTextCtrl::GetNumberOfLines() const
507{
d90895ac 508// return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
0e320a79
DW
509 return 0;
510}
511
512long wxTextCtrl::XYToPosition(long x, long y) const
513{
d90895ac
DW
514 HWND hWnd = GetHwnd();
515
516 // This gets the char index for the _beginning_ of this line
517// TODO:
518/*
519 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
520 return (long)(x + charIndex);
521*/
522 return 0L;
0e320a79
DW
523}
524
d90895ac 525bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
0e320a79 526{
d90895ac
DW
527 HWND hWnd = GetHwnd();
528
529 // This gets the line number containing the character
9dea36ef 530 int lineNo = -1;
d90895ac
DW
531// lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
532
533 if ( lineNo == -1 )
534 {
535 // no such line
536 return FALSE;
537 }
538
539 // This gets the char index for the _beginning_ of this line
540 int charIndex = 0; // TODO: (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
541 if ( charIndex == -1 )
542 {
543 return FALSE;
544 }
545
546 // The X position must therefore be the different between pos and charIndex
547 if ( x )
548 *x = (long)(pos - charIndex);
549 if ( y )
550 *y = (long)lineNo;
551
552 return TRUE;
0e320a79
DW
553}
554
555void wxTextCtrl::ShowPosition(long pos)
556{
d90895ac
DW
557 HWND hWnd = GetHwnd();
558
559 // To scroll to a position, we pass the number of lines and characters
560 // to scroll *by*. This means that we need to:
561 // (1) Find the line position of the current line.
562 // (2) Find the line position of pos.
563 // (3) Scroll by (pos - current).
564 // For now, ignore the horizontal scrolling.
565
566 // Is this where scrolling is relative to - the line containing the caret?
567 // Or is the first visible line??? Try first visible line.
568// int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
569
570// TODO:
571/*
572 int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
573
574 int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
575
576 int linesToScroll = specifiedLineLineNo - currentLineLineNo;
577
578 if (linesToScroll != 0)
579 (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
580*/
0e320a79
DW
581}
582
583int wxTextCtrl::GetLineLength(long lineNo) const
584{
d90895ac
DW
585// TODO:
586/*
587
588 long charIndex = XYToPosition(0, lineNo);
589 int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
590 return len;
591*/
0e320a79
DW
592 return 0;
593}
594
595wxString wxTextCtrl::GetLineText(long lineNo) const
596{
d90895ac
DW
597 size_t len = (size_t)GetLineLength(lineNo) + 1;
598 char *buf = (char *)malloc(len);
599 *(WORD *)buf = len;
600 int noChars = 0; // TODO:(int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
601 buf[noChars] = 0;
0e320a79 602
d90895ac 603 wxString str(buf);
0e320a79 604
d90895ac 605 free(buf);
0e320a79 606
d90895ac 607 return str;
0e320a79
DW
608}
609
d90895ac 610// ----------------------------------------------------------------------------
0e320a79 611// Undo/redo
d90895ac
DW
612// ----------------------------------------------------------------------------
613
0e320a79
DW
614void wxTextCtrl::Undo()
615{
d90895ac
DW
616 if (CanUndo())
617 {
618// ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
619 }
0e320a79
DW
620}
621
622void wxTextCtrl::Redo()
623{
d90895ac
DW
624 if (CanRedo())
625 {
626 // Same as Undo, since Undo undoes the undo, i.e. a redo.
627// ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
628 }
0e320a79
DW
629}
630
631bool wxTextCtrl::CanUndo() const
632{
d90895ac 633// return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
0e320a79
DW
634 return FALSE;
635}
636
637bool wxTextCtrl::CanRedo() const
638{
d90895ac 639// return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
0e320a79
DW
640 return FALSE;
641}
642
d90895ac
DW
643// ----------------------------------------------------------------------------
644// implemenation details
645// ----------------------------------------------------------------------------
0e320a79
DW
646
647void wxTextCtrl::Command(wxCommandEvent & event)
648{
d90895ac 649 SetValue(event.GetString());
0e320a79
DW
650 ProcessCommand (event);
651}
652
653void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
654{
655 // By default, load the first file into the text window.
656 if (event.GetNumberOfFiles() > 0)
657 {
658 LoadFile(event.GetFiles()[0]);
659 }
660}
661
d90895ac
DW
662WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
663 WXUINT message, WXWPARAM wParam,
664 WXLPARAM lParam)
665{
666 HDC hdc = (HDC)pDC;
667// TODO:
668/*
669 SetBkMode(hdc, GetParent()->GetTransparentBackground() ? TRANSPARENT
670 : OPAQUE);
0e320a79 671
d90895ac
DW
672 ::SetBkColor(hdc, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
673 ::SetTextColor(hdc, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
0e320a79 674*/
d90895ac 675 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
0e320a79 676
d90895ac 677 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
0e320a79 678}
0e320a79 679
d90895ac 680void wxTextCtrl::OnChar(wxKeyEvent& event)
0e320a79 681{
d90895ac
DW
682 switch ( event.KeyCode() )
683 {
684// TODO:
685/*
686 case WXK_RETURN:
687 if ( !(m_windowStyle & wxTE_MULTILINE) )
688 {
689 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
690 event.SetEventObject( this );
691 if ( GetEventHandler()->ProcessEvent(event) )
692 return;
693 }
694 //else: multiline controls need Enter for themselves
695
696 break;
697
698 case WXK_TAB:
699 // always produce navigation event - even if we process TAB
700 // ourselves the fact that we got here means that the user code
701 // decided to skip processing of this TAB - probably to let it
702 // do its default job.
703 //
704 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
705 // handled by Windows
706 {
707 wxNavigationKeyEvent eventNav;
708 eventNav.SetDirection(!event.ShiftDown());
709 eventNav.SetWindowChange(FALSE);
710 eventNav.SetEventObject(this);
711
712 if ( GetEventHandler()->ProcessEvent(eventNav) )
713 return;
714 }
715 break;
716*/
717 default:
718 event.Skip();
719 return;
720 }
0e320a79 721
d90895ac
DW
722 // don't just call event.Skip() because this will cause TABs and ENTERs
723 // be passed upwards and we don't always want this - instead process it
724 // right here
725
726 // FIXME
727 event.Skip();
0e320a79
DW
728}
729
d90895ac 730bool wxTextCtrl::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
0e320a79 731{
d90895ac
DW
732 switch (param)
733 {
734// TODO:
735/*
736 case EN_SETFOCUS:
737 case EN_KILLFOCUS:
738 {
739 wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
740 : wxEVT_SET_FOCUS,
741 m_windowId);
742 event.SetEventObject( this );
743 GetEventHandler()->ProcessEvent(event);
744 }
745 break;
746
747 case EN_CHANGE:
748 {
749 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
750 wxString val(GetValue());
751 if ( !val.IsNull() )
752 event.m_commandString = WXSTRINGCAST val;
753 event.SetEventObject( this );
754 ProcessCommand(event);
755 }
756 break;
757
758 case EN_ERRSPACE:
759 // the text size limit has been hit - increase it
760 AdjustSpaceLimit();
761 break;
762
763 // the other notification messages are not processed
764 case EN_UPDATE:
765 case EN_MAXTEXT:
766 case EN_HSCROLL:
767 case EN_VSCROLL:
768*/
769 default:
770 return FALSE;
771 }
772
773 // processed
774 return TRUE;
0e320a79
DW
775}
776
d90895ac 777void wxTextCtrl::AdjustSpaceLimit()
0e320a79 778{
d90895ac
DW
779// TODO:
780/*
781 unsigned int len = ::GetWindowTextLength(GetHwnd()),
782 limit = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
783 if ( len > limit )
784 {
785 limit = len + 0x8000; // 32Kb
786
787 if ( limit > 0xffff )
788 ::SendMessage(GetHwnd(), EM_LIMITTEXT, 0, limit);
789 else
790 ::SendMessage(GetHwnd(), EM_LIMITTEXT, limit, 0);
791 }
792*/
0e320a79
DW
793}
794
d90895ac 795bool wxTextCtrl::AcceptsFocus() const
0e320a79 796{
d90895ac
DW
797 // we don't want focus if we can't be edited
798 return IsEditable() && wxControl::AcceptsFocus();
0e320a79
DW
799}
800
e78c4d50 801wxSize wxTextCtrl::DoGetBestSize() const
0e320a79 802{
d90895ac 803 int cx, cy;
e78c4d50 804 wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont());
0e320a79 805
d90895ac
DW
806 int wText = DEFAULT_ITEM_WIDTH;
807
808 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
809 if ( m_windowStyle & wxTE_MULTILINE )
810 {
811 hText *= wxMin(GetNumberOfLines(), 5);
812 }
813 //else: for single line control everything is ok
814
815 return wxSize(wText, hText);
0e320a79
DW
816}
817
d90895ac
DW
818// ----------------------------------------------------------------------------
819// standard handlers for standard edit menu events
820// ----------------------------------------------------------------------------
821
0e320a79
DW
822void wxTextCtrl::OnCut(wxCommandEvent& event)
823{
824 Cut();
825}
826
827void wxTextCtrl::OnCopy(wxCommandEvent& event)
828{
829 Copy();
830}
831
832void wxTextCtrl::OnPaste(wxCommandEvent& event)
833{
834 Paste();
835}
836
837void wxTextCtrl::OnUndo(wxCommandEvent& event)
838{
839 Undo();
840}
841
842void wxTextCtrl::OnRedo(wxCommandEvent& event)
843{
844 Redo();
845}
846
847void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
848{
849 event.Enable( CanCut() );
850}
851
852void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
853{
854 event.Enable( CanCopy() );
855}
856
857void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
858{
859 event.Enable( CanPaste() );
860}
861
862void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
863{
864 event.Enable( CanUndo() );
865}
866
867void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
868{
869 event.Enable( CanRedo() );
870}
d90895ac 871