-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlWithText.cpp
More file actions
54 lines (45 loc) · 1.6 KB
/
ControlWithText.cpp
File metadata and controls
54 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2020, The maxGUI Contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <maxGUI/ControlWithText.hpp>
#if defined(MAX_PLATFORM_WINDOWS)
#include <maxGUI/Win32String.hpp>
#endif
#include <utility>
namespace maxGUI
{
#if defined(MAX_PLATFORM_WINDOWS)
ControlWithText::ControlWithText(HWND window_handle) noexcept
: Control(std::move(window_handle))
{}
#elif defined(MAX_PLATFORM_LINUX)
ControlWithText::ControlWithText(QWidget* widget) noexcept
: Control(std::move(widget))
{}
#endif
std::string ControlWithText::GetText() const noexcept {
#if defined(MAX_PLATFORM_WINDOWS)
size_t length_in_chars = static_cast<size_t>(SendMessage(window_handle_, WM_GETTEXTLENGTH, 0, 0));
TCHAR* buffer = new wchar_t[length_in_chars];
SendMessage(window_handle_, WM_GETTEXT, length_in_chars, reinterpret_cast<LPARAM>(buffer));
Win32String win32_string(std::move(buffer), std::move(length_in_chars));
return Win32StringToUtf8(std::move(win32_string));
#endif
#if defined(MAX_PLATFORM_LINUX)
return std::string();
#endif
}
void ControlWithText::SetText(std::string text) noexcept {
#if defined(MAX_PLATFORM_WINDOWS)
Win32String win32_text = Utf8ToWin32String(std::move(text));
SendMessage(window_handle_, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(win32_text.text_));
#endif
#if defined(MAX_PLATFORM_LINUX)
(void)text;
#endif
}
ControlWithTextFactory::ControlWithTextFactory(Rectangle rectangle, std::string text) noexcept
: ControlFactory(std::move(rectangle))
, text_(std::move(text))
{}
} // namespace maxGUI