Trimming added

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@764 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-08-28 10:07:30 +00:00
parent df398575ae
commit 4f1efc6c40

View file

@ -311,6 +311,64 @@ void CDialogTemplate::DlgUnitsToPixels(short& x, short& y) {
y = float(y) * (float(r.bottom)/1024);
}
// Returns the size of a string in the dialog (in dialog units)
SIZE CDialogTemplate::GetStringSize(char *str) {
DWORD dwTemp;
BYTE* pbDlg = Save(dwTemp);
HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0);
delete [] pbDlg;
SIZE size;
GetTextExtentPoint32(GetDC(hDlg), str, lstrlen(str), &size);
DestroyWindow(hDlg);
PixelsToDlgUnits((short&)size.cx, (short&)size.cy);
return size;
}
// Trims the right margins of a control to fit a given text string size.
void CDialogTemplate::RTrimToString(WORD id, char *str, int margins) {
DialogItemTemplate* item = GetItem(id);
if (!item) return;
SIZE size = GetStringSize(str);
size.cx += margins;
item->sWidth = size.cx;
item->sHeight = size.cy;
}
// Trims the left margins of a control to fit a given text string size.
void CDialogTemplate::LTrimToString(WORD id, char *str, int margins) {
DialogItemTemplate* item = GetItem(id);
if (!item) return;
SIZE size = GetStringSize(str);
size.cx += margins;
item->sX += item->sWidth - size.cx;
item->sWidth = size.cx;
item->sHeight = size.cy;
}
// Trims the left and right margins of a control to fit a given text string size.
void CDialogTemplate::CTrimToString(WORD id, char *str, int margins) {
DialogItemTemplate* item = GetItem(id);
if (!item) return;
SIZE size = GetStringSize(str);
size.cx += margins;
item->sX += item->sWidth/2 - size.cx/2;
item->sWidth = size.cx;
item->sHeight = size.cy;
}
// Saves the dialog in the form of DLGTEMPLATE[EX]
BYTE* CDialogTemplate::Save(DWORD& dwSize) {
// We need the size first to know how much memory to allocate