summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-11-04 09:18:57 -0500
committerPietro Gagliardi <[email protected]>2014-11-04 09:18:57 -0500
commit44cd9db87cbbe5534ee88e4bc96cfcef130d53dc (patch)
tree0cc427d9d4b909ec88824fe1111fcb6aada430a2
parentc5aa4bc964c4c33dd846c932ae0f2b6e4d2413eb (diff)
Started the Windows ProgressBar implemetnation. There's still an important detail left over...
-rw-r--r--basicctrls_windows.c5
-rw-r--r--progressbar_windows.go52
-rw-r--r--winapi_windows.h1
3 files changed, 57 insertions, 1 deletions
diff --git a/basicctrls_windows.c b/basicctrls_windows.c
index 60cc0c8..4cda2eb 100644
--- a/basicctrls_windows.c
+++ b/basicctrls_windows.c
@@ -235,4 +235,7 @@ void setSpinboxEditSubclass(HWND hwnd, void *data)
{
if ((*fv_SetWindowSubclass)(hwnd, spinboxEditSubProc, 0, (DWORD_PTR) data) == FALSE)
xpanic("error subclassing Spinbox edit control to give it its own event handler", GetLastError());
-} \ No newline at end of file
+}
+
+// provided for cgo's benefit
+LPWSTR xPROGRESS_CLASS = PROGRESS_CLASS;
diff --git a/progressbar_windows.go b/progressbar_windows.go
new file mode 100644
index 0000000..807b0c1
--- /dev/null
+++ b/progressbar_windows.go
@@ -0,0 +1,52 @@
+// 4 november 2014
+
+package ui
+
+import (
+ "fmt"
+)
+
+// #include "winapi_windows.h"
+import "C"
+
+type progressbar struct {
+ *controlSingleHWND
+}
+
+func newProgressBar() ProgressBar {
+ hwnd := C.newControl(C.xPROGRESS_CLASS,
+ C.PBS_SMOOTH,
+ 0)
+ p := &progressbar{
+ controlSingleHWND: newControlSingleHWND(hwnd),
+ }
+ p.fpreferredSize = p.xpreferredSize
+ p.fnTabStops = func() int {
+ // progress bars are not tab stops
+ return 0
+ }
+ return p
+}
+
+func (p *progressbar) Percent() int {
+ return int(C.SendMessageW(p.hwnd, C.PBM_GETPOS, 0, 0))
+}
+
+func (p *progressbar) SetPercent(percent int) {
+ if percent < 0 || percent > 100 {
+ panic(fmt.Errorf("given ProgressBar percentage %d out of range", percent))
+ }
+ // TODO circumvent aero
+ C.SendMessageW(p.hwnd, C.PBM_SETPOS, C.WPARAM(percent), 0)
+}
+
+const (
+ // via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx
+ // this is the double-width option
+ progressbarWidth = 237
+ progressbarHeight = 8
+)
+
+func (p *progressbar) xpreferredSize(d *sizing) (width, height int) {
+ return fromdlgunitsX(progressbarWidth, d), fromdlgunitsY(progressbarHeight, d)
+}
diff --git a/winapi_windows.h b/winapi_windows.h
index 7ea6ed3..75476b1 100644
--- a/winapi_windows.h
+++ b/winapi_windows.h
@@ -77,6 +77,7 @@ extern void textfieldHideInvalidBalloonTip(HWND);
extern void setGroupSubclass(HWND, void *);
extern HWND newUpDown(HWND, void *);
extern void setSpinboxEditSubclass(HWND, void *);
+extern LPWSTR xPROGRESS_CLASS;
// init_windows.c
extern HINSTANCE hInstance;