2015-05-19 20:05:18 -05:00
|
|
|
// 19 may 2015
|
2016-04-22 19:14:12 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-05-19 20:05:18 -05:00
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
struct uiProgressBar {
|
|
|
|
uiWindowsControl c;
|
2015-05-19 20:05:18 -05:00
|
|
|
HWND hwnd;
|
|
|
|
};
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
uiWindowsDefineControl(
|
2016-04-24 14:04:36 -05:00
|
|
|
uiProgressBar // type name
|
2015-08-30 11:25:53 -05:00
|
|
|
)
|
2015-05-29 18:48:27 -05:00
|
|
|
|
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
|
|
|
|
|
2015-08-31 16:50:23 -05:00
|
|
|
static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
|
2015-05-19 20:05:18 -05:00
|
|
|
{
|
2015-08-31 16:50:23 -05:00
|
|
|
*width = uiWindowsDlgUnitsToX(pbarWidth, d->BaseX);
|
|
|
|
*height = uiWindowsDlgUnitsToY(pbarHeight, d->BaseY);
|
2015-05-19 20:05:18 -05:00
|
|
|
}
|
|
|
|
|
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-08-30 11:25:53 -05:00
|
|
|
void uiProgressBarSetValue(uiProgressBar *p, int value)
|
2015-05-19 20:05:18 -05:00
|
|
|
{
|
2015-06-08 02:56:17 -05:00
|
|
|
if (value < 0 || value > 100)
|
2015-08-30 11:25:53 -05:00
|
|
|
complain("value %d out of range in uiProgressBarSetValue()", value);
|
2015-06-08 02:56:17 -05:00
|
|
|
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)
|
|
|
|
{
|
2015-08-30 11:25:53 -05:00
|
|
|
uiProgressBar *p;
|
2015-05-19 20:05:18 -05:00
|
|
|
|
2016-04-24 16:38:48 -05:00
|
|
|
p = (uiProgressBar *) uiNewControl(uiProgressBar);
|
2015-05-19 20:05:18 -05:00
|
|
|
|
2015-08-31 11:33:44 -05:00
|
|
|
p->hwnd = uiWindowsEnsureCreateControlHWND(0,
|
2015-05-29 17:03:24 -05:00
|
|
|
PROGRESS_CLASSW, L"",
|
|
|
|
PBS_SMOOTH,
|
|
|
|
hInstance, NULL,
|
|
|
|
FALSE);
|
2015-05-19 20:05:18 -05:00
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
uiWindowsFinishNewControl(p, uiProgressBar);
|
2015-05-19 20:05:18 -05:00
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
return p;
|
2015-05-19 20:05:18 -05:00
|
|
|
}
|