go fmt. Precursor to bug report filing.

This commit is contained in:
Pietro Gagliardi 2014-10-02 10:05:53 -04:00
parent 09db0bffff
commit 982004d050
50 changed files with 1081 additions and 1078 deletions

View File

@ -185,14 +185,14 @@ var areaCallbacks = []struct {
name string
callback C.GCallback
}{
{ "draw", area_draw_callback },
{ "button-press-event", area_button_press_event_callback },
{ "button-release-event", area_button_release_event_callback },
{ "motion-notify-event", area_motion_notify_event_callback },
{ "enter-notify-event", area_enterleave_notify_event_callback },
{ "leave-notify-event", area_enterleave_notify_event_callback },
{ "key-press-event", area_key_press_event_callback },
{ "key-release-event", area_key_release_event_callback },
{"draw", area_draw_callback},
{"button-press-event", area_button_press_event_callback},
{"button-release-event", area_button_release_event_callback},
{"motion-notify-event", area_motion_notify_event_callback},
{"enter-notify-event", area_enterleave_notify_event_callback},
{"leave-notify-event", area_enterleave_notify_event_callback},
{"key-press-event", area_key_press_event_callback},
{"key-release-event", area_key_release_event_callback},
}
//export our_area_draw_callback

View File

@ -122,7 +122,7 @@ func dotoARGB(img unsafe.Pointer, ppvBits unsafe.Pointer, toNRGBA C.BOOL) {
i := (*image.RGBA)(unsafe.Pointer(img))
t := toNRGBA != C.FALSE
// the bitmap Windows gives us has a stride == width
toARGB(i, uintptr(ppvBits), i.Rect.Dx() * 4, t)
toARGB(i, uintptr(ppvBits), i.Rect.Dx()*4, t)
}
//export areaWidthLONG
@ -184,19 +184,19 @@ func finishAreaMouseEvent(data unsafe.Pointer, cbutton C.DWORD, up C.BOOL, heldB
}
// though wparam will contain control and shift state, let's use just one function to get modifiers for both keyboard and mouse events; it'll work the same anyway since we have to do this for alt and windows key (super)
me.Modifiers = getModifiers()
if button != 1 && (heldButtons & C.MK_LBUTTON) != 0 {
if button != 1 && (heldButtons&C.MK_LBUTTON) != 0 {
me.Held = append(me.Held, 1)
}
if button != 2 && (heldButtons & C.MK_MBUTTON) != 0 {
if button != 2 && (heldButtons&C.MK_MBUTTON) != 0 {
me.Held = append(me.Held, 2)
}
if button != 3 && (heldButtons & C.MK_RBUTTON) != 0 {
if button != 3 && (heldButtons&C.MK_RBUTTON) != 0 {
me.Held = append(me.Held, 3)
}
if button != 4 && (heldButtons & C.MK_XBUTTON1) != 0 {
if button != 4 && (heldButtons&C.MK_XBUTTON1) != 0 {
me.Held = append(me.Held, 4)
}
if button != 5 && (heldButtons & C.MK_XBUTTON2) != 0 {
if button != 5 && (heldButtons&C.MK_XBUTTON2) != 0 {
me.Held = append(me.Held, 5)
}
a.handler.Mouse(me)

View File

@ -19,7 +19,7 @@ var buttonclass = toUTF16("BUTTON")
func newButton(text string) *button {
hwnd := C.newControl(buttonclass,
C.BS_PUSHBUTTON | C.WS_TABSTOP,
C.BS_PUSHBUTTON|C.WS_TABSTOP,
0)
b := &button{
_hwnd: hwnd,
@ -84,7 +84,7 @@ func (b *button) preferredSize(d *sizing) (width, height int) {
return int(size.cx), int(size.cy)
}
// that failed, fall back
println("message failed; falling back")
println("message failed; falling back")
// don't worry about the error return from GetSystemMetrics(); there's no way to tell (explicitly documented as such)
xmargins := 2 * int(C.GetSystemMetrics(C.SM_CXEDGE))
return xmargins + int(b._textlen), fromdlgunitsY(buttonHeight, d)

View File

@ -19,7 +19,7 @@ func newCheckbox(text string) *checkbox {
// don't use BS_AUTOCHECKBOX here because it creates problems when refocusing (see http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx)
// we'll handle actually toggling the check state ourselves (see controls_windows.c)
hwnd := C.newControl(buttonclass,
C.BS_CHECKBOX | C.WS_TABSTOP,
C.BS_CHECKBOX|C.WS_TABSTOP,
0)
c := &checkbox{
_hwnd: hwnd,

View File

@ -4,9 +4,9 @@ package ui
import (
"fmt"
"reflect"
"syscall"
"unsafe"
"reflect"
)
// #include "winapi_windows.h"
@ -40,7 +40,7 @@ func getWindowText(hwnd C.HWND) string {
// WM_GETTEXTLENGTH and WM_GETTEXT return the count /without/ the terminating null character
// but WM_GETTEXT expects the buffer size handed to it to /include/ the terminating null character
n := C.getWindowTextLen(hwnd)
buf := make([]uint16, int(n + 1))
buf := make([]uint16, int(n+1))
C.getWindowText(hwnd, C.WPARAM(n),
C.LPWSTR(unsafe.Pointer(&buf[0])))
return syscall.UTF16ToString(buf)

View File

@ -42,8 +42,8 @@ func (c *container) resize(x, y, width, height int) {
return
}
d := c.beginResize()
allocations := c.child.allocate(x + d.xmargin, y + d.ymargintop,
width - (2 * d.xmargin), height - d.ymargintop - d.ymarginbottom, d)
allocations := c.child.allocate(x+d.xmargin, y+d.ymargintop,
width-(2*d.xmargin), height-d.ymargintop-d.ymarginbottom, d)
c.translateAllocationCoords(allocations, width, height)
// move in reverse so as to approximate right->left order so neighbors make sense
for i := len(allocations) - 1; i >= 0; i-- {

View File

@ -57,7 +57,7 @@ func (c *container) setParent(hwnd C.HWND) {
// this is needed because Windows won't move/resize a child window for us
func (c *container) move(r *C.RECT) {
C.moveWindow(c.hwnd, C.int(r.left), C.int(r.top), C.int(r.right - r.left), C.int(r.bottom - r.top))
C.moveWindow(c.hwnd, C.int(r.left), C.int(r.top), C.int(r.right-r.left), C.int(r.bottom-r.top))
}
func (c *container) show() {
@ -78,7 +78,7 @@ func storeContainerHWND(data unsafe.Pointer, hwnd C.HWND) {
func containerResize(data unsafe.Pointer, r *C.RECT) {
c := (*container)(data)
// the origin of any window's content area is always (0, 0), but let's use the values from the RECT just to be safe
c.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
c.resize(int(r.left), int(r.top), int(r.right-r.left), int(r.bottom-r.top))
}
// For Windows, Microsoft just hands you a list of preferred control sizes as part of the MSDN documentation and tells you to roll with it.

28
grid.go
View File

@ -31,6 +31,7 @@ type Grid interface {
// Align represents the alignment of a Control in its cell of a Grid.
type Align uint
const (
LeftTop Align = iota
Center
@ -40,6 +41,7 @@ const (
// Side represents a side of a Control to add other Controls to a Grid to.
type Side uint
const (
West Side = iota
East
@ -105,10 +107,10 @@ func (g *grid) reorigin() {
for i := range g.controls {
g.controls[i].x += xmin
g.controls[i].y += ymin
if g.xmax < g.controls[i].x + g.controls[i].xspan {
if g.xmax < g.controls[i].x+g.controls[i].xspan {
g.xmax = g.controls[i].x + g.controls[i].xspan
}
if g.ymax < g.controls[i].y + g.controls[i].yspan {
if g.ymax < g.controls[i].y+g.controls[i].yspan {
g.ymax = g.controls[i].y + g.controls[i].yspan
}
}
@ -176,8 +178,8 @@ func (g *grid) mkgrid() (gg [][]int, colwidths []int, rowheights []int) {
}
}
for i := range g.controls {
for y := g.controls[i].y; y < g.controls[i].y + g.controls[i].yspan; y++ {
for x := g.controls[i].x; x < g.controls[i].x + g.controls[i].xspan; x++ {
for y := g.controls[i].y; y < g.controls[i].y+g.controls[i].yspan; y++ {
for x := g.controls[i].x; x < g.controls[i].x+g.controls[i].xspan; x++ {
gg[y][x] = i
}
}
@ -241,28 +243,28 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
for i := range g.controls {
if g.controls[i].xexpand && g.controls[i].xspan != 1 {
do := true
for x := g.controls[i].x; x < g.controls[i].x + g.controls[i].xspan; x++ {
for x := g.controls[i].x; x < g.controls[i].x+g.controls[i].xspan; x++ {
if xexpand[x] {
do = false
break
}
}
if do {
for x := g.controls[i].x; x < g.controls[i].x + g.controls[i].xspan; x++ {
for x := g.controls[i].x; x < g.controls[i].x+g.controls[i].xspan; x++ {
xexpand[x] = true
}
}
}
if g.controls[i].yexpand && g.controls[i].yspan != 1 {
do := true
for y := g.controls[i].y; y < g.controls[i].y + g.controls[i].yspan; y++ {
for y := g.controls[i].y; y < g.controls[i].y+g.controls[i].yspan; y++ {
if yexpand[y] {
do = false
break
}
}
if do {
for y := g.controls[i].y; y < g.controls[i].y + g.controls[i].yspan; y++ {
for y := g.controls[i].y; y < g.controls[i].y+g.controls[i].yspan; y++ {
yexpand[y] = true
}
}
@ -372,7 +374,7 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
for _, i := range ycol {
if i != -1 { // treat empty cells like spaces
as := g.controls[i].control.allocate(
g.controls[i].finalx + x, g.controls[i].finaly + y,
g.controls[i].finalx+x, g.controls[i].finaly+y,
g.controls[i].finalwidth, g.controls[i].finalheight, d)
if current != nil { // connect first left to first right
current.neighbor = g.controls[i].control
@ -409,10 +411,10 @@ func (g *grid) preferredSize(d *sizing) (width, height int) {
}
w, h := g.controls[i].control.preferredSize(d)
// allot equal space in the presence of spanning to keep things sane
if colwidths[x] < w / g.controls[i].xspan {
if colwidths[x] < w/g.controls[i].xspan {
colwidths[x] = w / g.controls[i].xspan
}
if rowheights[y] < h / g.controls[i].yspan {
if rowheights[y] < h/g.controls[i].yspan {
rowheights[y] = h / g.controls[i].yspan
}
// save these for step 6
@ -432,8 +434,8 @@ func (g *grid) preferredSize(d *sizing) (width, height int) {
}
// and that's it; just account for padding
return colwidth + (g.xmax - 1) * d.xpadding,
rowheight + (g.ymax - 1) * d.ypadding
return colwidth + (g.xmax-1)*d.xpadding,
rowheight + (g.ymax-1)*d.ypadding
}
func (g *grid) commitResize(a *allocation, d *sizing) {

View File

@ -6,8 +6,8 @@ package ui
import (
"fmt"
"unsafe"
"image"
"unsafe"
)
// #include "gtk_unix.h"

View File

@ -17,7 +17,7 @@ func finishNewLabel(text string, standalone bool) *label {
hwnd := C.newControl(labelclass,
// SS_NOPREFIX avoids accelerator translation; SS_LEFTNOWORDWRAP clips text past the end
// controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi)
C.SS_NOPREFIX | C.SS_LEFTNOWORDWRAP,
C.SS_NOPREFIX|C.SS_LEFTNOWORDWRAP,
C.WS_EX_TRANSPARENT)
l := &label{
_hwnd: hwnd,

View File

@ -192,7 +192,6 @@ func (s *stack) getAuxResizeInfo(d *sizing) {
// this is to satisfy Control; nothing to do here
}
// Space returns a null Control intended for padding layouts with blank space.
// It appears to its owner as a Control of 0x0 size.
//

View File

@ -40,7 +40,7 @@ func (t *tab) Append(name string, control Control) {
defer freegstr(cname)
C.gtk_notebook_set_tab_label_text(t.notebook,
// unfortunately there does not seem to be a gtk_notebook_set_nth_tab_label_text()
C.gtk_notebook_get_nth_page(t.notebook, C.gint(len(t.tabs) - 1)),
C.gtk_notebook_get_nth_page(t.notebook, C.gint(len(t.tabs)-1)),
cname)
}

View File

@ -22,7 +22,7 @@ type tab struct {
func newTab() Tab {
hwnd := C.newControl(C.xWC_TABCONTROL,
C.TCS_TOOLTIPS | C.WS_TABSTOP,
C.TCS_TOOLTIPS|C.WS_TABSTOP,
0) // don't set WS_EX_CONTROLPARENT here; see uitask_windows.c
t := &tab{
_hwnd: hwnd,
@ -38,7 +38,7 @@ func (t *tab) Append(name string, control Control) {
t.tabs = append(t.tabs, c)
// initially hide tab 1..n controls; if we don't, they'll appear over other tabs, resulting in weird behavior
if len(t.tabs) != 1 {
t.tabs[len(t.tabs) - 1].hide()
t.tabs[len(t.tabs)-1].hide()
}
C.tabAppend(t._hwnd, toUTF16(name))
}

View File

@ -4,8 +4,8 @@ package ui
import (
"fmt"
"unsafe"
"reflect"
"unsafe"
)
// #include "winapi_windows.h"
@ -26,7 +26,7 @@ type table struct {
func finishNewTable(b *tablebase, ty reflect.Type) Table {
t := &table{
_hwnd: C.newControl(C.xWC_LISTVIEW,
C.LVS_REPORT | C.LVS_OWNERDATA | C.LVS_NOSORTHEADER | C.LVS_SHOWSELALWAYS | C.LVS_SINGLESEL | C.WS_HSCROLL | C.WS_VSCROLL | C.WS_TABSTOP,
C.LVS_REPORT|C.LVS_OWNERDATA|C.LVS_NOSORTHEADER|C.LVS_SHOWSELALWAYS|C.LVS_SINGLESEL|C.WS_HSCROLL|C.WS_VSCROLL|C.WS_TABSTOP,
C.WS_EX_CLIENTEDGE), // WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog)
tablebase: b,
hotrow: -1,
@ -38,7 +38,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
C.setTableSubclass(t._hwnd, unsafe.Pointer(t))
// LVS_EX_FULLROWSELECT gives us selection across the whole row, not just the leftmost column; this makes the list view work like on other platforms
// LVS_EX_SUBITEMIMAGES gives us images in subitems, which will be important when both images and checkboxes are added
C.tableAddExtendedStyles(t._hwnd, C.LVS_EX_FULLROWSELECT | C.LVS_EX_SUBITEMIMAGES)
C.tableAddExtendedStyles(t._hwnd, C.LVS_EX_FULLROWSELECT|C.LVS_EX_SUBITEMIMAGES)
// this must come after the subclass because it uses one of our private messages
C.SendMessageW(t._hwnd, C.msgTableMakeInitialCheckboxImageList, 0, 0)
for i := 0; i < ty.NumField(); i++ {
@ -89,18 +89,18 @@ func tableGetCell(data unsafe.Pointer, item *C.LVITEMW) {
d := reflect.Indirect(reflect.ValueOf(t.data))
datum := d.Index(int(item.iItem)).Field(int(item.iSubItem))
isText := true
if item.mask & C.LVIF_IMAGE != 0 {
if item.mask&C.LVIF_IMAGE != 0 {
if datum.Type() == reflect.TypeOf(ImageIndex(0)) {
item.iImage = C.int(datum.Interface().(ImageIndex))
isText = false
}
// else let the default behavior work
}
if item.mask & C.LVIF_INDENT != 0 {
if item.mask&C.LVIF_INDENT != 0 {
// always have an indent of zero
item.iIndent = 0
}
if item.mask & C.LVIF_STATE != 0 {
if item.mask&C.LVIF_STATE != 0 {
// start by not changing any state
item.stateMask = 0
if datum.Kind() == reflect.Bool {
@ -129,7 +129,7 @@ func tableGetCell(data unsafe.Pointer, item *C.LVITEMW) {
isText = false
}
}
if item.mask & C.LVIF_TEXT != 0 {
if item.mask&C.LVIF_TEXT != 0 {
if isText {
s := fmt.Sprintf("%v", datum)
item.pszText = toUTF16(s)

View File

@ -19,7 +19,7 @@ var editclass = toUTF16("EDIT")
func startNewTextField(style C.DWORD) *textfield {
hwnd := C.newControl(editclass,
style | C.textfieldStyle,
style|C.textfieldStyle,
C.textfieldExtStyle) // WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog)
t := &textfield{
_hwnd: hwnd,

View File

@ -3,10 +3,10 @@
package ui
import (
"reflect"
"runtime"
"sync"
"unsafe"
"reflect"
)
// Go initializes and runs package ui.
@ -131,7 +131,7 @@ type ForeignEvent struct {
func NewForeignEvent(channel interface{}, handler func(data interface{})) *ForeignEvent {
c := reflect.ValueOf(channel)
t := c.Type()
if t.Kind() != reflect.Chan || (t.ChanDir() & reflect.RecvDir) == 0 {
if t.Kind() != reflect.Chan || (t.ChanDir()&reflect.RecvDir) == 0 {
panic("non-channel or non-receivable channel passed to NewForeignEvent()")
}
fe := &ForeignEvent{

View File

@ -40,7 +40,7 @@ func newWindow(title string, width int, height int, control Control) *window {
if hwnd != w.hwnd {
panic(fmt.Errorf("inconsistency: hwnd returned by CreateWindowEx() (%p) and hwnd stored in Window (%p) differ", hwnd, w.hwnd))
}
hresult := C.EnableThemeDialogTexture(w.hwnd, C.ETDT_ENABLE | C.ETDT_USETABTEXTURE)
hresult := C.EnableThemeDialogTexture(w.hwnd, C.ETDT_ENABLE|C.ETDT_USETABTEXTURE)
if hresult != C.S_OK {
panic(fmt.Errorf("error setting tab background texture on Window; HRESULT: 0x%X", hresult))
}

View File

@ -3,8 +3,8 @@
package ui
import (
"fmt"
"bytes"
"fmt"
"image"
"image/draw"
_ "image/png"
@ -42,10 +42,10 @@ func readIcons() ([]icon, ImageList) {
func tileImage(times int) *image.RGBA {
dx := firstimg.Rect.Dx()
dy := firstimg.Rect.Dy()
res := image.NewRGBA(image.Rect(0, 0, times * dx, times * dy))
res := image.NewRGBA(image.Rect(0, 0, times*dx, times*dy))
r := image.Rect(0, 0, dx, dy)
for y := 0; y < times; y++ {
rr := r.Add(image.Pt(0, y * dy))
rr := r.Add(image.Pt(0, y*dy))
for x := 0; x < times; x++ {
draw.Draw(res, rr, firstimg, image.ZP, draw.Src)
rr = rr.Add(image.Pt(dx, 0))
@ -58,12 +58,12 @@ var icons = []struct {
data []byte
name string
}{
{ __16x16_categories_applications_accessories_png, "16x16/categories/applications-accessories.png", },
{ __16x16_places_folder_png, "16x16/places/folder.png", },
{ __16x16_mimetypes_x_office_spreadsheet_png, "16x16/mimetypes/x-office-spreadsheet.png", },
{ __32x32_categories_applications_accessories_png, "32x32/categories/applications-accessories.png", },
{ __32x32_places_folder_png, "32x32/places/folder.png", },
{ __32x32_mimetypes_x_office_spreadsheet_png, "32x32/mimetypes/x-office-spreadsheet.png", },
{__16x16_categories_applications_accessories_png, "16x16/categories/applications-accessories.png"},
{__16x16_places_folder_png, "16x16/places/folder.png"},
{__16x16_mimetypes_x_office_spreadsheet_png, "16x16/mimetypes/x-office-spreadsheet.png"},
{__32x32_categories_applications_accessories_png, "32x32/categories/applications-accessories.png"},
{__32x32_places_folder_png, "32x32/places/folder.png"},
{__32x32_mimetypes_x_office_spreadsheet_png, "32x32/mimetypes/x-office-spreadsheet.png"},
}
// from http://tango.freedesktop.org/releases/tango-icon-theme-0.8.90.tar.gz, which is public domain

View File

@ -116,7 +116,7 @@ func (r *repainter) alter(rect image.Rectangle, c color.Color) {
}
func (r *repainter) dorect() {
rect := image.Rect(r.xv, r.yv, r.xv + r.wv, r.yv + r.hv)
rect := image.Rect(r.xv, r.yv, r.xv+r.wv, r.yv+r.hv)
r.alter(rect, color.RGBA{255, 0, 255, 128})
r.area.Repaint(rect)
}

View File

@ -5,15 +5,15 @@ package ui
// This file is called zz_test.go to keep it separate from the other files in this package (and because go test won't accept just test.go)
import (
"fmt"
"flag"
"reflect"
"testing"
"fmt"
"image"
"image/color"
"image/draw"
"time"
"reflect"
"strings"
"testing"
"time"
)
var closeOnClick = flag.Bool("close", false, "close on click")
@ -23,12 +23,13 @@ type dtype struct {
Name string
Address string
}
var ddata = []dtype{
{ "alpha", "beta" },
{ "gamma", "delta" },
{ "epsilon", "zeta" },
{ "eta", "theta" },
{ "iota", "kappa" },
{"alpha", "beta"},
{"gamma", "delta"},
{"epsilon", "zeta"},
{"eta", "theta"},
{"iota", "kappa"},
}
type testwin struct {
@ -67,9 +68,10 @@ type testwin struct {
type areaHandler struct {
handled bool
}
func (a *areaHandler) Paint(r image.Rectangle) *image.RGBA {
i := image.NewRGBA(r)
draw.Draw(i, r, &image.Uniform{color.RGBA{128,0,128,255}}, image.ZP, draw.Src)
draw.Draw(i, r, &image.Uniform{color.RGBA{128, 0, 128, 255}}, image.ZP, draw.Src)
return i
}
func (a *areaHandler) Mouse(me MouseEvent) { fmt.Printf("%#v\n", me) }
@ -192,7 +194,7 @@ func (tw *testwin) make(done chan struct{}) {
NewCheckbox("hello"),
NewTextField(),
NewPasswordField(),
NewTable(reflect.TypeOf(struct{A,B,C int}{})),
NewTable(reflect.TypeOf(struct{ A, B, C int }{})),
NewStandaloneLabel("hello"))
tw.t.Append("Pref Width", tw.spw)
tw.sph = NewVerticalStack(
@ -200,7 +202,7 @@ func (tw *testwin) make(done chan struct{}) {
NewCheckbox("hello"),
NewTextField(),
NewPasswordField(),
NewTable(reflect.TypeOf(struct{A,B,C int}{})),
NewTable(reflect.TypeOf(struct{ A, B, C int }{})),
NewStandaloneLabel("hello ÉÀÔ"))
tw.t.Append("Pref Height", tw.sph)
stack1 := NewHorizontalStack(NewLabel("Test"), NewTextField())
@ -208,7 +210,7 @@ func (tw *testwin) make(done chan struct{}) {
stack2 := NewHorizontalStack(NewLabel("ÉÀÔ"), NewTextField())
stack2.SetStretchy(1)
stack3 := NewHorizontalStack(NewLabel("Test 2"),
NewTable(reflect.TypeOf(struct{A,B,C int}{})))
NewTable(reflect.TypeOf(struct{ A, B, C int }{})))
stack3.SetStretchy(1)
tw.s = NewVerticalStack(stack1, stack2, stack3)
tw.s.SetStretchy(2)