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