Migrated windows/button.c. This might be better; I don't know yet...
This commit is contained in:
parent
de2025b156
commit
5e5df97642
|
@ -7,10 +7,6 @@ This file assumes that you have included <windows.h> and "ui.h" beforehand. It p
|
||||||
#ifndef __UI_UI_WINDOWS_H__
|
#ifndef __UI_UI_WINDOWS_H__
|
||||||
#define __UI_UI_WINDOWS_H__
|
#define __UI_UI_WINDOWS_H__
|
||||||
|
|
||||||
// Correctness macros.
|
|
||||||
#define uiControlHWND(c) ((HWND) uiControlHandle(c))
|
|
||||||
#define uiParentHWND(p) ((HWND) uiParentHandle(p))
|
|
||||||
|
|
||||||
// uiWindowsNewControl() initializes the given uiControl with the given Windows API control inside.
|
// uiWindowsNewControl() initializes the given uiControl with the given Windows API control inside.
|
||||||
// You will need to provide the preferredSize() method yourself.
|
// You will need to provide the preferredSize() method yourself.
|
||||||
typedef struct uiWindowsNewControlParams uiWindowsNewControlParams;
|
typedef struct uiWindowsNewControlParams uiWindowsNewControlParams;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
struct button {
|
struct button {
|
||||||
uiButton b;
|
uiButton b;
|
||||||
|
HWND hwnd;
|
||||||
void (*onClicked)(uiButton *, void *);
|
void (*onClicked)(uiButton *, void *);
|
||||||
void *onClickedData;
|
void *onClickedData;
|
||||||
};
|
};
|
||||||
|
@ -35,15 +36,13 @@ static void onWM_DESTROY(uiControl *c)
|
||||||
|
|
||||||
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||||
{
|
{
|
||||||
HWND hwnd;
|
struct button *b = (struct button *) c;
|
||||||
SIZE size;
|
SIZE size;
|
||||||
|
|
||||||
hwnd = uiControlHWND(c);
|
|
||||||
|
|
||||||
// try the comctl32 version 6 way
|
// try the comctl32 version 6 way
|
||||||
size.cx = 0; // explicitly ask for ideal size
|
size.cx = 0; // explicitly ask for ideal size
|
||||||
size.cy = 0;
|
size.cy = 0;
|
||||||
if (SendMessageW(hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) {
|
if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) {
|
||||||
*width = size.cx;
|
*width = size.cx;
|
||||||
*height = size.cy;
|
*height = size.cy;
|
||||||
return;
|
return;
|
||||||
|
@ -52,7 +51,7 @@ static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *
|
||||||
// that didn't work; fall back to using Microsoft's metrics
|
// 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
|
// Microsoft says to use a fixed width for all buttons; this isn't good enough
|
||||||
// use the text width instead, with some edge padding
|
// use the text width instead, with some edge padding
|
||||||
*width = uiWindowsWindowTextWidth(hwnd) + (2 * GetSystemMetrics(SM_CXEDGE));
|
*width = uiWindowsWindowTextWidth(b->hwnd) + (2 * GetSystemMetrics(SM_CXEDGE));
|
||||||
*height = uiDlgUnitsToY(buttonHeight, d->sys->baseY);
|
*height = uiDlgUnitsToY(buttonHeight, d->sys->baseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,17 +60,17 @@ static void defaultOnClicked(uiButton *b, void *data)
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *getText(uiButton *b)
|
static char *buttonText(uiButton *b)
|
||||||
{
|
{
|
||||||
return uiWindowsControlText(uiControl(b));
|
return uiWindowsControlText(uiControl(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setText(uiButton *b, const char *text)
|
static void buttonSetText(uiButton *b, const char *text)
|
||||||
{
|
{
|
||||||
uiWindowsControlSetText(uiControl(b), text);
|
uiWindowsControlSetText(uiControl(b), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
struct button *b = (struct button *) bb;
|
||||||
|
|
||||||
|
@ -100,13 +99,15 @@ uiButton *uiNewButton(const char *text)
|
||||||
uiWindowsNewControl(uiControl(b), &p);
|
uiWindowsNewControl(uiControl(b), &p);
|
||||||
uiFree(wtext);
|
uiFree(wtext);
|
||||||
|
|
||||||
|
b->hwnd = HWND(b);
|
||||||
|
|
||||||
b->onClicked = defaultOnClicked;
|
b->onClicked = defaultOnClicked;
|
||||||
|
|
||||||
uiControl(b)->PreferredSize = preferredSize;
|
uiControl(b)->PreferredSize = preferredSize;
|
||||||
|
|
||||||
uiButton(b)->Text = getText;
|
uiButton(b)->Text = buttonText;
|
||||||
uiButton(b)->SetText = setText;
|
uiButton(b)->SetText = buttonSetText;
|
||||||
uiButton(b)->OnClicked = setOnClicked;
|
uiButton(b)->OnClicked = buttonOnClicked;
|
||||||
|
|
||||||
return uiButton(b);
|
return uiButton(b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@ enum {
|
||||||
msgUpdateChild, // fake because Windows seems to SWP_NOSIZE MoveWindow()s and SetWindowPos()s that don't change the window size (even if SWP_NOSIZE isn't specified)
|
msgUpdateChild, // fake because Windows seems to SWP_NOSIZE MoveWindow()s and SetWindowPos()s that don't change the window size (even if SWP_NOSIZE isn't specified)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define HWND(c) ((HWND) uiControlHandle(uiControl(c)))
|
||||||
|
// TODO get rid of this
|
||||||
|
#define uiControlHWND(c) HWND(c)
|
||||||
|
#define uiParentHWND(p) ((HWND) uiParentHandle(p))
|
||||||
|
|
||||||
// debug_windows.c
|
// debug_windows.c
|
||||||
extern HRESULT logLastError(const char *);
|
extern HRESULT logLastError(const char *);
|
||||||
extern HRESULT logHRESULT(const char *, HRESULT);
|
extern HRESULT logHRESULT(const char *, HRESULT);
|
||||||
|
|
Loading…
Reference in New Issue