I need to provide a sign in function within my plugin. I'm using WDL-OL, and it looks like the only thing available for me to get text input is to have an IControl use IGraphics::CreateTextEntry(). This works well, but doesn't provide any option for hidden/password style text.
I see that the Tale IPlug library(among others) supplies an IEditableTextControl class that supports these features. However that control relies on a specific IGraphics::PromptUserInput(IEditableTextControl*) overload for this functionality.
The implementations for Tale PromptUserInput() and WDL-OL CreateTextEntry() are nearly identical. So I added the following in the IGraphicsWin class:
Code:
void IGraphicsWin::CreateTextEntryStyle(IControl* pControl, IText* pText, IRECT* pTextRect, const char* pString, IParam* pParam, bool pIsSecure, bool pIsEditable)
{
if (!pControl || mParamEditWnd) return;
DWORD editStyle;
switch ( pText->mAlign )
{
case IText::kAlignNear: editStyle = ES_LEFT; break;
case IText::kAlignFar: editStyle = ES_RIGHT; break;
case IText::kAlignCenter:
default: editStyle = ES_CENTER; break;
}
// Biggest difference from orignal function
if (!pIsEditable) editStyle |= ES_READONLY;
if (pIsSecure)
editStyle |= ES_PASSWORD;
else
editStyle |= ES_MULTILINE;
mParamEditWnd = CreateWindow("EDIT", pString, WS_CHILD | WS_VISIBLE | editStyle ,
pTextRect->L, pTextRect->T, pTextRect->W()+1, pTextRect->H()-2, // Original WDL-OL function use ->H()+1. Why? Just added whitespace to the bottom
mPlugWnd, (HMENU) PARAM_EDIT_ID, mHInstance, 0);
HFONT font = CreateFont(pText->mSize, 0, 0, 0, pText->mStyle == IText::kStyleBold ? FW_BOLD : 0, pText->mStyle == IText::kStyleItalic ? TRUE : 0, 0, 0, 0, 0, 0, 0, 0, pText->mFont);
SendMessage(mParamEditWnd, WM_SETFONT, (WPARAM) font, 0);
SendMessage(mParamEditWnd, EM_SETSEL, 0, -1);
Edit_LimitText(mParamEditWnd, pControl->GetTextEntryLength());
SetFocus(mParamEditWnd);
mDefEditProc = (WNDPROC) SetWindowLongPtr(mParamEditWnd, GWLP_WNDPROC, (LONG_PTR) ParamEditProc);
SetWindowLong(mParamEditWnd, GWLP_USERDATA, (LPARAM) this);
//SetWindowLongPtr(mParamEditWnd, GWLP_USERDATA, 0xdeadf00b); //this was from the Tale repo. For key input???
//DeleteObject(font);
mEdControl = pControl;
mEdParam = pParam; // could be 0
}
I added my own IEditableTextControl class that calls this function instead of PromptUserInfo() - and it works! I realize this is windows specific, and I will need to address the Mac side of it as well.
When using this new function I noticed that using password style text would give my input a box a white background, regardless of my controls mText.mTextEntryBGColor
To fix that I altered IGraphicsWin::WndProc():
Code:
case WM_CTLCOLOREDIT:
{
if(!pGraphics->mEdControl)
return 0;
IText* pText = pGraphics->mEdControl->GetText();
HDC dc = (HDC) wParam;
SetBkColor(dc, RGB(pText->mTextEntryBGColor.R, pText->mTextEntryBGColor.G, pText->mTextEntryBGColor.B));
SetTextColor(dc, RGB(pText->mTextEntryFGColor.R, pText->mTextEntryFGColor.G, pText->mTextEntryFGColor.B));
SetBkMode(dc, OPAQUE);
//return (BOOL)GetStockObject(DC_BRUSH);
// Added this:
HBRUSH hBrush = CreateSolidBrush(RGB(pText->mTextEntryBGColor.R, pText->mTextEntryBGColor.G, pText->mTextEntryBGColor.B));
SelectObject((HDC)wParam, (HGDIOBJ)hBrush);
return (BOOL)hBrush;
}
The difference is using CreateSolidBrush() instead of GetStockBrush(). This works well for ES_PASSWORD, but when using ES_READONLY, the background gets set to gray regardless. I don't know why.
I'm new to IPlug and I don't fully understand how everything in IGraphics might be interacting with these changes I made. So I'm wondering if this is the right/safe way to get these features.
Bonus Questions
-within WDL-OL CreateTextEntry(), the CreateWindow() call passes pTextRect->W+1 and pTextRect->H()+1. Whats the reason behind adding +1. H()+1 was adding white space to bottom of colored background area.
-Tale's PromptUserInput() uses the line
Code:
SetWindowLongPtr(mParamEditWnd, GWLP_USERDATA, 0xdeadf00b);
and WDL-OL uses the line
Code:
SetWindowLong(mParamEditWnd, GWLP_USERDATA, (LPARAM) this);
What's going on there?
Finally: Thank you.