-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_editwithbuttons.h
103 lines (77 loc) · 2.06 KB
/
my_editwithbuttons.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#include "resource.h"
#include "foo_discogs.h"
#include "tags.h"
#include "libPPUI/CEditWithButtons.h"
class CMyEditWithButtons : public CEditWithButtons {
public:
typedef CEditWithButtons TParent;
BEGIN_MSG_MAP_EX(CMyEditWithButtons)
MSG_WM_SETFOCUS(OnSetFocus)
MSG_WM_KILLFOCUS(OnKillFocus)
CHAIN_MSG_MAP(TParent)
END_MSG_MAP()
CMyEditWithButtons() : CEditWithButtons(), m_stdf_call_history(nullptr)
{
m_bMsgHandled = true;
}
void OnSetFocus(HWND hWnd)
{
DefWindowProc();
}
void OnKillFocus(HWND hWnd)
{
DefWindowProc();
}
void SetHistoryHandler(std::function<bool(HWND, wchar_t* wchart)> stdf_call_history) {
m_stdf_call_history = stdf_call_history;
std::wstring histValCopy(L"");
auto condition_hist = [histValCopy](const wchar_t* txt) -> bool {
return CONF.history_enabled();
};
auto handler_onHistKey = [this, histValCopy] {
wchar_t wstr[MAX_PATH + 1] = {};
GetWindowText(wstr, MAX_PATH);
bool updated = this->m_stdf_call_history(this->m_hWnd, wstr);
if (updated) {
std::wstring updValCopy(wstr);
SetWindowText(updValCopy.c_str());
::SetFocus(this->m_hWnd);
}
return updated;
};
AddButton(L"more", handler_onHistKey, condition_hist, L"\x2026");
}
void SetEnterEscHandlers() {
auto handler_onEnterKey = [this] {
return false;
};
std::wstring clearValCopy(L"");
auto handler_onClearKey = [this, clearValCopy] {
this->SetWindowText(clearValCopy.c_str());
return false;
};
auto condition_clear = [clearValCopy](const wchar_t* txt) -> bool {
return clearValCopy != txt;
};
this->onEnterKey = handler_onEnterKey;
AddButton(L"clear", handler_onClearKey, condition_clear, L"\x00D7");
}
void FocusClear() {
HWND wnd = this->GetNextDlgTabItem(m_hWnd, FALSE);
if (wnd) {
::SetFocus(wnd);
}
}
void SetEnterOverride(std::function<bool()>stdf_func) {
if (stdf_func) {
this->onEnterKey = stdf_func;
}
else {
this->onEnterKey = nullptr;
this->onEscKey = nullptr;
}
}
private:
std::function<bool(HWND, wchar_t* wstr)> m_stdf_call_history;
};