From 180193231d5a4437bfa1e0a2f2ba597430c14d16 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 19 May 2015 21:05:18 -0400 Subject: [PATCH] Added a basic progressbar. More TODOs. --- redo/test/page4.c | 7 ++++ redo/ui.idl | 6 ++++ redo/windows/GNUmakeinc.mk | 1 + redo/windows/progressbar.c | 74 ++++++++++++++++++++++++++++++++++++++ redo/windows/spinbox.c | 2 ++ 5 files changed, 90 insertions(+) create mode 100644 redo/windows/progressbar.c diff --git a/redo/test/page4.c b/redo/test/page4.c index f5d655a0..51394967 100644 --- a/redo/test/page4.c +++ b/redo/test/page4.c @@ -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; } diff --git a/redo/ui.idl b/redo/ui.idl index 1566159e..63eb8c96 100644 --- a/redo/ui.idl +++ b/redo/ui.idl @@ -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; diff --git a/redo/windows/GNUmakeinc.mk b/redo/windows/GNUmakeinc.mk index e70db6f7..bc6384f1 100644 --- a/redo/windows/GNUmakeinc.mk +++ b/redo/windows/GNUmakeinc.mk @@ -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 \ diff --git a/redo/windows/progressbar.c b/redo/windows/progressbar.c new file mode 100644 index 00000000..cce0f1e5 --- /dev/null +++ b/redo/windows/progressbar.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); +} diff --git a/redo/windows/spinbox.c b/redo/windows/spinbox.c index ef3677cb..a4b04ee5 100644 --- a/redo/windows/spinbox.c +++ b/redo/windows/spinbox.c @@ -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,