More go fmt.
This commit is contained in:
parent
ad8a90ec7e
commit
1e66637cd2
26
button.go
26
button.go
|
@ -11,20 +11,20 @@ type Button struct {
|
|||
// Clicked gets a message when the button is clicked.
|
||||
// You cannot change it once the Window containing the Button has been created.
|
||||
// If you do not respond to this signal, nothing will happen.
|
||||
Clicked chan struct{}
|
||||
Clicked chan struct{}
|
||||
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
}
|
||||
|
||||
// NewButton creates a new button with the specified text.
|
||||
func NewButton(text string) (b *Button) {
|
||||
return &Button{
|
||||
sysData: mksysdata(c_button),
|
||||
initText: text,
|
||||
Clicked: newEvent(),
|
||||
sysData: mksysdata(c_button),
|
||||
initText: text,
|
||||
Clicked: newEvent(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,11 @@ func (b *Button) make(window *sysData) error {
|
|||
|
||||
func (b *Button) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
|
||||
*rr = append(*rr, resizerequest{
|
||||
sysData: b.sysData,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
sysData: b.sysData,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ func our_window_delete_event_callback(widget *C.GtkWidget, event *C.GdkEvent, wh
|
|||
// called when the user tries to close the window
|
||||
s := (*sysData)(unsafe.Pointer(what))
|
||||
s.signal()
|
||||
return C.TRUE // do not close the window
|
||||
return C.TRUE // do not close the window
|
||||
}
|
||||
|
||||
var window_delete_event_callback = C.GCallback(C.our_window_delete_event_callback)
|
||||
|
@ -37,13 +37,13 @@ var window_delete_event_callback = C.GCallback(C.our_window_delete_event_callbac
|
|||
func our_window_configure_event_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean {
|
||||
// called when the window is resized
|
||||
s := (*sysData)(unsafe.Pointer(what))
|
||||
if s.container != nil && s.resize != nil { // wait for init
|
||||
if s.container != nil && s.resize != nil { // wait for init
|
||||
width, height := gtk_window_get_size(s.widget)
|
||||
// top-left is (0,0) so no need for winheight
|
||||
s.doResize(0, 0, width, height, 0)
|
||||
}
|
||||
// no need to manually redraw everything: since we use gtk_widget_set_size_request(), that queues both resize and redraw for us (thanks Company in irc.gimp.net/#gtk+)
|
||||
return C.FALSE // continue the event chain
|
||||
return C.FALSE // continue the event chain
|
||||
}
|
||||
|
||||
var window_configure_event_callback = C.GCallback(C.our_window_configure_event_callback)
|
||||
|
@ -78,8 +78,8 @@ func g_signal_connect_pointer(obj *C.GtkWidget, sig string, callback C.GCallback
|
|||
// 2) we need to make sure one idle function runs and finishes running before we start the next; otherwise we could wind up with weird things like the ret channel being closed early
|
||||
// so our_idle_callback() calls the uitask function in what and sends a message back to the dispatcher over done that it finished running; the dispatcher is still holding onto the uitask function so it won't be collected
|
||||
type gtkIdleOp struct {
|
||||
what func()
|
||||
done chan struct{}
|
||||
what func()
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
//export our_idle_callback
|
||||
|
@ -87,7 +87,7 @@ func our_idle_callback(what C.gpointer) C.gboolean {
|
|||
idleop := (*gtkIdleOp)(unsafe.Pointer(what))
|
||||
idleop.what()
|
||||
idleop.done <- struct{}{}
|
||||
return C.FALSE // remove this idle function; we're finished
|
||||
return C.FALSE // remove this idle function; we're finished
|
||||
}
|
||||
|
||||
func gdk_threads_add_idle(idleop *gtkIdleOp) {
|
||||
|
|
24
checkbox.go
24
checkbox.go
|
@ -8,18 +8,18 @@ import (
|
|||
|
||||
// A Checkbox is a clickable square with a label. The square can be either checked or unchecked. Checkboxes start out unchecked.
|
||||
type Checkbox struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
initCheck bool
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initText string
|
||||
initCheck bool
|
||||
}
|
||||
|
||||
// NewCheckbox creates a new checkbox with the specified text.
|
||||
func NewCheckbox(text string) (c *Checkbox) {
|
||||
return &Checkbox{
|
||||
sysData: mksysdata(c_checkbox),
|
||||
initText: text,
|
||||
sysData: mksysdata(c_checkbox),
|
||||
initText: text,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,11 +72,11 @@ func (c *Checkbox) make(window *sysData) error {
|
|||
|
||||
func (c *Checkbox) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
|
||||
*rr = append(*rr, resizerequest{
|
||||
sysData: c.sysData,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
sysData: c.sysData,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
26
combobox.go
26
combobox.go
|
@ -9,16 +9,16 @@ import (
|
|||
|
||||
// A Combobox is a drop-down list of items, of which at most one can be selected at any given time. You may optionally make the combobox editable to allow custom items. Initially, no item will be selected (and no text entered in an editable Combobox's entry field). What happens to the text shown in a Combobox if its width is too small is implementation-defined.
|
||||
type Combobox struct {
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initItems []string
|
||||
lock sync.Mutex
|
||||
created bool
|
||||
sysData *sysData
|
||||
initItems []string
|
||||
}
|
||||
|
||||
func newCombobox(editable bool, items ...string) (c *Combobox) {
|
||||
c = &Combobox{
|
||||
sysData: mksysdata(c_combobox),
|
||||
initItems: items,
|
||||
sysData: mksysdata(c_combobox),
|
||||
initItems: items,
|
||||
}
|
||||
c.sysData.alternate = editable
|
||||
return c
|
||||
|
@ -67,7 +67,7 @@ func (c *Combobox) InsertBefore(what string, before int) {
|
|||
if before < 0 || before >= len(c.initItems) {
|
||||
goto badrange
|
||||
}
|
||||
m = make([]string, 0, len(c.initItems) + 1)
|
||||
m = make([]string, 0, len(c.initItems)+1)
|
||||
m = append(m, c.initItems[:before]...)
|
||||
m = append(m, what)
|
||||
c.initItems = append(m, c.initItems[before:]...)
|
||||
|
@ -91,7 +91,7 @@ func (c *Combobox) Delete(index int) {
|
|||
if index < 0 || index >= len(c.initItems) {
|
||||
goto badrange
|
||||
}
|
||||
c.initItems = append(c.initItems[:index], c.initItems[index + 1:]...)
|
||||
c.initItems = append(c.initItems[:index], c.initItems[index+1:]...)
|
||||
return
|
||||
badrange:
|
||||
panic(fmt.Errorf("index %d out of range in Combobox.Delete()", index))
|
||||
|
@ -149,11 +149,11 @@ func (c *Combobox) make(window *sysData) (err error) {
|
|||
|
||||
func (c *Combobox) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
|
||||
*rr = append(*rr, resizerequest{
|
||||
sysData: c.sysData,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
sysData: c.sysData,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ package ui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// pretty much every constant here except _WM_USER is from commctrl.h, except where noted
|
||||
|
@ -17,7 +17,7 @@ var (
|
|||
|
||||
var (
|
||||
_activateActCtx = kernel32.NewProc("ActivateActCtx")
|
||||
_createActCtx = kernel32.NewProc("CreateActCtxW")
|
||||
_createActCtx = kernel32.NewProc("CreateActCtxW")
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -43,15 +43,15 @@ func forceCommonControls6() (err error) {
|
|||
manifestfile.Close()
|
||||
|
||||
var actctx struct {
|
||||
cbSize uint32
|
||||
dwFlags uint32
|
||||
lpSource *uint16
|
||||
wProcessorArchitecture uint16
|
||||
wLangId uint16 // originally LANGID
|
||||
lpAssemblyDirectory uintptr // originally LPCWSTR
|
||||
lpResourceName uintptr // originally LPCWSTR
|
||||
lpApplicationName uintptr // originally LPCWSTR
|
||||
hModule _HANDLE // originally HMODULE
|
||||
cbSize uint32
|
||||
dwFlags uint32
|
||||
lpSource *uint16
|
||||
wProcessorArchitecture uint16
|
||||
wLangId uint16 // originally LANGID
|
||||
lpAssemblyDirectory uintptr // originally LPCWSTR
|
||||
lpResourceName uintptr // originally LPCWSTR
|
||||
lpApplicationName uintptr // originally LPCWSTR
|
||||
hModule _HANDLE // originally HMODULE
|
||||
}
|
||||
|
||||
actctx.cbSize = uint32(unsafe.Sizeof(actctx))
|
||||
|
@ -61,13 +61,13 @@ func forceCommonControls6() (err error) {
|
|||
|
||||
r1, _, err := _createActCtx.Call(uintptr(unsafe.Pointer(&actctx)))
|
||||
// don't negConst() INVALID_HANDLE_VALUE; windowsconstgen was given a pointer by windows.h, and pointers are unsigned, so converting it back to signed doesn't work
|
||||
if r1 == _INVALID_HANDLE_VALUE { // failure
|
||||
if r1 == _INVALID_HANDLE_VALUE { // failure
|
||||
return fmt.Errorf("error creating activation context for synthesized manifest file: %v", err)
|
||||
}
|
||||
r1, _, err = _activateActCtx.Call(
|
||||
r1,
|
||||
uintptr(unsafe.Pointer(&comctlManifestCookie)))
|
||||
if r1 == uintptr(_FALSE) { // failure
|
||||
if r1 == uintptr(_FALSE) { // failure
|
||||
return fmt.Errorf("error activating activation context for synthesized manifest file: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
@ -75,8 +75,8 @@ func forceCommonControls6() (err error) {
|
|||
|
||||
func initCommonControls() (err error) {
|
||||
var icc struct {
|
||||
dwSize uint32
|
||||
dwICC uint32
|
||||
dwSize uint32
|
||||
dwICC uint32
|
||||
}
|
||||
|
||||
err = forceCommonControls6()
|
||||
|
@ -89,7 +89,7 @@ func initCommonControls() (err error) {
|
|||
|
||||
comctl32 = syscall.NewLazyDLL("comctl32.dll")
|
||||
r1, _, err := comctl32.NewProc("InitCommonControlsEx").Call(uintptr(unsafe.Pointer(&icc)))
|
||||
if r1 == _FALSE { // failure
|
||||
if r1 == _FALSE { // failure
|
||||
return fmt.Errorf("error initializing Common Controls (comctl32.dll); Windows last error: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
user32 = syscall.NewLazyDLL("user32.dll")
|
||||
user32 = syscall.NewLazyDLL("user32.dll")
|
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
gdi32 = syscall.NewLazyDLL("gdi32.dll")
|
||||
comctl32 *syscall.LazyDLL // comctl32 not defined here; see comctl_windows.go
|
||||
msimg32 = syscall.NewLazyDLL("msimg32.dll")
|
||||
gdi32 = syscall.NewLazyDLL("gdi32.dll")
|
||||
comctl32 *syscall.LazyDLL // comctl32 not defined here; see comctl_windows.go
|
||||
msimg32 = syscall.NewLazyDLL("msimg32.dll")
|
||||
)
|
||||
|
||||
type _HANDLE uintptr
|
||||
|
@ -38,27 +38,27 @@ func (w _WPARAM) HIWORD() uint16 {
|
|||
func (l _LPARAM) X() int32 {
|
||||
// according to windowsx.h
|
||||
loword := uint16(l & 0xFFFF)
|
||||
short := int16(loword) // convert to signed...
|
||||
return int32(short) // ...and sign extend
|
||||
short := int16(loword) // convert to signed...
|
||||
return int32(short) // ...and sign extend
|
||||
}
|
||||
|
||||
func (l _LPARAM) Y() int32 {
|
||||
// according to windowsx.h
|
||||
hiword := uint16((l & 0xFFFF0000) >> 16)
|
||||
short := int16(hiword) // convert to signed...
|
||||
return int32(short) // ...and sign extend
|
||||
short := int16(hiword) // convert to signed...
|
||||
return int32(short) // ...and sign extend
|
||||
}
|
||||
|
||||
type _POINT struct {
|
||||
x int32
|
||||
y int32
|
||||
x int32
|
||||
y int32
|
||||
}
|
||||
|
||||
type _RECT struct {
|
||||
left int32
|
||||
top int32
|
||||
right int32
|
||||
bottom int32
|
||||
left int32
|
||||
top int32
|
||||
right int32
|
||||
bottom int32
|
||||
}
|
||||
|
||||
// Go doesn't allow negative constants to be forced into unsigned types at compile-time; this will do it at runtime.
|
||||
|
@ -85,20 +85,20 @@ func utf16ToLPARAM(s *uint16) uintptr {
|
|||
|
||||
var (
|
||||
_adjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
|
||||
_createWindowEx = user32.NewProc("CreateWindowExW")
|
||||
_getClientRect = user32.NewProc("GetClientRect")
|
||||
_moveWindow = user32.NewProc("MoveWindow")
|
||||
_setWindowPos = user32.NewProc("SetWindowPos")
|
||||
_setWindowText = user32.NewProc("SetWindowTextW")
|
||||
_showWindow = user32.NewProc("ShowWindow")
|
||||
_createWindowEx = user32.NewProc("CreateWindowExW")
|
||||
_getClientRect = user32.NewProc("GetClientRect")
|
||||
_moveWindow = user32.NewProc("MoveWindow")
|
||||
_setWindowPos = user32.NewProc("SetWindowPos")
|
||||
_setWindowText = user32.NewProc("SetWindowTextW")
|
||||
_showWindow = user32.NewProc("ShowWindow")
|
||||
)
|
||||
|
||||
type _MINMAXINFO struct {
|
||||
ptReserved _POINT
|
||||
ptMaxSize _POINT
|
||||
ptMaxPosition _POINT
|
||||
ptMinTrackSize _POINT
|
||||
ptMaxTrackSize _POINT
|
||||
ptReserved _POINT
|
||||
ptMaxSize _POINT
|
||||
ptMaxPosition _POINT
|
||||
ptMinTrackSize _POINT
|
||||
ptMaxTrackSize _POINT
|
||||
}
|
||||
|
||||
func (l _LPARAM) MINMAXINFO() *_MINMAXINFO {
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
|
||||
package ui
|
||||
|
||||
import (
|
||||
// ...
|
||||
)
|
||||
|
||||
// A Control represents an UI control. Note that Control contains unexported members; this has the consequence that you can't build custom controls that interface directly with the system-specific code (fo rinstance, to import an unsupported control), or at least not without some hackery. If you want to make your own controls, create an Area and provide an AreaHandler that does what you need.
|
||||
type Control interface {
|
||||
make(window *sysData) error
|
||||
|
|
|
@ -26,17 +26,17 @@ func CheckRadioButton(hDlg HWND, nIDFirstButton int, nIDLastButton int, nIDCheck
|
|||
*/
|
||||
|
||||
var (
|
||||
_getScrollInfo = user32.NewProc("GetScrollInfo")
|
||||
_setScrollInfo = user32.NewProc("SetScrollInfo")
|
||||
_getScrollInfo = user32.NewProc("GetScrollInfo")
|
||||
_setScrollInfo = user32.NewProc("SetScrollInfo")
|
||||
_scrollWindowEx = user32.NewProc("ScrollWindowEx")
|
||||
)
|
||||
|
||||
type _SCROLLINFO struct {
|
||||
cbSize uint32
|
||||
fMask uint32
|
||||
nMin int32 // originally int
|
||||
nMax int32 // originally int
|
||||
nPage uint32
|
||||
nPos int32 // originally int
|
||||
nTrackPos int32 // originally int
|
||||
cbSize uint32
|
||||
fMask uint32
|
||||
nMin int32 // originally int
|
||||
nMax int32 // originally int
|
||||
nPage uint32
|
||||
nPos int32 // originally int
|
||||
nTrackPos int32 // originally int
|
||||
}
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
|
||||
package ui
|
||||
|
||||
import (
|
||||
// ...
|
||||
)
|
||||
|
||||
/*
|
||||
This creates a class goAppDelegate that will be used as the delegate for /everything/. Specifically, it:
|
||||
- runs uitask requests (uitask:)
|
||||
|
@ -36,11 +32,11 @@ func appDelegate_windowShouldClose(win C.id) {
|
|||
//export appDelegate_windowDidResize
|
||||
func appDelegate_windowDidResize(win C.id) {
|
||||
s := getSysData(win)
|
||||
wincv := C.windowGetContentView(win) // we want the content view's size, not the window's
|
||||
wincv := C.windowGetContentView(win) // we want the content view's size, not the window's
|
||||
r := C.frame(wincv)
|
||||
// winheight is used here because (0,0) is the bottom-left corner, not the top-left corner
|
||||
s.doResize(0, 0, int(r.width), int(r.height), int(r.height))
|
||||
C.display(win) // redraw everything
|
||||
C.display(win) // redraw everything
|
||||
}
|
||||
|
||||
//export appDelegate_buttonClicked
|
||||
|
|
Loading…
Reference in New Issue