2011-02-24 09:25:20 +00:00
|
|
|
void pComboBox::append(const string &text) {
|
|
|
|
SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)(wchar_t*)utf16_t(text));
|
|
|
|
if(SendMessage(hwnd, CB_GETCOUNT, 0, 0) == 1) setSelection(0);
|
|
|
|
}
|
|
|
|
|
2011-03-22 12:56:49 +00:00
|
|
|
Geometry pComboBox::minimumGeometry() {
|
|
|
|
unsigned maximumWidth = 0;
|
2011-09-27 11:55:02 +00:00
|
|
|
for(auto &text : comboBox.state.text) maximumWidth = max(maximumWidth, pFont::geometry(hfont, text).width);
|
2011-09-05 03:48:23 +00:00
|
|
|
return { 0, 0, maximumWidth + 24, pFont::geometry(hfont, " ").height + 10 };
|
2011-03-22 12:56:49 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 12:49:39 +00:00
|
|
|
void pComboBox::modify(unsigned row, const string &text) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::remove(unsigned row) {
|
|
|
|
locked = true;
|
|
|
|
unsigned position = selection();
|
|
|
|
SendMessage(hwnd, CB_DELETESTRING, row, 0);
|
|
|
|
if(position == row) setSelection(0);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
2011-02-24 09:25:20 +00:00
|
|
|
void pComboBox::reset() {
|
|
|
|
SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned pComboBox::selection() {
|
|
|
|
return SendMessage(hwnd, CB_GETCURSEL, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::setSelection(unsigned row) {
|
|
|
|
SendMessage(hwnd, CB_SETCURSEL, row, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::constructor() {
|
|
|
|
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
|
|
|
);
|
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&comboBox);
|
|
|
|
setDefaultFont();
|
2011-09-27 11:55:02 +00:00
|
|
|
for(auto &text : comboBox.state.text) append(text);
|
2011-02-24 09:25:20 +00:00
|
|
|
setSelection(comboBox.state.selection);
|
2011-09-05 03:48:23 +00:00
|
|
|
synchronize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::destructor() {
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboBox::setGeometry(const Geometry &geometry) {
|
|
|
|
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
|
|
|
}
|