Added the initial Windows Spinbox code.

This commit is contained in:
Pietro Gagliardi 2014-10-28 15:46:13 -04:00
parent 649b52b6ef
commit 667745dd8c
4 changed files with 67 additions and 0 deletions

View File

@ -160,3 +160,6 @@ void setGroupSubclass(HWND hwnd, void *data)
if ((*fv_SetWindowSubclass)(hwnd, groupSubProc, 0, (DWORD_PTR) data) == FALSE)
xpanic("error subclassing Group to give it its own event handler", GetLastError());
}
// provided for cgo's benefit
LPWSTR xUPDOWN_CLASSW = UPDOWN_CLASSW;

View File

@ -17,6 +17,7 @@ BOOL (*WINAPI fv_ImageList_Destroy)(HIMAGELIST);
ICC_PROGRESS_CLASS | /* progress bars */ \
ICC_TAB_CLASSES | /* tabs */ \
ICC_LISTVIEW_CLASSES | /* list views */ \
ICC_UPDOWN_CLASS | /* spinboxes */ \
0)
// note that this is an 8-bit character string we're writing; see the encoding clause

62
spinbox_windows.go Normal file
View File

@ -0,0 +1,62 @@
// 28 october 2014
package ui
import (
"unsafe"
)
// #include "winapi_windows.h"
import "C"
// TODO do we have to manually monitor user changes to the edit control?
type spinbox struct {
hwndEdit C.HWND
hwndUpDown C.HWND
}
func newSpinbox() Spinbox {
s := new(spinbox)
s.hwndEdit = C.newControl(editclass,
C.textfieldStyle | C.ES_NUMBER,
C.textfieldExtStyle)
s.hwndUpDown = C.newControl(C.xUPDOWN_CLASSW,
C.UDS_ALIGNRIGHT | C.UDS_ARROWKEYS | C.UDS_HOTTRACK | C.UDS_NOTHOUSANDS | C.UDS_SETBUDDYINT,
0)
C.SendMessageW(s.hwndUpDown, C.UDM_SETBUDDY, C.WPARAM(uintptr(unsafe.Pointer(s.hwndEdit))), 0)
C.SendMessageW(s.hwndUpDown, C.UDM_SETRANGE32, 0, 100)
C.SendMessageW(s.hwndUpDown, C.UDM_SETPOS32, 0, 0)
return s
}
func (s *spinbox) setParent(p *controlParent) {
C.controlSetParent(s.hwndEdit, p.hwnd)
C.controlSetParent(s.hwndUpDown, p.hwnd)
}
func (s *spinbox) preferredSize(d *sizing) (width, height int) {
// TODO
return 20, 20
}
func (s *spinbox) resize(x int, y int, width int, height int, d *sizing) {
C.moveWindow(s.hwndEdit, C.int(x), C.int(y), C.int(width), C.int(height))
}
func (s *spinbox) nTabStops() int {
// TODO does the up-down control count?
return 1
}
// TODO be sure to modify this when we add Show()/Hide()
func (s *spinbox) containerShow() {
C.ShowWindow(s.hwndEdit, C.SW_SHOW)
C.ShowWindow(s.hwndUpDown, C.SW_SHOW)
}
// TODO be sure to modify this when we add Show()/Hide()
func (s *spinbox) containerHide() {
C.ShowWindow(s.hwndEdit, C.SW_HIDE)
C.ShowWindow(s.hwndUpDown, C.SW_HIDE)
}

View File

@ -75,6 +75,7 @@ extern void setTextFieldSubclass(HWND, void *);
extern void textfieldSetAndShowInvalidBalloonTip(HWND, WCHAR *);
extern void textfieldHideInvalidBalloonTip(HWND);
extern void setGroupSubclass(HWND, void *);
extern LPWSTR xUPDOWN_CLASSW;
// init_windows.c
extern HINSTANCE hInstance;