]> git.saurik.com Git - wxWidgets.git/blame - src/msw/textentry.cpp
Implemented HasContainerColumns() for GTK+
[wxWidgets.git] / src / msw / textentry.cpp
CommitLineData
69a05ef6
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/textentry.cpp
3// Purpose: wxTextEntry implementation for wxMSW
4// Author: Vadim Zeitlin
5// Created: 2007-09-26
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
c0ae6c3b 27 #include "wx/string.h"
69a05ef6
VZ
28#endif // WX_PRECOMP
29
30#include "wx/textentry.h"
31
32#include "wx/msw/private.h"
33
34#define GetEditHwnd() ((HWND)(GetEditHWND()))
35
36// ============================================================================
37// wxTextEntry implementation
38// ============================================================================
39
40void wxTextEntry::WriteText(const wxString& text)
41{
42 ::SendMessage(GetEditHwnd(), EM_REPLACESEL, 0, (LPARAM)text.wx_str());
43}
44
45wxString wxTextEntry::GetValue() const
46{
47 return wxGetWindowText(GetEditHWND());
48}
49
50void wxTextEntry::Remove(long from, long to)
51{
52 DoSetSelection(from, to, SetSel_NoScroll);
53 WriteText(wxString());
54}
55
56void wxTextEntry::Copy()
57{
58 ::SendMessage(GetEditHwnd(), WM_COPY, 0, 0);
59}
60
61void wxTextEntry::Cut()
62{
63 ::SendMessage(GetEditHwnd(), WM_CUT, 0, 0);
64}
65
66void wxTextEntry::Paste()
67{
68 ::SendMessage(GetEditHwnd(), WM_PASTE, 0, 0);
69}
70
71void wxTextEntry::Undo()
72{
73 ::SendMessage(GetEditHwnd(), EM_UNDO, 0, 0);
74}
75
76void wxTextEntry::Redo()
77{
3cb6eaec 78 // same as Undo, since Undo undoes the undo
69a05ef6
VZ
79 Undo();
80 return;
81}
82
83bool wxTextEntry::CanUndo() const
84{
85 return ::SendMessage(GetEditHwnd(), EM_CANUNDO, 0, 0) != 0;
86}
87
88bool wxTextEntry::CanRedo() const
89{
90 // see comment in Redo()
91 return CanUndo();
92}
93
94void wxTextEntry::SetInsertionPoint(long pos)
95{
96 // be careful to call DoSetSelection() which is overridden in wxTextCtrl
97 // and not just SetSelection() here
98 DoSetSelection(pos, pos);
99}
100
101long wxTextEntry::GetInsertionPoint() const
102{
103 long from;
104 GetSelection(&from, NULL);
105 return from;
106}
107
108long wxTextEntry::GetLastPosition() const
109{
110 return ::SendMessage(GetEditHwnd(), EM_LINELENGTH, 0, 0);
111}
112
113void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags))
114{
115 // if from and to are both -1, it means (in wxWidgets) that all text should
116 // be selected, translate this into Windows convention
117 if ( (from == -1) && (to == -1) )
118 {
119 from = 0;
120 }
121
122 ::SendMessage(GetEditHwnd(), EM_SETSEL, from, to);
123}
124
125void wxTextEntry::GetSelection(long *from, long *to) const
126{
127 DWORD dwStart, dwEnd;
128 ::SendMessage(GetEditHwnd(), EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
129
130 if ( from )
131 *from = dwStart;
132 if ( to )
133 *to = dwEnd;
134}
135
136bool wxTextEntry::IsEditable() const
137{
5ad3f0c8 138 return !(::GetWindowLong(GetEditHwnd(), GWL_STYLE) & ES_READONLY);
69a05ef6
VZ
139}
140
141void wxTextEntry::SetEditable(bool editable)
142{
143 ::SendMessage(GetEditHwnd(), EM_SETREADONLY, !editable, 0);
144}
145
146void wxTextEntry::SetMaxLength(unsigned long len)
147{
148 if ( len >= 0xffff )
149 {
150 // this will set it to a platform-dependent maximum (much more
151 // than 64Kb under NT)
152 len = 0;
153 }
154
155 ::SendMessage(GetEditHwnd(), EM_LIMITTEXT, len, 0);
156}