4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2012 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_SCREEN_EDIT_WINDOW_HXX
25 #define XCSOAR_SCREEN_EDIT_WINDOW_HXX
27 #include "Screen/Window.hpp"
30 #include <tstring.hpp>
36 class EditWindowStyle
: public WindowStyle
{
42 EditWindowStyle():is_read_only(false) {
43 text_style
|= DT_LEFT
| DT_VCENTER
;
46 EditWindowStyle(const WindowStyle other
)
47 :WindowStyle(other
), is_read_only(false) {
48 text_style
|= DT_LEFT
| DT_VCENTER
;
52 style
|= ES_LEFT
| ES_AUTOHSCROLL
;
55 EditWindowStyle(const WindowStyle other
):WindowStyle(other
) {
56 style
|= ES_LEFT
| ES_AUTOHSCROLL
;
70 text_style
&= ~DT_VCENTER
;
71 text_style
|= DT_WORDBREAK
;
73 style
&= ~ES_AUTOHSCROLL
;
74 style
|= ES_MULTILINE
;
80 text_style
&= ~DT_LEFT
;
81 text_style
|= DT_CENTER
;
88 void vertical_center() {
90 text_style
|= DT_VCENTER
;
98 * A simple text editor widget.
100 class EditWindow
: public Window
{
108 void set(ContainerWindow
&parent
, PixelScalar left
, PixelScalar top
,
109 UPixelScalar width
, UPixelScalar height
,
110 const EditWindowStyle style
);
112 void set(ContainerWindow
&parent
, const PixelRect rc
,
113 const EditWindowStyle style
);
115 unsigned get_row_count() const {
116 assert_none_locked();
119 const TCHAR
*str
= value
.c_str();
122 while ((str
= strchr(str
, _T('\n'))) != NULL
) {
128 return ::SendMessage(hWnd
, EM_GETLINECOUNT
, 0, 0);
132 void set_text(const TCHAR
*text
);
134 void get_text(TCHAR
*text
, size_t max_length
) {
136 value
.copy(text
, std::min(max_length
- 1, value
.length()));
138 ::GetWindowText(hWnd
, text
, max_length
);
142 void set_read_only(bool value
) {
143 assert_none_locked();
149 ::SendMessage(hWnd
, EM_SETREADONLY
, (WPARAM
)(BOOL
)value
, 0L);
153 bool is_read_only() const {
157 return (get_window_style() & ES_READONLY
) != 0;
161 void set_selection(int start
, int end
) {
162 assert_none_locked();
167 ::SendMessage(hWnd
, EM_SETSEL
, (WPARAM
)start
, (LPARAM
)end
);
171 void set_selection() {
175 set_selection(0, -1);
181 virtual void OnPaint(Canvas
&canvas
);
182 #endif /* !USE_GDI */