From f16f287b979fd6459203604e10c1977ff88d3d43 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 29 Apr 2016 12:18:46 -0400 Subject: [PATCH] Migrated button.cpp. Allowed NULL out parameters in the uiWindowsSizing functions. --- windows/button.cpp | 29 +++++++++++++++++++---------- windows/sizing.cpp | 12 ++++++++---- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/windows/button.cpp b/windows/button.cpp index fe46366f..1556fdd1 100644 --- a/windows/button.cpp +++ b/windows/button.cpp @@ -8,11 +8,6 @@ struct uiButton { void *onClickedData; }; -uiWindowsDefineControlWithOnDestroy( - uiButton, // type name - uiWindowsUnregisterWM_COMMANDHandler(me->hwnd); // on destroy -) - static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) { uiButton *b = uiButton(c); @@ -24,13 +19,26 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) return TRUE; } +static void uiButtonDestroy(uiControl *c) +{ + uiButton *b = uiButton(c); + + uiWindowsUnregisterWM_COMMANDHandler(b->hwnd); + uiWindowsEnsureDestroyWindow(b->hwnd); + uiFreeControl(b->hwnd); +} + +uiWindowsControlAllDefaultsExceptDestroy(uiButton) + // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing #define buttonHeight 14 -static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height) +static void uiButtonMinimumSize(uiWindowsControl *c, intmax_t *width, intmax_t *height) { uiButton *b = uiButton(c); SIZE size; + uiWindowsSizing sizing; + int y; // try the comctl32 version 6 way size.cx = 0; // explicitly ask for ideal size @@ -45,7 +53,10 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width // Microsoft says to use a fixed width for all buttons; this isn't good enough // use the text width instead, with some edge padding *width = uiWindowsWindowTextWidth(b->hwnd) + (2 * GetSystemMetrics(SM_CXEDGE)); - *height = uiWindowsDlgUnitsToY(buttonHeight, d->BaseY); + y = buttonHeight; + uiWindowsGetSizing(b->hwnd, &sizing); + uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); + *height = y; } static void defaultOnClicked(uiButton *b, void *data) @@ -76,7 +87,7 @@ uiButton *uiNewButton(const char *text) uiButton *b; WCHAR *wtext; - b = (uiButton *) uiNewControl(uiButton); + uiWindowsNewControl(uiButton, b); wtext = toUTF16(text); b->hwnd = uiWindowsEnsureCreateControlHWND(0, @@ -89,7 +100,5 @@ uiButton *uiNewButton(const char *text) uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); uiButtonOnClicked(b, defaultOnClicked, NULL); - uiWindowsFinishNewControl(b, uiButton); - return b; } diff --git a/windows/sizing.cpp b/windows/sizing.cpp index a5079575..fd3358d3 100644 --- a/windows/sizing.cpp +++ b/windows/sizing.cpp @@ -39,8 +39,10 @@ void uiWindowsGetSizing(HWND hwnd, uiWindowsSizing *sizing); void uiWindowsSizingDlgUnitsToPixels(uiWindowsSIzing *sizing, int *x, int *y) { - *x = dlgUnitsToX(*x, sizing->BaseX); - *y = dlgUnitsToY(*y, sizing->BaseY); + if (x != NULL) + *x = dlgUnitsToX(*x, sizing->BaseX); + if (y != NULL) + *y = dlgUnitsToY(*y, sizing->BaseY); } // from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing and https://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx @@ -50,6 +52,8 @@ void uiWindowsSizingDlgUnitsToPixels(uiWindowsSIzing *sizing, int *x, int *y) void uiWindowsSizingStandardPadding(uiWindowsSizing *sizing, int *x, int *y) { - *x = dlgUnitsToX(winXPadding, sizing->BaseX); - *y = dlgUnitsToY(winYPadding, sizing->BaseY); + if (x != NULL) + *x = dlgUnitsToX(winXPadding, sizing->BaseX); + if (y != NULL) + *y = dlgUnitsToY(winYPadding, sizing->BaseY); }