]> git.saurik.com Git - wxWidgets.git/blame - src/os2/textctrl.cpp
wxFontEnumerator mostly works for wxMSW
[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
46#if !USE_SHARED_LIBRARY
d90895ac
DW
47
48// ----------------------------------------------------------------------------
49// event tables and other macros
50// ----------------------------------------------------------------------------
51
0e320a79
DW
52IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
53
54BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
d90895ac
DW
55 EVT_CHAR(wxTextCtrl::OnChar)
56 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
57
0e320a79
DW
58 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
59 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
60 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
61 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
62 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
63
64 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
65 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
66 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
67 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
68 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
69END_EVENT_TABLE()
0e320a79 70
d90895ac
DW
71#endif // USE_SHARED_LIBRARY
72
73// ============================================================================
74// implementation
75// ============================================================================
76
77// ----------------------------------------------------------------------------
78// creation
79// ----------------------------------------------------------------------------
80
0e320a79 81wxTextCtrl::wxTextCtrl()
0e320a79 82{
0e320a79
DW
83}
84
85bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
d90895ac
DW
86 const wxString& value,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxValidator& validator,
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
303 long from, to;
304// GetSelection(& from, & to);
305 return (from != to);
306}
307
308bool wxTextCtrl::CanCut() const
309{
310 // Can cut if there's a selection
311 long from, to;
312// GetSelection(& from, & to);
313 return (from != to);
314}
315
316bool wxTextCtrl::CanPaste() const
317{
318 if (!IsEditable())
319 return FALSE;
320
321 // Standard edit control: check for straight text on clipboard
322 bool isTextAvailable = FALSE;
323//TODO:
324/*
325 if ( ::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
326 {
327 isTextAvailable = (::IsClipboardFormatAvailable(CF_TEXT) != 0);
328 ::CloseClipboard();
329 }
330*/
331 return isTextAvailable;
0e320a79
DW
332}
333
d90895ac
DW
334// ----------------------------------------------------------------------------
335// Accessors
336// ----------------------------------------------------------------------------
337
0e320a79
DW
338void wxTextCtrl::SetEditable(bool editable)
339{
d90895ac
DW
340 HWND hWnd = GetHwnd();
341// SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
0e320a79
DW
342}
343
344void wxTextCtrl::SetInsertionPoint(long pos)
345{
d90895ac
DW
346// TODO:
347/*
348 HWND hWnd = GetHwnd();
349 {
350 SendMessage(hWnd, EM_SETSEL, pos, pos);
351 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
352 }
353 static const char *nothing = "";
354 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
355*/
0e320a79
DW
356}
357
358void wxTextCtrl::SetInsertionPointEnd()
359{
d90895ac
DW
360// TODO:
361/*
0e320a79
DW
362 long pos = GetLastPosition();
363 SetInsertionPoint(pos);
d90895ac 364*/
0e320a79
DW
365}
366
367long wxTextCtrl::GetInsertionPoint() const
368{
d90895ac
DW
369// TODO:
370/*
371 DWORD Pos = (DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
372 return Pos & 0xFFFF;
373*/
0e320a79
DW
374 return 0;
375}
376
377long wxTextCtrl::GetLastPosition() const
378{
d90895ac 379 HWND hWnd = GetHwnd();
0e320a79 380
d90895ac
DW
381// TODO:
382/*
383 // Will always return a number > 0 (according to docs)
384 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
0e320a79 385
d90895ac
DW
386 // This gets the char index for the _beginning_ of the last line
387 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
0e320a79 388
d90895ac
DW
389 // Get number of characters in the last line. We'll add this to the character
390 // index for the last line, 1st position.
391 int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
392
393 return (long)(charIndex + lineLength);
394*/
395 return 0L;
0e320a79
DW
396}
397
d90895ac
DW
398// If the return values from and to are the same, there is no
399// selection.
400void wxTextCtrl::GetSelection(long* from, long* to) const
0e320a79 401{
d90895ac
DW
402 DWORD dwStart, dwEnd;
403 MPARAM wParam = (MPARAM) (DWORD*) & dwStart; // receives starting position
404 MPARAM lParam = (MPARAM) (DWORD*) & dwEnd; // receives ending position
0e320a79 405
d90895ac 406// ::SendMessage(GetHwnd(), EM_GETSEL, wParam, lParam);
0e320a79 407
d90895ac
DW
408 *from = dwStart;
409 *to = dwEnd;
410}
0e320a79 411
d90895ac
DW
412bool wxTextCtrl::IsEditable() const
413{
414// TODO:
415/*
416 long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
0e320a79 417
d90895ac
DW
418 return ((style & ES_READONLY) == 0);
419*/
0e320a79
DW
420 return FALSE;
421}
422
d90895ac
DW
423// ----------------------------------------------------------------------------
424// Editing
425// ----------------------------------------------------------------------------
426
427void wxTextCtrl::Replace(long from, long to, const wxString& value)
0e320a79 428{
d90895ac
DW
429#if wxUSE_CLIPBOARD
430 HWND hWnd = GetHwnd();
431 long fromChar = from;
432 long toChar = to;
0e320a79 433
d90895ac
DW
434 // Set selection and remove it
435// SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
436// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79 437
d90895ac
DW
438 // Now replace with 'value', by pasting.
439 wxSetClipboardData(wxDF_TEXT, (wxObject *) (const wxChar *)value, 0, 0);
0e320a79 440
d90895ac
DW
441 // Paste into edit control
442// SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
443#else
444 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
445#endif
0e320a79
DW
446}
447
d90895ac 448void wxTextCtrl::Remove(long from, long to)
0e320a79 449{
d90895ac
DW
450 HWND hWnd = GetHwnd();
451 long fromChar = from;
452 long toChar = to;
453
454 // Cut all selected text
455// SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
456// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79
DW
457}
458
d90895ac 459void wxTextCtrl::SetSelection(long from, long to)
0e320a79 460{
d90895ac
DW
461 HWND hWnd = GetHwnd();
462 long fromChar = from;
463 long toChar = to;
464
465 // if from and to are both -1, it means (in wxWindows) that all text should
466 // be selected. Translate into Windows convention
467 if ((from == -1) && (to == -1))
468 {
469 fromChar = 0;
470 toChar = -1;
471 }
472
473// SendMessage(hWnd, EM_SETSEL, (WPARAM)fromChar, (LPARAM)toChar);
474// SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
0e320a79
DW
475}
476
d90895ac 477bool wxTextCtrl::LoadFile(const wxString& file)
0e320a79 478{
d90895ac
DW
479// TODO:
480/*
481 if ( wxTextCtrlBase::LoadFile(file) )
482 {
483 // update the size limit if needed
484 AdjustSpaceLimit();
485
486 return TRUE;
487 }
488*/
489 return FALSE;
0e320a79
DW
490}
491
492bool wxTextCtrl::IsModified() const
493{
d90895ac 494// return (SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0);
0e320a79
DW
495 return FALSE;
496}
497
498// Makes 'unmodified'
499void wxTextCtrl::DiscardEdits()
500{
d90895ac 501// SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L);
0e320a79
DW
502}
503
504int wxTextCtrl::GetNumberOfLines() const
505{
d90895ac 506// return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
0e320a79
DW
507 return 0;
508}
509
510long wxTextCtrl::XYToPosition(long x, long y) const
511{
d90895ac
DW
512 HWND hWnd = GetHwnd();
513
514 // This gets the char index for the _beginning_ of this line
515// TODO:
516/*
517 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
518 return (long)(x + charIndex);
519*/
520 return 0L;
0e320a79
DW
521}
522
d90895ac 523bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
0e320a79 524{
d90895ac
DW
525 HWND hWnd = GetHwnd();
526
527 // This gets the line number containing the character
528 int lineNo;
529// lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
530
531 if ( lineNo == -1 )
532 {
533 // no such line
534 return FALSE;
535 }
536
537 // This gets the char index for the _beginning_ of this line
538 int charIndex = 0; // TODO: (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
539 if ( charIndex == -1 )
540 {
541 return FALSE;
542 }
543
544 // The X position must therefore be the different between pos and charIndex
545 if ( x )
546 *x = (long)(pos - charIndex);
547 if ( y )
548 *y = (long)lineNo;
549
550 return TRUE;
0e320a79
DW
551}
552
553void wxTextCtrl::ShowPosition(long pos)
554{
d90895ac
DW
555 HWND hWnd = GetHwnd();
556
557 // To scroll to a position, we pass the number of lines and characters
558 // to scroll *by*. This means that we need to:
559 // (1) Find the line position of the current line.
560 // (2) Find the line position of pos.
561 // (3) Scroll by (pos - current).
562 // For now, ignore the horizontal scrolling.
563
564 // Is this where scrolling is relative to - the line containing the caret?
565 // Or is the first visible line??? Try first visible line.
566// int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
567
568// TODO:
569/*
570 int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
571
572 int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
573
574 int linesToScroll = specifiedLineLineNo - currentLineLineNo;
575
576 if (linesToScroll != 0)
577 (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
578*/
0e320a79
DW
579}
580
581int wxTextCtrl::GetLineLength(long lineNo) const
582{
d90895ac
DW
583// TODO:
584/*
585
586 long charIndex = XYToPosition(0, lineNo);
587 int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
588 return len;
589*/
0e320a79
DW
590 return 0;
591}
592
593wxString wxTextCtrl::GetLineText(long lineNo) const
594{
d90895ac
DW
595 size_t len = (size_t)GetLineLength(lineNo) + 1;
596 char *buf = (char *)malloc(len);
597 *(WORD *)buf = len;
598 int noChars = 0; // TODO:(int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
599 buf[noChars] = 0;
0e320a79 600
d90895ac 601 wxString str(buf);
0e320a79 602
d90895ac 603 free(buf);
0e320a79 604
d90895ac 605 return str;
0e320a79
DW
606}
607
d90895ac 608// ----------------------------------------------------------------------------
0e320a79 609// Undo/redo
d90895ac
DW
610// ----------------------------------------------------------------------------
611
0e320a79
DW
612void wxTextCtrl::Undo()
613{
d90895ac
DW
614 if (CanUndo())
615 {
616// ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
617 }
0e320a79
DW
618}
619
620void wxTextCtrl::Redo()
621{
d90895ac
DW
622 if (CanRedo())
623 {
624 // Same as Undo, since Undo undoes the undo, i.e. a redo.
625// ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
626 }
0e320a79
DW
627}
628
629bool wxTextCtrl::CanUndo() const
630{
d90895ac 631// return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
0e320a79
DW
632 return FALSE;
633}
634
635bool wxTextCtrl::CanRedo() const
636{
d90895ac 637// return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
0e320a79
DW
638 return FALSE;
639}
640
d90895ac
DW
641// ----------------------------------------------------------------------------
642// implemenation details
643// ----------------------------------------------------------------------------
0e320a79
DW
644
645void wxTextCtrl::Command(wxCommandEvent & event)
646{
d90895ac 647 SetValue(event.GetString());
0e320a79
DW
648 ProcessCommand (event);
649}
650
651void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
652{
653 // By default, load the first file into the text window.
654 if (event.GetNumberOfFiles() > 0)
655 {
656 LoadFile(event.GetFiles()[0]);
657 }
658}
659
d90895ac
DW
660WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
661 WXUINT message, WXWPARAM wParam,
662 WXLPARAM lParam)
663{
664 HDC hdc = (HDC)pDC;
665// TODO:
666/*
667 SetBkMode(hdc, GetParent()->GetTransparentBackground() ? TRANSPARENT
668 : OPAQUE);
0e320a79 669
d90895ac
DW
670 ::SetBkColor(hdc, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
671 ::SetTextColor(hdc, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
0e320a79 672*/
d90895ac 673 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
0e320a79 674
d90895ac 675 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
0e320a79 676}
0e320a79 677
d90895ac 678void wxTextCtrl::OnChar(wxKeyEvent& event)
0e320a79 679{
d90895ac
DW
680 switch ( event.KeyCode() )
681 {
682// TODO:
683/*
684 case WXK_RETURN:
685 if ( !(m_windowStyle & wxTE_MULTILINE) )
686 {
687 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
688 event.SetEventObject( this );
689 if ( GetEventHandler()->ProcessEvent(event) )
690 return;
691 }
692 //else: multiline controls need Enter for themselves
693
694 break;
695
696 case WXK_TAB:
697 // always produce navigation event - even if we process TAB
698 // ourselves the fact that we got here means that the user code
699 // decided to skip processing of this TAB - probably to let it
700 // do its default job.
701 //
702 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
703 // handled by Windows
704 {
705 wxNavigationKeyEvent eventNav;
706 eventNav.SetDirection(!event.ShiftDown());
707 eventNav.SetWindowChange(FALSE);
708 eventNav.SetEventObject(this);
709
710 if ( GetEventHandler()->ProcessEvent(eventNav) )
711 return;
712 }
713 break;
714*/
715 default:
716 event.Skip();
717 return;
718 }
0e320a79 719
d90895ac
DW
720 // don't just call event.Skip() because this will cause TABs and ENTERs
721 // be passed upwards and we don't always want this - instead process it
722 // right here
723
724 // FIXME
725 event.Skip();
0e320a79
DW
726}
727
d90895ac 728bool wxTextCtrl::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
0e320a79 729{
d90895ac
DW
730 switch (param)
731 {
732// TODO:
733/*
734 case EN_SETFOCUS:
735 case EN_KILLFOCUS:
736 {
737 wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
738 : wxEVT_SET_FOCUS,
739 m_windowId);
740 event.SetEventObject( this );
741 GetEventHandler()->ProcessEvent(event);
742 }
743 break;
744
745 case EN_CHANGE:
746 {
747 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
748 wxString val(GetValue());
749 if ( !val.IsNull() )
750 event.m_commandString = WXSTRINGCAST val;
751 event.SetEventObject( this );
752 ProcessCommand(event);
753 }
754 break;
755
756 case EN_ERRSPACE:
757 // the text size limit has been hit - increase it
758 AdjustSpaceLimit();
759 break;
760
761 // the other notification messages are not processed
762 case EN_UPDATE:
763 case EN_MAXTEXT:
764 case EN_HSCROLL:
765 case EN_VSCROLL:
766*/
767 default:
768 return FALSE;
769 }
770
771 // processed
772 return TRUE;
0e320a79
DW
773}
774
d90895ac 775void wxTextCtrl::AdjustSpaceLimit()
0e320a79 776{
d90895ac
DW
777// TODO:
778/*
779 unsigned int len = ::GetWindowTextLength(GetHwnd()),
780 limit = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
781 if ( len > limit )
782 {
783 limit = len + 0x8000; // 32Kb
784
785 if ( limit > 0xffff )
786 ::SendMessage(GetHwnd(), EM_LIMITTEXT, 0, limit);
787 else
788 ::SendMessage(GetHwnd(), EM_LIMITTEXT, limit, 0);
789 }
790*/
0e320a79
DW
791}
792
d90895ac 793bool wxTextCtrl::AcceptsFocus() const
0e320a79 794{
d90895ac
DW
795 // we don't want focus if we can't be edited
796 return IsEditable() && wxControl::AcceptsFocus();
0e320a79
DW
797}
798
d90895ac 799wxSize wxTextCtrl::DoGetBestSize()
0e320a79 800{
d90895ac
DW
801 int cx, cy;
802 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
0e320a79 803
d90895ac
DW
804 int wText = DEFAULT_ITEM_WIDTH;
805
806 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
807 if ( m_windowStyle & wxTE_MULTILINE )
808 {
809 hText *= wxMin(GetNumberOfLines(), 5);
810 }
811 //else: for single line control everything is ok
812
813 return wxSize(wText, hText);
0e320a79
DW
814}
815
d90895ac
DW
816// ----------------------------------------------------------------------------
817// standard handlers for standard edit menu events
818// ----------------------------------------------------------------------------
819
0e320a79
DW
820void wxTextCtrl::OnCut(wxCommandEvent& event)
821{
822 Cut();
823}
824
825void wxTextCtrl::OnCopy(wxCommandEvent& event)
826{
827 Copy();
828}
829
830void wxTextCtrl::OnPaste(wxCommandEvent& event)
831{
832 Paste();
833}
834
835void wxTextCtrl::OnUndo(wxCommandEvent& event)
836{
837 Undo();
838}
839
840void wxTextCtrl::OnRedo(wxCommandEvent& event)
841{
842 Redo();
843}
844
845void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
846{
847 event.Enable( CanCut() );
848}
849
850void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
851{
852 event.Enable( CanCopy() );
853}
854
855void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
856{
857 event.Enable( CanPaste() );
858}
859
860void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
861{
862 event.Enable( CanUndo() );
863}
864
865void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
866{
867 event.Enable( CanRedo() );
868}
d90895ac 869