FreeRDP
Loading...
Searching...
No Matches
SdlInputWidgetPairList Class Reference

#include <sdl_input_widget_pair_list.hpp>

Inheritance diagram for SdlInputWidgetPairList:
Collaboration diagram for SdlInputWidgetPairList:

Public Member Functions

 SdlInputWidgetPairList (const std::string &title, const std::vector< std::string > &labels, const std::vector< std::string > &initial, const std::vector< Uint32 > &flags, ssize_t selected=-1)
 
 SdlInputWidgetPairList (const SdlInputWidgetPairList &other)=delete
 
 SdlInputWidgetPairList (SdlInputWidgetPairList &&other)=delete
 
SdlInputWidgetPairListoperator= (const SdlInputWidgetPairList &other)=delete
 
SdlInputWidgetPairListoperator= (SdlInputWidgetPairList &&other)=delete
 
int run (std::vector< std::string > &result)
 
- Public Member Functions inherited from SdlWidgetList
 SdlWidgetList (const SdlWidgetList &other)=delete
 
 SdlWidgetList (SdlWidgetList &&other)=delete
 
SdlWidgetListoperator= (const SdlWidgetList &other)=delete
 
SdlWidgetListoperator= (SdlWidgetList &&other)=delete
 
virtual bool reset (const std::string &title, size_t width, size_t height)
 
virtual bool visible () const
 

Protected Member Functions

bool updateInternal () override
 
ssize_t get_index (const SDL_MouseButtonEvent &button)
 
- Protected Member Functions inherited from SdlWidgetList
bool update ()
 
virtual bool clearWindow ()
 

Additional Inherited Members

- Protected Attributes inherited from SdlWidgetList
std::shared_ptr< SDL_Window > _window
 
std::shared_ptr< SDL_Renderer > _renderer
 
SdlButtonList _buttons
 
SDL_Color _backgroundcolor { 0x38, 0x36, 0x35, 0xff }
 

Detailed Description

FreeRDP: A Remote Desktop Protocol Implementation SDL Client helper dialogs

Copyright 2025 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m Copyright 2025 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 30 of file sdl_input_widget_pair_list.hpp.

Constructor & Destructor Documentation

◆ SdlInputWidgetPairList()

SdlInputWidgetPairList::SdlInputWidgetPairList ( const std::string &  title,
const std::vector< std::string > &  labels,
const std::vector< std::string > &  initial,
const std::vector< Uint32 > &  flags,
ssize_t  selected = -1 
)

Definition at line 30 of file sdl_input_widget_pair_list.cpp.

34{
35 assert(labels.size() == initial.size());
36 assert(labels.size() == flags.size());
37 const std::vector<int> buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL };
38 const std::vector<std::string> buttonlabels = { "accept", "cancel" };
39
40 const size_t widget_width = 300;
41 const size_t widget_heigth = 50;
42
43 const size_t total_width = widget_width + widget_width;
44 const size_t input_height = labels.size() * (widget_heigth + vpadding) + vpadding;
45 const size_t total_height = input_height + widget_heigth;
46 assert(total_width <= INT32_MAX);
47 assert(total_height <= INT32_MAX);
48
49 if (reset(title, total_width, total_height))
50 {
51 for (size_t x = 0; x < labels.size(); x++)
52 {
53 std::shared_ptr<SdlInputWidgetPair> widget(new SdlInputWidgetPair(
54 _renderer, labels[x], initial[x], flags[x], x, widget_width, widget_heigth));
55 m_list.emplace_back(widget);
56 }
57
58 std::ignore = _buttons.populate(
59 _renderer, buttonlabels, buttonids, total_width, static_cast<Sint32>(input_height),
60 static_cast<Sint32>(widget_width), static_cast<Sint32>(widget_heigth));
61 _buttons.set_highlight(0);
62 m_currentActiveTextInput = selected;
63 }
64}

◆ ~SdlInputWidgetPairList()

SdlInputWidgetPairList::~SdlInputWidgetPairList ( )
override

Definition at line 111 of file sdl_input_widget_pair_list.cpp.

112{
113 m_list.clear();
114 _buttons.clear();
115}

Member Function Documentation

◆ get_index()

ssize_t SdlInputWidgetPairList::get_index ( const SDL_MouseButtonEvent &  button)
protected

Definition at line 130 of file sdl_input_widget_pair_list.cpp.

131{
132 const auto x = button.x;
133 const auto y = button.y;
134 for (size_t i = 0; i < m_list.size(); i++)
135 {
136 auto& cur = m_list[i];
137 auto r = cur->input_rect();
138
139 if ((x >= r.x) && (x <= r.x + r.w) && (y >= r.y) && (y <= r.y + r.h))
140 return WINPR_ASSERTING_INT_CAST(ssize_t, i);
141 }
142 return -1;
143}

◆ run()

