Added uiEditableCombobox on Windows.
This commit is contained in:
parent
ce338bcaaf
commit
095e08bc79
|
@ -18,6 +18,9 @@ This README is being written.<br>
|
||||||
|
|
||||||
*Note that today's entry may be updated later today.*
|
*Note that today's entry may be updated later today.*
|
||||||
|
|
||||||
|
* **24 May 2016**
|
||||||
|
* As promised, `uiCombobox` is now split into `uiCombobox` for non-editable comboboxes and `uiEditableCombobox` for editable comboboxes. Mind the function changes as well :)
|
||||||
|
|
||||||
* **23 May 2016**
|
* **23 May 2016**
|
||||||
* Fixed surrogate pair drawing on OS X.
|
* Fixed surrogate pair drawing on OS X.
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ CXXFILES += \
|
||||||
windows/drawpath.cpp \
|
windows/drawpath.cpp \
|
||||||
windows/drawtext.cpp \
|
windows/drawtext.cpp \
|
||||||
windows/dwrite.cpp \
|
windows/dwrite.cpp \
|
||||||
|
windows/editablecombo.cpp \
|
||||||
windows/entry.cpp \
|
windows/entry.cpp \
|
||||||
windows/events.cpp \
|
windows/events.cpp \
|
||||||
windows/fontbutton.cpp \
|
windows/fontbutton.cpp \
|
||||||
|
|
|
@ -13,7 +13,6 @@ struct uiCombobox {
|
||||||
void *onSelectedData;
|
void *onSelectedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: NOT triggered on entering text
|
|
||||||
static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult)
|
static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult)
|
||||||
{
|
{
|
||||||
uiCombobox *c = uiCombobox(cc);
|
uiCombobox *c = uiCombobox(cc);
|
||||||
|
@ -95,7 +94,7 @@ void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), v
|
||||||
c->onSelectedData = data;
|
c->onSelectedData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uiCombobox *finishNewCombobox(DWORD style)
|
uiCombobox *uiNewCombobox(void)
|
||||||
{
|
{
|
||||||
uiCombobox *c;
|
uiCombobox *c;
|
||||||
|
|
||||||
|
@ -103,7 +102,7 @@ static uiCombobox *finishNewCombobox(DWORD style)
|
||||||
|
|
||||||
c->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
|
c->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
|
||||||
L"combobox", L"",
|
L"combobox", L"",
|
||||||
style | WS_TABSTOP,
|
CBS_DROPDOWNLIST | WS_TABSTOP,
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
|
@ -112,13 +111,3 @@ static uiCombobox *finishNewCombobox(DWORD style)
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiCombobox *uiNewCombobox(void)
|
|
||||||
{
|
|
||||||
return finishNewCombobox(CBS_DROPDOWNLIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
uiCombobox *uiNewEditableCombobox(void)
|
|
||||||
{
|
|
||||||
return finishNewCombobox(CBS_DROPDOWN);
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
// 20 may 2015
|
||||||
|
#include "uipriv_windows.hpp"
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// - is there extra space on the bottom?
|
||||||
|
|
||||||
|
// we as Common Controls 6 users don't need to worry about the height of comboboxes; see http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx
|
||||||
|
|
||||||
|
struct uiEditableCombobox {
|
||||||
|
uiWindowsControl c;
|
||||||
|
HWND hwnd;
|
||||||
|
void (*onChanged)(uiEditableCombobox *, void *);
|
||||||
|
void *onChangedData;
|
||||||
|
};
|
||||||
|
|
||||||
|
static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult)
|
||||||
|
{
|
||||||
|
uiEditableCombobox *c = uiEditableCombobox(cc);
|
||||||
|
|
||||||
|
if (code == CBN_SELCHANGE) {
|
||||||
|
// like on OS X, this is sent before the edit has been updated :(
|
||||||
|
// TODO error check
|
||||||
|
// TODO proper function for GetAncestor()
|
||||||
|
PostMessage(GetAncestor(hwnd, GA_PARENT),
|
||||||
|
WM_COMMAND,
|
||||||
|
MAKEWPARAM(GetWindowLongPtrW(hwnd, GWLP_ID), CBN_EDITCHANGE),
|
||||||
|
(LPARAM) hwnd);
|
||||||
|
*lResult = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if (code != CBN_EDITCHANGE)
|
||||||
|
return FALSE;
|
||||||
|
(*(c->onChanged))(c, c->onChangedData);
|
||||||
|
*lResult = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiEditableComboboxDestroy(uiControl *cc)
|
||||||
|
{
|
||||||
|
uiEditableCombobox *c = uiEditableCombobox(cc);
|
||||||
|
|
||||||
|
uiWindowsUnregisterWM_COMMANDHandler(c->hwnd);
|
||||||
|
uiWindowsEnsureDestroyWindow(c->hwnd);
|
||||||
|
uiFreeControl(uiControl(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
uiWindowsControlAllDefaultsExceptDestroy(uiEditableCombobox)
|
||||||
|
|
||||||
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
|
#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary; TODO */
|
||||||
|
#define comboboxHeight 14
|
||||||
|
|
||||||
|
static void uiEditableComboboxMinimumSize(uiWindowsControl *cc, intmax_t *width, intmax_t *height)
|
||||||
|
{
|
||||||
|
uiEditableCombobox *c = uiEditableCombobox(cc);
|
||||||
|
uiWindowsSizing sizing;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
x = comboboxWidth;
|
||||||
|
y = comboboxHeight;
|
||||||
|
uiWindowsGetSizing(c->hwnd, &sizing);
|
||||||
|
uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y);
|
||||||
|
*width = x;
|
||||||
|
*height = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defaultOnChanged(uiEditableCombobox *c, void *data)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text)
|
||||||
|
{
|
||||||
|
WCHAR *wtext;
|
||||||
|
LRESULT res;
|
||||||
|
|
||||||
|
wtext = toUTF16(text);
|
||||||
|
res = SendMessageW(c->hwnd, CB_ADDSTRING, 0, (LPARAM) wtext);
|
||||||
|
if (res == (LRESULT) CB_ERR)
|
||||||
|
logLastError(L"error appending item to uiEditableCombobox");
|
||||||
|
else if (res == (LRESULT) CB_ERRSPACE)
|
||||||
|
logLastError(L"memory exhausted appending item to uiEditableCombobox");
|
||||||
|
uiFree(wtext);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *uiEditableComboboxText(uiEditableCombobox *c)
|
||||||
|
{
|
||||||
|
return uiWindowsWindowText(c->hwnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text)
|
||||||
|
{
|
||||||
|
// does not trigger any notifications
|
||||||
|
uiWindowsSetWindowText(c->hwnd, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiEditableComboboxOnChanged(uiEditableCombobox *c, void (*f)(uiEditableCombobox *c, void *data), void *data)
|
||||||
|
{
|
||||||
|
c->onChanged = f;
|
||||||
|
c->onChangedData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
uiEditableCombobox *uiNewEditableCombobox(void)
|
||||||
|
{
|
||||||
|
uiEditableCombobox *c;
|
||||||
|
|
||||||
|
uiWindowsNewControl(uiEditableCombobox, c);
|
||||||
|
|
||||||
|
c->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
|
||||||
|
L"combobox", L"",
|
||||||
|
CBS_DROPDOWN | WS_TABSTOP,
|
||||||
|
hInstance, NULL,
|
||||||
|
TRUE);
|
||||||
|
|
||||||
|
uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c));
|
||||||
|
uiEditableComboboxOnChanged(c, defaultOnChanged, NULL);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
Loading…
Reference in New Issue