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-07-29 09:42:45 +00:00
|
|
|
void pComboButton::modify(unsigned row, string text) {
|
2012-06-25 12:49:39 +00:00
|
|
|
locked = true;
|
|
|
|
unsigned position = selection();
|
|
|
|
SendMessage(hwnd, CB_DELETESTRING, row, 0);
|
|
|
|
SendMessage(hwnd, CB_INSERTSTRING, row, (LPARAM)(wchar_t*)utf16_t(text));
|
|
|
|
setSelection(position);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::remove(unsigned row) {
|
2012-06-25 12:49:39 +00:00
|
|
|
locked = true;
|
|
|
|
unsigned position = selection();
|
|
|
|
SendMessage(hwnd, CB_DELETESTRING, row, 0);
|
|
|
|
if(position == row) setSelection(0);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
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-03-15 13:11:33 +00:00
|
|
|
unsigned pComboButton::selection() {
|
2011-02-24 09:25:20 +00:00
|
|
|
return SendMessage(hwnd, CB_GETCURSEL, 0, 0);
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
void pComboButton::setSelection(unsigned row) {
|
2011-02-24 09:25:20 +00:00
|
|
|
SendMessage(hwnd, CB_SETCURSEL, row, 0);
|
|
|
|
}
|
|
|
|
|
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,
|
2011-09-05 03:48:23 +00:00
|
|
|
parentWindow->p.hwnd, (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-07-29 09:42:45 +00:00
|
|
|
void pComboButton::setGeometry(Geometry geometry) {
|
2011-09-05 03:48:23 +00:00
|
|
|
SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER);
|
|
|
|
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);
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
}
|