Reduced the number of unnecessary error returns based on MSDN. The TODOs that used to be there have been moved to a new file; similar files for Mac and Linux will also be made.

This commit is contained in:
Pietro Gagliardi 2014-02-15 13:36:24 -05:00
parent dce24dae3f
commit d1768f2787
7 changed files with 19 additions and 32 deletions

View File

@ -42,11 +42,7 @@ func (c *Checkbox) Checked() bool {
c.lock.Lock()
defer c.lock.Unlock()
check, err := c.sysData.isChecked()
if err != nil {
panic(err) // TODO
}
return check
return c.sysData.isChecked()
}
func (c *Checkbox) make(window *sysData) error {

View File

@ -29,14 +29,14 @@ func NewCombobox(editable bool, items ...string) (c *Combobox) {
// TODO Append, InsertBefore, Delete
// Selection returns the current selection.
func (c *Combobox) Selection() (string, error) {
func (c *Combobox) Selection() string {
c.lock.Lock()
defer c.lock.Unlock()
if c.created {
return c.sysData.text()
}
return "", nil
return ""
}
// TODO SelectedIndex

View File

@ -27,14 +27,14 @@ func NewLineEdit(text string) *LineEdit {
// TODO SetText
// Text returns the LineEdit's text.
func (l *LineEdit) Text() (string, error) {
func (l *LineEdit) Text() string {
l.lock.Lock()
defer l.lock.Unlock()
if l.created {
return l.sysData.text()
}
return l.initText, nil
return l.initText
}
// TODO adorn errors with what failed

18
main.go
View File

@ -30,19 +30,11 @@ mainloop:
case <-w.Closing:
break mainloop
case <-b.Clicked:
cs1, err := cb1.Selection()
if err != nil {
panic(err)
}
cs2, err := cb2.Selection()
if err != nil {
panic(err)
}
et, err := e.Text()
if err != nil {
panic(err)
}
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s", c.Checked(), cs1, cs2, et))
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s",
c.Checked(),
cb1.Selection(),
cb2.Selection(),
e.Text()))
if err != nil {
panic(err)
}

View File

@ -27,7 +27,7 @@ func (c *cSysData) setText(text string) error {
func (c *cSysData) setRect(x int, y int, width int, height int) error {
panic(runtime.GOOS + " sysData does not define setRect()")
}
func (c *cSysData) isChecked() (bool, error) {
func (c *cSysData) isChecked() bool {
panic(runtime.GOOS + " sysData does not define isChecked()")
}
func (c *cSysData) text() (string, error) {

View File

@ -244,8 +244,7 @@ func (s *sysData) setRect(x int, y int, width int, height int) error {
return nil
}
// TODO figure out how to handle error
func (s *sysData) isChecked() (bool, error) {
func (s *sysData) isChecked() bool {
ret := make(chan uiret)
defer close(ret)
uitask <- &uimsg{
@ -259,16 +258,14 @@ func (s *sysData) isChecked() (bool, error) {
ret: ret,
}
r := <-ret
return r.ret == _BST_CHECKED, nil
return r.ret == _BST_CHECKED
}
// TODO adorn error messages with which part failed
func (s *sysData) text() (str string, err error) {
func (s *sysData) text() (str string) {
var tc []uint16
ret := make(chan uiret)
defer close(ret)
// TODO figure out how to handle errors
uitask <- &uimsg{
call: _sendMessage,
p: []uintptr{
@ -282,7 +279,6 @@ func (s *sysData) text() (str string, err error) {
r := <-ret
length := r.ret + 1 // terminating null
tc = make([]uint16, length)
// TODO figure out how to handle errors
uitask <- &uimsg{
call: _sendMessage,
p: []uintptr{
@ -294,8 +290,7 @@ func (s *sysData) text() (str string, err error) {
ret: ret,
}
<-ret
// TODO check character count
return syscall.UTF16ToString(tc), nil
return syscall.UTF16ToString(tc)
}
// TODO figure out how to handle errors

4
winerrors.md Normal file
View File

@ -0,0 +1,4 @@
- all SendMessage() calls
- BM_GETCHECK (sysData.isChecked())
- WM_GETTEXTLENGTH (LRESULT is unsinged so) (sysData.text())
- WM_GETTEXT (WM_GETTEXTLENGTH docs say its result may be larger than the actual length, so we can't use that) (sysData.text())