summaryrefslogtreecommitdiff
path: root/progressbar_windows.go
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 /progressbar_windows.go
parentc5aa4bc964c4c33dd846c932ae0f2b6e4d2413eb (diff)
Started the Windows ProgressBar implemetnation. There's still an important detail left over...
Diffstat (limited to 'progressbar_windows.go')
-rw-r--r--progressbar_windows.go52
1 files changed, 52 insertions, 0 deletions
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)
+}