File style cleanup for the SDL 2.0 release
This commit is contained in:
parent
2ac8624930
commit
0cb6385637
376 changed files with 17562 additions and 17773 deletions
|
@ -36,28 +36,28 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
WORD dlgVer;
|
||||
WORD signature;
|
||||
DWORD helpID;
|
||||
DWORD exStyle;
|
||||
DWORD style;
|
||||
WORD cDlgItems;
|
||||
short x;
|
||||
short y;
|
||||
short cx;
|
||||
short cy;
|
||||
WORD dlgVer;
|
||||
WORD signature;
|
||||
DWORD helpID;
|
||||
DWORD exStyle;
|
||||
DWORD style;
|
||||
WORD cDlgItems;
|
||||
short x;
|
||||
short y;
|
||||
short cx;
|
||||
short cy;
|
||||
} DLGTEMPLATEEX;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DWORD helpID;
|
||||
DWORD exStyle;
|
||||
DWORD style;
|
||||
short x;
|
||||
short y;
|
||||
short cx;
|
||||
short cy;
|
||||
DWORD id;
|
||||
DWORD helpID;
|
||||
DWORD exStyle;
|
||||
DWORD style;
|
||||
short x;
|
||||
short y;
|
||||
short cx;
|
||||
short cy;
|
||||
DWORD id;
|
||||
} DLGITEMTEMPLATEEX;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
@ -76,7 +76,7 @@ static INT_PTR MessageBoxDialogProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPA
|
|||
switch ( iMessage ) {
|
||||
case WM_COMMAND:
|
||||
/* Return the ID of the button that was pushed */
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
|
@ -108,7 +108,7 @@ static SDL_bool ExpandDialogSpace(WIN_DialogData *dialog, size_t space)
|
|||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static SDL_bool AlignDialogData(WIN_DialogData *dialog, size_t size)
|
||||
{
|
||||
size_t padding = (dialog->used % size);
|
||||
|
@ -166,7 +166,7 @@ static int s_BaseUnitsX;
|
|||
static int s_BaseUnitsY;
|
||||
static void Vec2ToDLU(short *x, short *y)
|
||||
{
|
||||
SDL_assert(s_BaseUnitsX != 0); // we init in WIN_ShowMessageBox(), which is the only public function...
|
||||
SDL_assert(s_BaseUnitsX != 0); /* we init in WIN_ShowMessageBox(), which is the only public function... */
|
||||
|
||||
*x = MulDiv(*x, 4, s_BaseUnitsX);
|
||||
*y = MulDiv(*y, 8, s_BaseUnitsY);
|
||||
|
@ -265,37 +265,37 @@ static WIN_DialogData *CreateDialogData(int w, int h, const char *caption)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// No menu
|
||||
/* No menu */
|
||||
WordToPass = 0;
|
||||
if (!AddDialogData(dialog, &WordToPass, 2)) {
|
||||
FreeDialogData(dialog);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// No custom class
|
||||
/* No custom class */
|
||||
if (!AddDialogData(dialog, &WordToPass, 2)) {
|
||||
FreeDialogData(dialog);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// title
|
||||
/* title */
|
||||
if (!AddDialogString(dialog, caption)) {
|
||||
FreeDialogData(dialog);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Font stuff
|
||||
/* Font stuff */
|
||||
{
|
||||
//
|
||||
// We want to use the system messagebox font.
|
||||
//
|
||||
/*
|
||||
* We want to use the system messagebox font.
|
||||
*/
|
||||
BYTE ToPass;
|
||||
|
||||
|
||||
NONCLIENTMETRICSA NCM;
|
||||
NCM.cbSize = sizeof(NCM);
|
||||
SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0);
|
||||
|
||||
// Font size - convert to logical font size for dialog parameter.
|
||||
|
||||
/* Font size - convert to logical font size for dialog parameter. */
|
||||
{
|
||||
HDC ScreenDC = GetDC(0);
|
||||
WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / GetDeviceCaps(ScreenDC, LOGPIXELSY));
|
||||
|
@ -307,28 +307,28 @@ static WIN_DialogData *CreateDialogData(int w, int h, const char *caption)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Font weight
|
||||
/* Font weight */
|
||||
WordToPass = (WORD)NCM.lfMessageFont.lfWeight;
|
||||
if (!AddDialogData(dialog, &WordToPass, 2)) {
|
||||
FreeDialogData(dialog);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// italic?
|
||||
/* italic? */
|
||||
ToPass = NCM.lfMessageFont.lfItalic;
|
||||
if (!AddDialogData(dialog, &ToPass, 1)) {
|
||||
FreeDialogData(dialog);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// charset?
|
||||
/* charset? */
|
||||
ToPass = NCM.lfMessageFont.lfCharSet;
|
||||
if (!AddDialogData(dialog, &ToPass, 1)) {
|
||||
FreeDialogData(dialog);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// font typeface.
|
||||
/* font typeface. */
|
||||
if (!AddDialogString(dialog, NCM.lfMessageFont.lfFaceName)) {
|
||||
FreeDialogData(dialog);
|
||||
return NULL;
|
||||
|
@ -355,44 +355,44 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
const int ButtonHeight = 26;
|
||||
const int TextMargin = 16;
|
||||
const int ButtonMargin = 12;
|
||||
|
||||
|
||||
// Jan 25th, 2013 - dant@fleetsa.com
|
||||
//
|
||||
//
|
||||
// I've tried to make this more reasonable, but I've run in to a lot
|
||||
// of nonsense.
|
||||
//
|
||||
// The original issue is the code was written in pixels and not
|
||||
// dialog units (DLUs). All DialogBox functions use DLUs, which
|
||||
// vary based on the selected font (yay).
|
||||
//
|
||||
// According to MSDN, the most reliable way to convert is via
|
||||
// MapDialogUnits, which requires an HWND, which we don't have
|
||||
// at time of template creation.
|
||||
//
|
||||
// We do however have:
|
||||
// The system font (DLU width 8 for me)
|
||||
// The font we select for the dialog (DLU width 6 for me)
|
||||
//
|
||||
// Based on experimentation, *neither* of these return the value
|
||||
// actually used. Stepping in to MapDialogUnits(), the conversion
|
||||
// is fairly clear, and uses 7 for me.
|
||||
//
|
||||
// As a result, some of this is hacky to ensure the sizing is
|
||||
// somewhat correct.
|
||||
//
|
||||
// Honestly, a long term solution is to use CreateWindow, not CreateDialog.
|
||||
//
|
||||
|
||||
//
|
||||
// In order to get text dimensions we need to have a DC with the desired font.
|
||||
// I'm assuming a dialog box in SDL is rare enough we can to the create.
|
||||
//
|
||||
/* Jan 25th, 2013 - dant@fleetsa.com
|
||||
*
|
||||
*
|
||||
* I've tried to make this more reasonable, but I've run in to a lot
|
||||
* of nonsense.
|
||||
*
|
||||
* The original issue is the code was written in pixels and not
|
||||
* dialog units (DLUs). All DialogBox functions use DLUs, which
|
||||
* vary based on the selected font (yay).
|
||||
*
|
||||
* According to MSDN, the most reliable way to convert is via
|
||||
* MapDialogUnits, which requires an HWND, which we don't have
|
||||
* at time of template creation.
|
||||
*
|
||||
* We do however have:
|
||||
* The system font (DLU width 8 for me)
|
||||
* The font we select for the dialog (DLU width 6 for me)
|
||||
*
|
||||
* Based on experimentation, *neither* of these return the value
|
||||
* actually used. Stepping in to MapDialogUnits(), the conversion
|
||||
* is fairly clear, and uses 7 for me.
|
||||
*
|
||||
* As a result, some of this is hacky to ensure the sizing is
|
||||
* somewhat correct.
|
||||
*
|
||||
* Honestly, a long term solution is to use CreateWindow, not CreateDialog.
|
||||
*
|
||||
|
||||
*
|
||||
* In order to get text dimensions we need to have a DC with the desired font.
|
||||
* I'm assuming a dialog box in SDL is rare enough we can to the create.
|
||||
*/
|
||||
HDC FontDC = CreateCompatibleDC(0);
|
||||
|
||||
|
||||
{
|
||||
// Create a duplicate of the font used in system message boxes.
|
||||
/* Create a duplicate of the font used in system message boxes. */
|
||||
LOGFONT lf;
|
||||
NONCLIENTMETRICS NCM;
|
||||
NCM.cbSize = sizeof(NCM);
|
||||
|
@ -401,40 +401,40 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
DialogFont = CreateFontIndirect(&lf);
|
||||
}
|
||||
|
||||
// Select the font in to our DC
|
||||
/* Select the font in to our DC */
|
||||
SelectObject(FontDC, DialogFont);
|
||||
|
||||
{
|
||||
// Get the metrics to try and figure our DLU conversion.
|
||||
/* Get the metrics to try and figure our DLU conversion. */
|
||||
GetTextMetrics(FontDC, &TM);
|
||||
s_BaseUnitsX = TM.tmAveCharWidth + 1;
|
||||
s_BaseUnitsY = TM.tmHeight;
|
||||
}
|
||||
|
||||
// Measure the *pixel* size of the string.
|
||||
|
||||
/* Measure the *pixel* size of the string. */
|
||||
wmessage = WIN_UTF8ToString(messageboxdata->message);
|
||||
SDL_zero(TextSize);
|
||||
Size.cx = DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT);
|
||||
|
||||
// Add some padding for hangs, etc.
|
||||
/* Add some padding for hangs, etc. */
|
||||
TextSize.right += 2;
|
||||
TextSize.bottom += 2;
|
||||
|
||||
// Done with the DC, and the string
|
||||
/* Done with the DC, and the string */
|
||||
DeleteDC(FontDC);
|
||||
SDL_free(wmessage);
|
||||
|
||||
// Increase the size of the dialog by some border spacing around the text.
|
||||
/* Increase the size of the dialog by some border spacing around the text. */
|
||||
Size.cx = TextSize.right - TextSize.left;
|
||||
Size.cy = TextSize.bottom - TextSize.top;
|
||||
Size.cx += TextMargin * 2;
|
||||
Size.cy += TextMargin * 2;
|
||||
|
||||
// Ensure the size is wide enough for all of the buttons.
|
||||
/* Ensure the size is wide enough for all of the buttons. */
|
||||
if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin)
|
||||
Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin;
|
||||
|
||||
// Add vertical space for the buttons and border.
|
||||
/* Add vertical space for the buttons and border. */
|
||||
Size.cy += ButtonHeight + TextMargin;
|
||||
|
||||
dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title);
|
||||
|
@ -447,7 +447,7 @@ WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// Align the buttons to the right/bottom.
|
||||
/* Align the buttons to the right/bottom. */
|
||||
x = Size.cx - ButtonWidth - ButtonMargin;
|
||||
y = Size.cy - ButtonHeight - ButtonMargin;
|
||||
for (i = 0; i < messageboxdata->numbuttons; ++i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue