2015-06-12 13:14:38 +00:00
|
|
|
#if defined(Hiro_ComboButton)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
auto pComboButton::construct() -> void {
|
|
|
|
hwnd = CreateWindow(
|
|
|
|
L"COMBOBOX", L"",
|
|
|
|
WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
_parentHandle(), nullptr, GetModuleHandle(0), 0
|
|
|
|
);
|
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
|
|
|
|
pWidget::_setState();
|
|
|
|
for(auto& item : state().items) append(item);
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pComboButton::destruct() -> void {
|
|
|
|
DestroyWindow(hwnd);
|
2011-03-22 12:56:49 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pComboButton::append(sComboButtonItem item) -> void {
|
|
|
|
lock();
|
|
|
|
SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(wchar_t*)utf16_t(item->state.text));
|
|
|
|
if(item->state.selected) SendMessage(hwnd, CB_SETCURSEL, item->offset(), 0);
|
|
|
|
if(SendMessage(hwnd, CB_GETCURSEL, 0, 0) == CB_ERR) item->setSelected();
|
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pComboButton::minimumSize() const -> Size {
|
|
|
|
signed width = 0;
|
|
|
|
for(auto& item : state().items) {
|
|
|
|
width = max(width, pFont::size(hfont, item->state.text).width());
|
|
|
|
}
|
|
|
|
return {width + 24, pFont::size(hfont, " ").height() + 10};
|
|
|
|
}
|
2012-06-25 12:49:39 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pComboButton::remove(sComboButtonItem item) -> void {
|
|
|
|
lock();
|
|
|
|
SendMessage(hwnd, CB_DELETESTRING, item->offset(), 0);
|
|
|
|
if(item->state.selected) SendMessage(hwnd, CB_SETCURSEL, 0, 0);
|
|
|
|
unlock();
|
2012-06-25 12:49:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pComboButton::reset() -> void {
|
2011-02-24 09:25:20 +00:00
|
|
|
SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pComboButton::setGeometry(Geometry geometry) -> void {
|
2013-12-11 11:19:17 +00:00
|
|
|
//height = minimum drop-down list height; use CB_SETITEMHEIGHT to control actual widget height
|
2015-06-12 13:14:38 +00:00
|
|
|
pWidget::setGeometry({geometry.x(), geometry.y(), geometry.width(), 1});
|
2013-11-28 10:29:01 +00:00
|
|
|
RECT rc;
|
|
|
|
GetWindowRect(hwnd, &rc);
|
2015-06-12 13:14:38 +00:00
|
|
|
unsigned adjustedHeight = geometry.height() - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0));
|
2013-11-28 10:29:01 +00:00
|
|
|
SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight);
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pComboButton::onChange() -> void {
|
|
|
|
signed offset = SendMessage(hwnd, CB_GETCURSEL, 0, 0);
|
|
|
|
if(offset == CB_ERR) return;
|
|
|
|
for(auto& item : state().items) item->state.selected = false;
|
|
|
|
if(auto item = self().item(offset)) item->setSelected();
|
|
|
|
self().doChange();
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
#endif
|