libui/redo/windows/progressbar.c

68 lines
2.0 KiB
C
Raw Normal View History

2015-05-19 20:05:18 -05:00
// 19 may 2015
#include "uipriv_windows.h"
struct progressbar {
uiProgressBar p;
HWND hwnd;
};
uiDefineControlType(uiProgressBar, uiTypeProgressBar, struct progressbar)
2015-05-19 20:05:18 -05:00
static uintptr_t progressbarHandle(uiControl *c)
{
struct progressbar *p = (struct progressbar *) c;
return (uintptr_t) (p->hwnd);
}
2015-05-19 20:05:18 -05:00
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define pbarWidth 237
#define pbarHeight 8
static void progressbarPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{
*width = uiWindowsDlgUnitsToX(pbarWidth, d->Sys->BaseX);
*height = uiWindowsDlgUnitsToY(pbarHeight, d->Sys->BaseY);
}
2015-06-08 02:56:17 -05:00
// unfortunately, as of Vista progress bars have a forced animation on increase
// we have to set the progress bar to value + 1 and decrease it back to value if we want an "instant" change
// see http://stackoverflow.com/questions/2217688/windows-7-aero-theme-progress-bar-bug
// it's not ideal/perfect, but it will have to do
2015-05-19 20:05:18 -05:00
static void progressbarSetValue(uiProgressBar *pp, int value)
{
struct progressbar *p = (struct progressbar *) pp;
2015-06-08 02:56:17 -05:00
if (value < 0 || value > 100)
complain("value %d out of range in progressbarSetValue()", value);
if (value == 100) { // because we can't 101
SendMessageW(p->hwnd, PBM_SETRANGE32, 0, 101);
SendMessageW(p->hwnd, PBM_SETPOS, 101, 0);
SendMessageW(p->hwnd, PBM_SETPOS, 100, 0);
SendMessageW(p->hwnd, PBM_SETRANGE32, 0, 100);
return;
}
SendMessageW(p->hwnd, PBM_SETPOS, (WPARAM) (value + 1), 0);
2015-05-19 20:05:18 -05:00
SendMessageW(p->hwnd, PBM_SETPOS, (WPARAM) value, 0);
}
uiProgressBar *uiNewProgressBar(void)
{
struct progressbar *p;
2015-05-19 20:05:18 -05:00
p = (struct progressbar *) uiWindowsNewSingleHWNDControl(uiTypeProgressBar());
2015-05-19 20:05:18 -05:00
2015-05-29 19:53:12 -05:00
p->hwnd = uiWindowsUtilCreateControlHWND(0,
PROGRESS_CLASSW, L"",
PBS_SMOOTH,
hInstance, NULL,
FALSE);
2015-05-19 20:05:18 -05:00
uiControl(p)->Handle = progressbarHandle;
uiControl(p)->PreferredSize = progressbarPreferredSize;
2015-05-19 20:05:18 -05:00
uiProgressBar(p)->SetValue = progressbarSetValue;
2015-05-19 20:05:18 -05:00
return uiProgressBar(p);
2015-05-19 20:05:18 -05:00
}