2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
void pComboButton::append(string text) {
|
2011-02-24 09:25:20 +00:00
|
|
|
SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(wchar_t*)utf16_t(text));
|
|
|
|
if(SendMessage(hwnd, CB_GETCOUNT, 0, 0) == 1) setSelection(0);
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
Size pComboButton::minimumSize() {
|
2011-03-22 12:56:49 +00:00
|
|
|
unsigned maximumWidth = 0;
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& text : comboButton.state.text) maximumWidth = max(maximumWidth, pFont::size(hfont, text).width);
|
2013-03-15 13:11:33 +00:00
|
|
|
return {maximumWidth + 24, pFont::size(hfont, " ").height + 10};
|
2011-03-22 12:56:49 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pComboButton::remove(unsigned selection) {
|
2012-06-25 12:49:39 +00:00
|
|
|
locked = true;
|
2013-11-28 10:29:01 +00:00
|
|
|
SendMessage(hwnd, CB_DELETESTRING, selection, 0);
|
2012-06-25 12:49:39 +00:00
|
|
|
locked = false;
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
if(selection == comboButton.state.selection) comboButton.setSelection(0);
|
2012-06-25 12:49:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::reset() {
|
2011-02-24 09:25:20 +00:00
|
|
|
SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pComboButton::setGeometry(Geometry geometry) {
|
2013-12-11 11:19:17 +00:00
|
|
|
//height = minimum drop-down list height; use CB_SETITEMHEIGHT to control actual widget height
|
|
|
|
pWidget::setGeometry({geometry.x, geometry.y, geometry.width, 1});
|
2013-11-28 10:29:01 +00:00
|
|
|
RECT rc;
|
|
|
|
GetWindowRect(hwnd, &rc);
|
|
|
|
unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0));
|
|
|
|
SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::setSelection(unsigned selection) {
|
|
|
|
SendMessage(hwnd, CB_SETCURSEL, selection, 0);
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pComboButton::setText(unsigned selection, string text) {
|
|
|
|
locked = true;
|
|
|
|
SendMessage(hwnd, CB_DELETESTRING, selection, 0);
|
|
|
|
SendMessage(hwnd, CB_INSERTSTRING, selection, (LPARAM)(wchar_t*)utf16_t(text));
|
|
|
|
setSelection(comboButton.state.selection);
|
|
|
|
locked = false;
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::constructor() {
|
2011-02-24 09:25:20 +00:00
|
|
|
hwnd = CreateWindow(
|
|
|
|
L"COMBOBOX", L"",
|
2011-09-05 03:48:23 +00:00
|
|
|
WS_CHILD | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
|
2011-02-24 09:25:20 +00:00
|
|
|
0, 0, 0, 0,
|
2013-11-28 10:29:01 +00:00
|
|
|
parentHwnd, (HMENU)id, GetModuleHandle(0), 0
|
2011-02-24 09:25:20 +00:00
|
|
|
);
|
2013-03-15 13:11:33 +00:00
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&comboButton);
|
2011-02-24 09:25:20 +00:00
|
|
|
setDefaultFont();
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& text : comboButton.state.text) append(text);
|
2013-03-15 13:11:33 +00:00
|
|
|
setSelection(comboButton.state.selection);
|
2011-09-05 03:48:23 +00:00
|
|
|
synchronize();
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::destructor() {
|
2011-09-05 03:48:23 +00:00
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::orphan() {
|
2011-09-05 03:48:23 +00:00
|
|
|
destructor();
|
|
|
|
constructor();
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pComboButton::onChange() {
|
|
|
|
unsigned selection = SendMessage(hwnd, CB_GETCURSEL, 0, 0);
|
|
|
|
if(selection == comboButton.state.selection) return;
|
|
|
|
comboButton.state.selection = selection;
|
|
|
|
if(comboButton.onChange) comboButton.onChange();
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
}
|