Trim now works like it should

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@790 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-08-28 20:15:58 +00:00
parent 4284744e89
commit 2053e07fe5

View file

@ -77,7 +77,6 @@ void ReadVarLenArr(BYTE* &seeker, char* &readInto) {
// A macro that adds the size of x (which can be a string a number, or nothing) to dwSize // A macro that adds the size of x (which can be a string a number, or nothing) to dwSize
#define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : (lstrlen(x)+1)*sizeof(WCHAR)) : sizeof(WORD) #define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : (lstrlen(x)+1)*sizeof(WCHAR)) : sizeof(WORD)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Construction/Destruction // Construction/Destruction
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -279,49 +278,57 @@ void CDialogTemplate::MoveAllAndResize(short x, short y) {
m_sHeight += y; m_sHeight += y;
} }
// Converts pixels to this dialog's units // Creates a dummy dialog that is used for converting units
void CDialogTemplate::PixelsToDlgUnits(short& x, short& y) { HWND CDialogTemplate::CreateDummyDialog() {
DWORD dwTemp; DWORD dwTemp;
BYTE* pbDlg = Save(dwTemp); BYTE* pbDlg = Save(dwTemp);
HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0); HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0);
delete [] pbDlg; delete [] pbDlg;
if (!hDlg) if (!hDlg)
throw runtime_error("Can't create dialog from template!"); throw runtime_error("Can't create dialog from template!");
RECT r = {0, 0, 1024, 1024};
return hDlg;
}
// Converts pixels to this dialog's units
void CDialogTemplate::PixelsToDlgUnits(short& x, short& y) {
HWND hDlg = CreateDummyDialog();
RECT r = {0, 0, 10000, 10000};
MapDialogRect(hDlg, &r); MapDialogRect(hDlg, &r);
DestroyWindow(hDlg); DestroyWindow(hDlg);
x = float(x) / (float(r.right)/1024); x = float(x) / (float(r.right)/10000);
y = float(y) / (float(r.bottom)/1024); y = float(y) / (float(r.bottom)/10000);
} }
// Converts pixels to this dialog's units // Converts pixels to this dialog's units
void CDialogTemplate::DlgUnitsToPixels(short& x, short& y) { void CDialogTemplate::DlgUnitsToPixels(short& x, short& y) {
DWORD dwTemp; HWND hDlg = CreateDummyDialog();
BYTE* pbDlg = Save(dwTemp); RECT r = {0, 0, 10000, 10000};
HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0);
delete [] pbDlg;
if (!hDlg)
throw runtime_error("Can't create dialog from template!");
RECT r = {0, 0, 1024, 1024};
MapDialogRect(hDlg, &r); MapDialogRect(hDlg, &r);
DestroyWindow(hDlg); DestroyWindow(hDlg);
x = float(x) * (float(r.right)/1024); x = float(x) * (float(r.right)/10000);
y = float(y) * (float(r.bottom)/1024); y = float(y) * (float(r.bottom)/10000);
} }
// Returns the size of a string in the dialog (in dialog units) // Returns the size of a string in the dialog (in dialog units)
SIZE CDialogTemplate::GetStringSize(char *str) { SIZE CDialogTemplate::GetStringSize(WORD id, char *str) {
DWORD dwTemp; HWND hDlg = CreateDummyDialog();
BYTE* pbDlg = Save(dwTemp);
HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0); LOGFONT f;
delete [] pbDlg; GetObject((HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0), sizeof(LOGFONT), &f);
HDC memDC = CreateCompatibleDC(GetDC(hDlg));
HFONT font = CreateFontIndirect(&f);
SelectObject(memDC, font);
SIZE size; SIZE size;
GetTextExtentPoint32(GetDC(hDlg), str, lstrlen(str), &size); GetTextExtentPoint32(memDC, str, lstrlen(str), &size);
DestroyWindow(hDlg); DestroyWindow(hDlg);
DeleteObject(font);
DeleteDC(memDC);
PixelsToDlgUnits((short&)size.cx, (short&)size.cy); PixelsToDlgUnits((short&)size.cx, (short&)size.cy);
@ -333,9 +340,10 @@ void CDialogTemplate::RTrimToString(WORD id, char *str, int margins) {
DialogItemTemplate* item = GetItem(id); DialogItemTemplate* item = GetItem(id);
if (!item) return; if (!item) return;
SIZE size = GetStringSize(str); SIZE size = GetStringSize(id, str);
size.cx += margins; size.cx += margins;
size.cy += 2;
item->sWidth = size.cx; item->sWidth = size.cx;
item->sHeight = size.cy; item->sHeight = size.cy;
@ -346,9 +354,10 @@ void CDialogTemplate::LTrimToString(WORD id, char *str, int margins) {
DialogItemTemplate* item = GetItem(id); DialogItemTemplate* item = GetItem(id);
if (!item) return; if (!item) return;
SIZE size = GetStringSize(str); SIZE size = GetStringSize(id, str);
size.cx += margins; size.cx += margins;
size.cy += 2;
item->sX += item->sWidth - size.cx; item->sX += item->sWidth - size.cx;
item->sWidth = size.cx; item->sWidth = size.cx;
@ -360,9 +369,10 @@ void CDialogTemplate::CTrimToString(WORD id, char *str, int margins) {
DialogItemTemplate* item = GetItem(id); DialogItemTemplate* item = GetItem(id);
if (!item) return; if (!item) return;
SIZE size = GetStringSize(str); SIZE size = GetStringSize(id, str);
size.cx += margins; size.cx += margins;
size.cy += 2;
item->sX += item->sWidth/2 - size.cx/2; item->sX += item->sWidth/2 - size.cx/2;
item->sWidth = size.cx; item->sWidth = size.cx;