po: update French translation
[xcsoar.git] / src / Screen / EditWindow.hpp
blobae8b3c4f32fadb9f3b3b7fa195be197895d3dbdb
1 /*
2 Copyright_License {
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"
29 #ifndef USE_GDI
30 #include <tstring.hpp>
31 #include <algorithm>
32 #endif
34 #include <winuser.h>
36 class EditWindowStyle : public WindowStyle {
37 public:
38 bool is_read_only;
40 public:
41 #ifndef USE_GDI
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;
50 #else
51 EditWindowStyle() {
52 style |= ES_LEFT | ES_AUTOHSCROLL;
55 EditWindowStyle(const WindowStyle other):WindowStyle(other) {
56 style |= ES_LEFT | ES_AUTOHSCROLL;
58 #endif
60 void read_only() {
61 #ifndef USE_GDI
62 is_read_only = true;
63 #else
64 style |= ES_READONLY;
65 #endif
68 void multiline() {
69 #ifndef USE_GDI
70 text_style &= ~DT_VCENTER;
71 text_style |= DT_WORDBREAK;
72 #else
73 style &= ~ES_AUTOHSCROLL;
74 style |= ES_MULTILINE;
75 #endif
78 void center() {
79 #ifndef USE_GDI
80 text_style &= ~DT_LEFT;
81 text_style |= DT_CENTER;
82 #else
83 style &= ~ES_LEFT;
84 style |= ES_CENTER;
85 #endif
88 void vertical_center() {
89 #ifndef USE_GDI
90 text_style |= DT_VCENTER;
91 #else
92 // TODO
93 #endif
97 /**
98 * A simple text editor widget.
100 class EditWindow : public Window {
101 #ifndef USE_GDI
102 bool read_only;
104 tstring value;
105 #endif
107 public:
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();
118 #ifndef USE_GDI
119 const TCHAR *str = value.c_str();
120 int row_count = 1;
122 while ((str = strchr(str, _T('\n'))) != NULL) {
123 str++;
124 row_count++;
126 return row_count;
127 #else /* USE_GDI */
128 return ::SendMessage(hWnd, EM_GETLINECOUNT, 0, 0);
129 #endif /* USE_GDI */
132 void set_text(const TCHAR *text);
134 void get_text(TCHAR *text, size_t max_length) {
135 #ifndef USE_GDI
136 value.copy(text, std::min(max_length - 1, value.length()));
137 #else
138 ::GetWindowText(hWnd, text, max_length);
139 #endif
142 void set_read_only(bool value) {
143 assert_none_locked();
145 #ifndef USE_GDI
146 read_only = value;
147 invalidate();
148 #else
149 ::SendMessage(hWnd, EM_SETREADONLY, (WPARAM)(BOOL)value, 0L);
150 #endif
153 bool is_read_only() const {
154 #ifndef USE_GDI
155 return read_only;
156 #else
157 return (get_window_style() & ES_READONLY) != 0;
158 #endif
161 void set_selection(int start, int end) {
162 assert_none_locked();
164 #ifndef USE_GDI
165 // XXX
166 #else
167 ::SendMessage(hWnd, EM_SETSEL, (WPARAM)start, (LPARAM)end);
168 #endif
171 void set_selection() {
172 #ifndef USE_GDI
173 // XXX
174 #else
175 set_selection(0, -1);
176 #endif
179 #ifndef USE_GDI
180 protected:
181 virtual void OnPaint(Canvas &canvas);
182 #endif /* !USE_GDI */
185 #endif