Added a basic progressbar. More TODOs.
This commit is contained in:
parent
44153a32df
commit
180193231d
|
@ -2,11 +2,15 @@
|
|||
#include "test.h"
|
||||
|
||||
static uiSpinbox *spinbox;
|
||||
static uiProgressBar *pbar;
|
||||
|
||||
#define CHANGED(what) \
|
||||
static void on ## what ## Changed(ui ## what *this, void *data) \
|
||||
{ \
|
||||
uintmax_t value; \
|
||||
printf("on %s changed\n", #what); \
|
||||
value = ui ## what ## Value(this); \
|
||||
uiProgressBarSetValue(pbar, value); \
|
||||
}
|
||||
CHANGED(Spinbox)
|
||||
|
||||
|
@ -20,5 +24,8 @@ uiBox *makePage4(void)
|
|||
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
|
||||
uiBoxAppend(page4, uiControl(spinbox), 0);
|
||||
|
||||
pbar = uiNewProgressBar();
|
||||
uiBoxAppend(page4, uiControl(pbar), 0);
|
||||
|
||||
return page4;
|
||||
}
|
||||
|
|
|
@ -148,6 +148,12 @@ interface Spinbox from Control {
|
|||
};
|
||||
func NewSpinbox(void) *Spinbox;
|
||||
|
||||
interface ProgressBar from Control {
|
||||
// TODO Value()
|
||||
func SetValue(n int);
|
||||
};
|
||||
func NewProgressBar(void) *ProgressBar;
|
||||
|
||||
interface Menu {
|
||||
func AppendItem(name *const char) *MenuItem;
|
||||
func AppendCheckItem(name *const char) *MenuItem;
|
||||
|
|
|
@ -14,6 +14,7 @@ osCFILES = \
|
|||
windows/main.c \
|
||||
windows/menu.c \
|
||||
windows/parent.c \
|
||||
windows/progressbar.c \
|
||||
windows/resize.c \
|
||||
windows/spinbox.c \
|
||||
windows/tab.c \
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
// 19 may 2015
|
||||
#include "uipriv_windows.h"
|
||||
|
||||
struct progressbar {
|
||||
uiProgressBar p;
|
||||
HWND hwnd;
|
||||
};
|
||||
|
||||
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void onDestroy(void *data)
|
||||
{
|
||||
struct progressbar *p = (struct progressbar *) data;
|
||||
|
||||
uiFree(p);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
struct label *l = (struct label *) c;
|
||||
|
||||
*width = uiWindowsDlgUnitsToX(pbarWidth, d->Sys->BaseX);
|
||||
*height = uiWindowsDlgUnitsToY(pbarHeight, d->Sys->BaseY);
|
||||
}
|
||||
|
||||
// TODO bypass Aero animations
|
||||
static void progressbarSetValue(uiProgressBar *pp, int value)
|
||||
{
|
||||
struct progressbar *p = (struct progressbar *) pp;
|
||||
|
||||
SendMessageW(p->hwnd, PBM_SETPOS, (WPARAM) value, 0);
|
||||
}
|
||||
|
||||
uiProgressBar *uiNewProgressBar(void)
|
||||
{
|
||||
struct progressbar *pbar;
|
||||
uiWindowsMakeControlParams p;
|
||||
|
||||
pbar = uiNew(struct progressbar);
|
||||
uiTyped(pbar)->Type = uiTypeProgressBar();
|
||||
|
||||
p.dwExStyle = 0;
|
||||
p.lpClassName = PROGRESS_CLASSW;
|
||||
p.lpWindowName = L"";
|
||||
p.dwStyle = PBS_SMOOTH;
|
||||
p.hInstance = hInstance;
|
||||
p.lpParam = NULL;
|
||||
p.useStandardControlFont = FALSE;
|
||||
p.onWM_COMMAND = onWM_COMMAND;
|
||||
p.onWM_NOTIFY = onWM_NOTIFY;
|
||||
p.onDestroy = onDestroy;
|
||||
p.onDestroyData = pbar;
|
||||
uiWindowsMakeControl(uiControl(pbar), &p);
|
||||
|
||||
pbar->hwnd = (HWND) uiControlHandle(uiControl(pbar));
|
||||
|
||||
uiControl(pbar)->PreferredSize = progressbarPreferredSize;
|
||||
|
||||
uiProgressBar(pbar)->SetValue = progressbarSetValue;
|
||||
|
||||
return uiProgressBar(pbar);
|
||||
}
|
|
@ -84,6 +84,8 @@ static void recreateUpDown(struct spinbox *s)
|
|||
s->updown = CreateWindowExW(0,
|
||||
UPDOWN_CLASSW, L"",
|
||||
// no WS_VISIBLE; we set visibility ourselves
|
||||
// TODO tab stop?
|
||||
// TODO maintain Z-order
|
||||
WS_CHILD | UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_HOTTRACK | UDS_NOTHOUSANDS | UDS_SETBUDDYINT,
|
||||
// this is important; it's necessary for autosizing to work
|
||||
0, 0, 0, 0,
|
||||
|
|
Loading…
Reference in New Issue