int SdlInputWidgetPairList::run ( std::vector< std::string > &  result)

Definition at line 145 of file sdl_input_widget_pair_list.cpp.

146{
147 int res = -1;
148 ssize_t LastActiveTextInput = -1;
149 m_currentActiveTextInput = next(m_currentActiveTextInput);
150
151 if (!_window || !_renderer)
152 return -2;
153
154 if (!SDL_StartTextInput(_window.get()))
155 return -3;
156
157 try
158 {
159 bool running = true;
160 while (running)
161 {
162 if (!update())
163 throw;
164
165 SDL_Event event = {};
166 if (!SDL_WaitEvent(&event))
167 throw;
168 do
169 {
170 switch (event.type)
171 {
172 case SDL_EVENT_KEY_UP:
173 {
174 switch (event.key.key)
175 {
176 case SDLK_BACKSPACE:
177 {
178 auto cur = get(m_currentActiveTextInput);
179 if (cur)
180 {
181 if ((event.key.mod & SDL_KMOD_CTRL) != 0)
182 {
183 if (!cur->set_str(""))
184 throw;
185 }
186 else
187 {
188 if (!cur->remove_str(1))
189 throw;
190 }
191 }
192 }
193 break;
194 case SDLK_TAB:
195 m_currentActiveTextInput = next(m_currentActiveTextInput);
196 break;
197 case SDLK_RETURN:
198 case SDLK_RETURN2:
199 case SDLK_KP_ENTER:
200 running = false;
201 res = INPUT_BUTTON_ACCEPT;
202 break;
203 case SDLK_ESCAPE:
204 running = false;
205 res = INPUT_BUTTON_CANCEL;
206 break;
207 case SDLK_V:
208 if ((event.key.mod & SDL_KMOD_CTRL) != 0)
209 {
210 auto cur = get(m_currentActiveTextInput);
211 if (cur)
212 {
213 auto text = SDL_GetClipboardText();
214 if (!cur->set_str(text))
215 throw;
216 }
217 }
218 break;
219 default:
220 break;
221 }
222 }
223 break;
224 case SDL_EVENT_TEXT_INPUT:
225 {
226 auto cur = get(m_currentActiveTextInput);
227 if (cur)
228 {
229 if (!cur->append_str(event.text.text))
230 throw;
231 }
232 }
233 break;
234 case SDL_EVENT_MOUSE_MOTION:
235 {
236 auto TextInputIndex = get_index(event.button);
237 for (auto& cur : m_list)
238 {
239 cur->set_mouseover(false);
240 }
241 if (TextInputIndex >= 0)
242 {
243 auto& cur = m_list[static_cast<size_t>(TextInputIndex)];
244 cur->set_mouseover(true);
245 }
246
247 _buttons.set_mouseover(event.button.x, event.button.y);
248 }
249 break;
250 case SDL_EVENT_MOUSE_BUTTON_DOWN:
251 {
252 auto val = get_index(event.button);
253 if (valid(val))
254 m_currentActiveTextInput = val;
255
256 auto button = _buttons.get_selected(event.button);
257 if (button)
258 {
259 running = false;
260 if (button->id() == INPUT_BUTTON_CANCEL)
261 res = INPUT_BUTTON_CANCEL;
262 else
263 res = INPUT_BUTTON_ACCEPT;
264 }
265 }
266 break;
267 case SDL_EVENT_QUIT:
268 res = INPUT_BUTTON_CANCEL;
269 running = false;
270 break;
271 default:
272 break;
273 }
274 } while (SDL_PollEvent(&event));
275
276 if (LastActiveTextInput != m_currentActiveTextInput)
277 {
278 LastActiveTextInput = m_currentActiveTextInput;
279 }
280
281 for (auto& cur : m_list)
282 {
283 if (!cur->set_highlight(false))
284 throw;
285 }
286 auto cur = get(m_currentActiveTextInput);
287 if (cur)
288 {
289 if (!cur->set_highlight(true))
290 throw;
291 }
292
293 auto rc = SDL_RenderPresent(_renderer.get());
294 if (!rc)
295 {
296 SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "[%s] SDL_RenderPresent failed with %s",
297 __func__, SDL_GetError());
298 }
299 }
300
301 for (auto& cur : m_list)
302 result.push_back(cur->value());
303 }
304 catch (...)
305 {
306 res = -2;
307 }
308 if (!SDL_StopTextInput(_window.get()))
309 return -4;
310
311 return res;
312}

◆ updateInternal()

bool SdlInputWidgetPairList::updateInternal ( )
overrideprotectedvirtual

Implements SdlWidgetList.

Definition at line 117 of file sdl_input_widget_pair_list.cpp.

118{
119 for (auto& btn : m_list)
120 {
121 if (!btn->update())
122 return false;
123 if (!btn->update())
124 return false;
125 }
126
127 return true;
128}

The documentation for this class was generated from the following files: