More go fmt.

This commit is contained in:
Pietro Gagliardi 2014-06-10 11:23:00 -04:00
parent 09e3fcd9cb
commit 6e7f15c8e0
2 changed files with 74 additions and 75 deletions

View File

@ -4,7 +4,6 @@ package ui
import ( import (
"fmt" "fmt"
// "syscall"
"unsafe" "unsafe"
) )
@ -20,64 +19,64 @@ import (
// As we are left with incomplete data, an arbitrary size will be chosen // As we are left with incomplete data, an arbitrary size will be chosen
const ( const (
defaultWidth = 100 // 2 * preferred width of buttons defaultWidth = 100 // 2 * preferred width of buttons
) )
type dlgunits struct { type dlgunits struct {
width int width int
height int height int
longest bool // TODO actually use this longest bool // TODO actually use this
getsize uintptr getsize uintptr
area bool // use area sizes instead area bool // use area sizes instead
} }
var stdDlgSizes = [nctypes]dlgunits{ var stdDlgSizes = [nctypes]dlgunits{
c_button: dlgunits{ c_button: dlgunits{
width: 50, width: 50,
height: 14, height: 14,
getsize: _BCM_GETIDEALSIZE, getsize: _BCM_GETIDEALSIZE,
}, },
c_checkbox: dlgunits{ c_checkbox: dlgunits{
// widtdh is not defined here so assume longest // widtdh is not defined here so assume longest
longest: true, longest: true,
height: 10, height: 10,
}, },
c_combobox: dlgunits{ c_combobox: dlgunits{
// technically the height of a combobox has to include the drop-down list (this is a historical accident: originally comboboxes weren't drop-down) // technically the height of a combobox has to include the drop-down list (this is a historical accident: originally comboboxes weren't drop-down)
// but since we're forcing Common Controls version 6, we can take advantage of one of its mechanisms to automatically fix this mistake (bad practice but whatever) // but since we're forcing Common Controls version 6, we can take advantage of one of its mechanisms to automatically fix this mistake (bad practice but whatever)
// see also: http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx // see also: http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx
// note that the Microsoft guidelines pages don't take the list size into account // note that the Microsoft guidelines pages don't take the list size into account
longest: true, longest: true,
height: 12, // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx; the page linked above says 14 height: 12, // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx; the page linked above says 14
}, },
c_lineedit: dlgunits{ c_lineedit: dlgunits{
longest: true, longest: true,
height: 14, height: 14,
}, },
c_label: dlgunits{ c_label: dlgunits{
longest: true, longest: true,
height: 8, height: 8,
}, },
c_listbox: dlgunits{ c_listbox: dlgunits{
longest: true, longest: true,
// height is not clearly defined here ("an integral number of items (3 items minimum)") so just use a three-line edit control // height is not clearly defined here ("an integral number of items (3 items minimum)") so just use a three-line edit control
height: 14 + 10 + 10, height: 14 + 10 + 10,
}, },
c_progressbar: dlgunits{ c_progressbar: dlgunits{
width: 237, // the first reference says 107 also works; TODO decide which to use width: 237, // the first reference says 107 also works; TODO decide which to use
height: 8, height: 8,
}, },
c_area: dlgunits{ c_area: dlgunits{
area: true, area: true,
}, },
} }
var ( var (
_selectObject = gdi32.NewProc("SelectObject") _selectObject = gdi32.NewProc("SelectObject")
_getDC = user32.NewProc("GetDC") _getDC = user32.NewProc("GetDC")
_getTextExtentPoint32 = gdi32.NewProc("GetTextExtentPoint32W") _getTextExtentPoint32 = gdi32.NewProc("GetTextExtentPoint32W")
_getTextMetrics = gdi32.NewProc("GetTextMetricsW") _getTextMetrics = gdi32.NewProc("GetTextMetricsW")
_releaseDC = user32.NewProc("ReleaseDC") _releaseDC = user32.NewProc("ReleaseDC")
) )
// This function runs on uitask; call the functions directly. // This function runs on uitask; call the functions directly.
@ -95,7 +94,7 @@ func (s *sysData) preferredSize() (width int, height int) {
msg, msg,
uintptr(0), uintptr(0),
uintptr(unsafe.Pointer(&size))) uintptr(unsafe.Pointer(&size)))
if r1 != uintptr(_FALSE) { // success if r1 != uintptr(_FALSE) { // success
return int(size.cx), int(size.cy) return int(size.cx), int(size.cy)
} }
// otherwise the message approach failed, so fall back to the regular approach // otherwise the message approach failed, so fall back to the regular approach
@ -107,28 +106,28 @@ func (s *sysData) preferredSize() (width int, height int) {
var baseX, baseY int var baseX, baseY int
r1, _, err := _getDC.Call(uintptr(s.hwnd)) r1, _, err := _getDC.Call(uintptr(s.hwnd))
if r1 == 0 { // failure if r1 == 0 { // failure
panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err)) panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err))
} }
dc = _HANDLE(r1) dc = _HANDLE(r1)
r1, _, err = _selectObject.Call( r1, _, err = _selectObject.Call(
uintptr(dc), uintptr(dc),
uintptr(controlFont)) uintptr(controlFont))
if r1 == 0 { // failure if r1 == 0 { // failure
panic(fmt.Errorf("error loading control font into device context for preferred size calculation: %v", err)) panic(fmt.Errorf("error loading control font into device context for preferred size calculation: %v", err))
} }
r1, _, err = _getTextMetrics.Call( r1, _, err = _getTextMetrics.Call(
uintptr(dc), uintptr(dc),
uintptr(unsafe.Pointer(&tm))) uintptr(unsafe.Pointer(&tm)))
if r1 == 0 { // failure if r1 == 0 { // failure
panic(fmt.Errorf("error getting text metrics for preferred size calculations: %v", err)) panic(fmt.Errorf("error getting text metrics for preferred size calculations: %v", err))
} }
baseX = int(tm.tmAveCharWidth) // TODO not optimal; third reference has better way baseX = int(tm.tmAveCharWidth) // TODO not optimal; third reference has better way
baseY = int(tm.tmHeight) baseY = int(tm.tmHeight)
r1, _, err = _releaseDC.Call( r1, _, err = _releaseDC.Call(
uintptr(s.hwnd), uintptr(s.hwnd),
uintptr(dc)) uintptr(dc))
if r1 == 0 { // failure if r1 == 0 { // failure
panic(fmt.Errorf("error releasing DC for preferred size calculations: %v", err)) panic(fmt.Errorf("error releasing DC for preferred size calculations: %v", err))
} }
@ -138,8 +137,8 @@ func (s *sysData) preferredSize() (width int, height int) {
width = defaultWidth width = defaultWidth
} }
height = stdDlgSizes[s.ctype].height height = stdDlgSizes[s.ctype].height
width = muldiv(width, baseX, 4) // equivalent to right of rect width = muldiv(width, baseX, 4) // equivalent to right of rect
height = muldiv(height, baseY, 8) // equivalent to bottom of rect height = muldiv(height, baseY, 8) // equivalent to bottom of rect
return width, height return width, height
} }
@ -158,29 +157,29 @@ func muldiv(ma int, mb int, div int) int {
} }
type _SIZE struct { type _SIZE struct {
cx int32 // originally LONG cx int32 // originally LONG
cy int32 cy int32
} }
type _TEXTMETRICS struct { type _TEXTMETRICS struct {
tmHeight int32 tmHeight int32
tmAscent int32 tmAscent int32
tmDescent int32 tmDescent int32
tmInternalLeading int32 tmInternalLeading int32
tmExternalLeading int32 tmExternalLeading int32
tmAveCharWidth int32 tmAveCharWidth int32
tmMaxCharWidth int32 tmMaxCharWidth int32
tmWeight int32 tmWeight int32
tmOverhang int32 tmOverhang int32
tmDigitizedAspectX int32 tmDigitizedAspectX int32
tmDigitizedAspectY int32 tmDigitizedAspectY int32
tmFirstChar uint16 tmFirstChar uint16
tmLastChar uint16 tmLastChar uint16
tmDefaultChar uint16 tmDefaultChar uint16
tmBreakChar uint16 tmBreakChar uint16
tmItalic byte tmItalic byte
tmUnderlined byte tmUnderlined byte
tmStruckOut byte tmStruckOut byte
tmPitchAndFamily byte tmPitchAndFamily byte
tmCharSet byte tmCharSet byte
} }

View File

@ -11,16 +11,16 @@ import (
// Alternatively, a progressbar can show an animation indicating that progress is being made but how much is indeterminate. // Alternatively, a progressbar can show an animation indicating that progress is being made but how much is indeterminate.
// Newly-created ProgressBars default to showing 0% progress. // Newly-created ProgressBars default to showing 0% progress.
type ProgressBar struct { type ProgressBar struct {
lock sync.Mutex lock sync.Mutex
created bool created bool
sysData *sysData sysData *sysData
initProg int initProg int
} }
// NewProgressBar creates a new ProgressBar. // NewProgressBar creates a new ProgressBar.
func NewProgressBar() *ProgressBar { func NewProgressBar() *ProgressBar {
return &ProgressBar{ return &ProgressBar{
sysData: mksysdata(c_progressbar), sysData: mksysdata(c_progressbar),
} }
} }
@ -58,11 +58,11 @@ func (p *ProgressBar) make(window *sysData) error {
func (p *ProgressBar) setRect(x int, y int, width int, height int, rr *[]resizerequest) { func (p *ProgressBar) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
*rr = append(*rr, resizerequest{ *rr = append(*rr, resizerequest{
sysData: p.sysData, sysData: p.sysData,
x: x, x: x,
y: y, y: y,
width: width, width: width,
height: height, height: height,
}) })
} }