summaryrefslogtreecommitdiff
path: root/new/button_windows.c
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-07 19:32:16 -0400
committerPietro Gagliardi <[email protected]>2015-04-07 19:32:16 -0400
commit42204af0865cd6c712b1f9b1e20694c1fc971503 (patch)
tree6e398429026632df2067a281c14dbe57970fec3a /new/button_windows.c
parent38eecd3fc3538c597a032c940519ffdb78cffd82 (diff)
Implemented uiButton.preferredSize() on Windows. This includes adding a function to get the width of text in a control.
Diffstat (limited to 'new/button_windows.c')
-rw-r--r--new/button_windows.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/new/button_windows.c b/new/button_windows.c
index 3725287..3eb7e1a 100644
--- a/new/button_windows.c
+++ b/new/button_windows.c
@@ -23,9 +23,30 @@ static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, void *data,
return FALSE;
}
+// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
+#define buttonHeight 14
+
static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height)
{
- // TODO
+ HWND hwnd;
+ SIZE size;
+
+ hwnd = (HWND) uiControlHandle(c);
+
+ // try the comctl32 version 6 way
+ size.cx = 0; // explicitly ask for ideal size
+ size.cy = 0;
+ if (SendMessageW(hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) {
+ *width = size.cx;
+ *height = size.cy;
+ return;
+ }
+
+ // that didn't work; fall back to using Microsoft's metrics
+ // 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(hwnd) + (2 * GetSystemMetrics(SM_CXEDGE));
+ *height = uiDlgUnitToY(buttonHeight, baseY);
}
static void defaultOnClicked(uiControl *c, void *data)