Mercurial > godwindows
changeset 86:2237ef63fb69
Add row data parameter to the item enter callback...
Add new by_data() varients of a couple of functions.
Add using and displaying row data to the test programs.
author | Brian Smith <brian@dbsoft.org> |
---|---|
date | Thu, 15 Aug 2013 14:08:25 -0500 |
parents | e9b0b18f9360 |
children | 4c8683490c14 |
files | src/dw/dw.go src/dw/dwglue.c src/dwootest/dwootest.go src/dwtest/dwtest.go |
diffstat | 4 files changed, 64 insertions(+), 146 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dw/dw.go Sat Aug 10 09:15:48 2013 -0500 +++ b/src/dw/dw.go Thu Aug 15 14:08:25 2013 -0500 @@ -4322,6 +4322,16 @@ Container_cursor(handle, text); } +// Cursors the item with the data speficied, and scrolls to that item. +func Container_cursor_by_data(handle HANDLE, data POINTER) { + C.go_container_cursor_by_data(handle.GetHandle(), unsafe.Pointer(data)); +} + +// Cursors the item with the data speficied, and scrolls to that item. +func (handle HCONTAINER) CursorByData(data POINTER) { + Container_cursor_by_data(handle, data); +} + // Deletes the item with the title specified. func Container_delete_row(handle HANDLE, text string) { ctext := C.CString(text); @@ -4335,6 +4345,16 @@ Container_delete_row(handle, text); } +// Deletes the item with the data specified. +func Container_delete_row_by_data(handle HANDLE, data POINTER) { + C.go_container_delete_row_by_data(handle.GetHandle(), unsafe.Pointer(data)); +} + +// Deletes the item with the data specified. +func (handle HCONTAINER) DeleteRowByData(data POINTER) { + Container_delete_row_by_data(handle, data); +} + // Optimizes the column widths so that all data is visible. func Container_optimize(handle HANDLE) { C.go_container_optimize(handle.GetHandle()); @@ -4704,7 +4724,7 @@ } // Connect a function or closure to a tree ENTER/RETURN press event. -func (window HTREE) ConnectItemEnter(sigfunc func(window HTREE, str string) int) { +func (window HTREE) ConnectItemEnter(sigfunc func(window HTREE, str string, itemdata POINTER) int) { csigname := C.CString(C.DW_SIGNAL_ITEM_ENTER); defer C.free(unsafe.Pointer(csigname)); @@ -4713,7 +4733,7 @@ } // Connect a function or closure to a container ENTER/RETURN press event. -func (window HCONTAINER) ConnectItemEnter(sigfunc func(window HCONTAINER, str string) int) { +func (window HCONTAINER) ConnectItemEnter(sigfunc func(window HCONTAINER, str string, itemdata POINTER) int) { csigname := C.CString(C.DW_SIGNAL_ITEM_ENTER); defer C.free(unsafe.Pointer(csigname)); @@ -5468,149 +5488,35 @@ return C.int(thisfunc(HGENERIC{window}, int(x), int(y), int(width), int(height), POINTER(data))); } -//export go_int_callback_string -func go_int_callback_string(pfunc unsafe.Pointer, window unsafe.Pointer, str *C.char, data unsafe.Pointer, flags C.uint) C.int { +//export go_int_callback_item_enter +func go_int_callback_item_enter(pfunc unsafe.Pointer, window unsafe.Pointer, text *C.char, data unsafe.Pointer, itemdata unsafe.Pointer, flags C.uint) C.int { switch flags { - case (1 << 8): // HWND - thisfunc := *(*func(HWND, string, POINTER) int)(pfunc); - return C.int(thisfunc(HWND{window}, C.GoString(str), POINTER(data))); - case (2 << 8): // HENTRYFIELD - thisfunc := *(*func(HENTRYFIELD, string, POINTER) int)(pfunc); - return C.int(thisfunc(HENTRYFIELD{window}, C.GoString(str), POINTER(data))); - case (3 << 8): // HTEXT - thisfunc := *(*func(HTEXT, string, POINTER) int)(pfunc); - return C.int(thisfunc(HTEXT{window}, C.GoString(str), POINTER(data))); case (4 << 8): // HTREE + thisfunc := *(*func(HTREE, string, POINTER, POINTER) int)(pfunc); + return C.int(thisfunc(HTREE{window}, C.GoString(text), POINTER(data), POINTER(itemdata))); + case (5 << 8): // HCONTAINER + thisfunc := *(*func(HCONTAINER, string, POINTER, POINTER) int)(pfunc); + filesystem := false; + if Window_get_data(HCONTAINER{window, false}, "_go_filesystem") != nil { + filesystem = true; + } + return C.int(thisfunc(HCONTAINER{window, filesystem}, C.GoString(text), POINTER(data), POINTER(itemdata))); + case go_flags_no_data: + thisfunc := *(*func(HANDLE, string, POINTER) int)(pfunc); + return C.int(thisfunc(HGENERIC{window}, C.GoString(text), POINTER(itemdata))); + case (4 << 8) | go_flags_no_data: // HTREE thisfunc := *(*func(HTREE, string, POINTER) int)(pfunc); - return C.int(thisfunc(HTREE{window}, C.GoString(str), POINTER(data))); - case (5 << 8): // HCONTAINER + return C.int(thisfunc(HTREE{window}, C.GoString(text), POINTER(itemdata))); + case (5 << 8) | go_flags_no_data: // HCONTAINER thisfunc := *(*func(HCONTAINER, string, POINTER) int)(pfunc); filesystem := false; if Window_get_data(HCONTAINER{window, false}, "_go_filesystem") != nil { filesystem = true; } - return C.int(thisfunc(HCONTAINER{window, filesystem}, C.GoString(str), POINTER(data))); - case (6 << 8): // HMLE - thisfunc := *(*func(HMLE, string, POINTER) int)(pfunc); - return C.int(thisfunc(HMLE{window}, C.GoString(str), POINTER(data))); - case (7 << 8): // HBUTTON - thisfunc := *(*func(HBUTTON, string, POINTER) int)(pfunc); - return C.int(thisfunc(HBUTTON{window}, C.GoString(str), POINTER(data))); - case (8 << 8): // HSPINBUTTON - thisfunc := *(*func(HSPINBUTTON, string, POINTER) int)(pfunc); - return C.int(thisfunc(HSPINBUTTON{window}, C.GoString(str), POINTER(data))); - case (9 << 8): // HNOTEBOOK - thisfunc := *(*func(HNOTEBOOK, string, POINTER) int)(pfunc); - return C.int(thisfunc(HNOTEBOOK{window}, C.GoString(str), POINTER(data))); - case (10 << 8): // HBOX - thisfunc := *(*func(HBOX, string, POINTER) int)(pfunc); - return C.int(thisfunc(HBOX{window}, C.GoString(str), POINTER(data))); - case (11 << 8): // HSCROLLBOX - thisfunc := *(*func(HSCROLLBOX, string, POINTER) int)(pfunc); - return C.int(thisfunc(HSCROLLBOX{window}, C.GoString(str), POINTER(data))); - case (12 << 8): // HMENUITEM - thisfunc := *(*func(HMENUITEM, string, POINTER) int)(pfunc); - return C.int(thisfunc(HMENUITEM{window}, C.GoString(str), POINTER(data))); - case (13 << 8): // HLISTBOX - thisfunc := *(*func(HLISTBOX, string, POINTER) int)(pfunc); - return C.int(thisfunc(HLISTBOX{window}, C.GoString(str), POINTER(data))); - case (14 << 8): // HPERCENT - thisfunc := *(*func(HPERCENT, string, POINTER) int)(pfunc); - return C.int(thisfunc(HPERCENT{window}, C.GoString(str), POINTER(data))); - case (15 << 8): // HSLIDER - thisfunc := *(*func(HSLIDER, string, POINTER) int)(pfunc); - return C.int(thisfunc(HSLIDER{window}, C.GoString(str), POINTER(data))); - case (16 << 8): // HSCROLLBAR - thisfunc := *(*func(HSCROLLBAR, string, POINTER) int)(pfunc); - return C.int(thisfunc(HSCROLLBAR{window}, C.GoString(str), POINTER(data))); - case (17 << 8): // HRENDER - thisfunc := *(*func(HRENDER, string, POINTER) int)(pfunc); - return C.int(thisfunc(HRENDER{window}, C.GoString(str), POINTER(data))); - case (18 << 8): // HHTML - thisfunc := *(*func(HRENDER, string, POINTER) int)(pfunc); - return C.int(thisfunc(HRENDER{window}, C.GoString(str), POINTER(data))); - case (19 << 8): // HCALENDAR - thisfunc := *(*func(HCALENDAR, string, POINTER) int)(pfunc); - return C.int(thisfunc(HCALENDAR{window}, C.GoString(str), POINTER(data))); - case (20 << 8): // HBITMAP - thisfunc := *(*func(HBITMAP, string, POINTER) int)(pfunc); - return C.int(thisfunc(HBITMAP{window}, C.GoString(str), POINTER(data))); - case (21 << 8): // HSPLITBAR - thisfunc := *(*func(HSPLITBAR, string, POINTER) int)(pfunc); - return C.int(thisfunc(HSPLITBAR{window}, C.GoString(str), POINTER(data))); - case go_flags_no_data: - thisfunc := *(*func(HANDLE, string) int)(pfunc); - return C.int(thisfunc(HGENERIC{window}, C.GoString(str))); - case (1 << 8) | go_flags_no_data: // HWND - thisfunc := *(*func(HWND, string) int)(pfunc); - return C.int(thisfunc(HWND{window}, C.GoString(str))); - case (2 << 8) | go_flags_no_data: // HENTRYFIELD - thisfunc := *(*func(HENTRYFIELD, string) int)(pfunc); - return C.int(thisfunc(HENTRYFIELD{window}, C.GoString(str))); - case (3 << 8) | go_flags_no_data: // HTEXT - thisfunc := *(*func(HTEXT, string) int)(pfunc); - return C.int(thisfunc(HTEXT{window}, C.GoString(str))); - case (4 << 8) | go_flags_no_data: // HTREE - thisfunc := *(*func(HTREE, string) int)(pfunc); - return C.int(thisfunc(HTREE{window}, C.GoString(str))); - case (5 << 8) | go_flags_no_data: // HCONTAINER - thisfunc := *(*func(HCONTAINER, string) int)(pfunc); - filesystem := false; - if Window_get_data(HCONTAINER{window, false}, "_go_filesystem") != nil { - filesystem = true; - } - return C.int(thisfunc(HCONTAINER{window, filesystem}, C.GoString(str))); - case (6 << 8) | go_flags_no_data: // HMLE - thisfunc := *(*func(HMLE, string) int)(pfunc); - return C.int(thisfunc(HMLE{window}, C.GoString(str))); - case (7 << 8) | go_flags_no_data: // HBUTTON - thisfunc := *(*func(HBUTTON, string) int)(pfunc); - return C.int(thisfunc(HBUTTON{window}, C.GoString(str))); - case (8 << 8) | go_flags_no_data: // HSPINBUTTON - thisfunc := *(*func(HSPINBUTTON, string) int)(pfunc); - return C.int(thisfunc(HSPINBUTTON{window}, C.GoString(str))); - case (9 << 8) | go_flags_no_data: // HNOTEBOOK - thisfunc := *(*func(HNOTEBOOK, string) int)(pfunc); - return C.int(thisfunc(HNOTEBOOK{window}, C.GoString(str))); - case (10 << 8) | go_flags_no_data: // HBOX - thisfunc := *(*func(HBOX, string) int)(pfunc); - return C.int(thisfunc(HBOX{window}, C.GoString(str))); - case (11 << 8) | go_flags_no_data: // HSCROLLBOX - thisfunc := *(*func(HSCROLLBOX, string) int)(pfunc); - return C.int(thisfunc(HSCROLLBOX{window}, C.GoString(str))); - case (12 << 8) | go_flags_no_data: // HMENUITEM - thisfunc := *(*func(HMENUITEM, string) int)(pfunc); - return C.int(thisfunc(HMENUITEM{window}, C.GoString(str))); - case (13 << 8) | go_flags_no_data: // HLISTBOX - thisfunc := *(*func(HLISTBOX, string) int)(pfunc); - return C.int(thisfunc(HLISTBOX{window}, C.GoString(str))); - case (14 << 8) | go_flags_no_data: // HPERCENT - thisfunc := *(*func(HPERCENT, string) int)(pfunc); - return C.int(thisfunc(HPERCENT{window}, C.GoString(str))); - case (15 << 8) | go_flags_no_data: // HSLIDER - thisfunc := *(*func(HSLIDER, string) int)(pfunc); - return C.int(thisfunc(HSLIDER{window}, C.GoString(str))); - case (16 << 8) | go_flags_no_data: // HSCROLLBAR - thisfunc := *(*func(HSCROLLBAR, string) int)(pfunc); - return C.int(thisfunc(HSCROLLBAR{window}, C.GoString(str))); - case (17 << 8) | go_flags_no_data: // HRENDER - thisfunc := *(*func(HRENDER, string) int)(pfunc); - return C.int(thisfunc(HRENDER{window}, C.GoString(str))); - case (18 << 8) | go_flags_no_data: // HHTML - thisfunc := *(*func(HHTML, string) int)(pfunc); - return C.int(thisfunc(HHTML{window}, C.GoString(str))); - case (19 << 8) | go_flags_no_data: // HCALENDAR - thisfunc := *(*func(HCALENDAR, string) int)(pfunc); - return C.int(thisfunc(HCALENDAR{window}, C.GoString(str))); - case (20 << 8) | go_flags_no_data: // HBITMAP - thisfunc := *(*func(HBITMAP, string) int)(pfunc); - return C.int(thisfunc(HBITMAP{window}, C.GoString(str))); - case (21 << 8) | go_flags_no_data: // HSPLITBAR - thisfunc := *(*func(HSPLITBAR, string) int)(pfunc); - return C.int(thisfunc(HSPLITBAR{window}, C.GoString(str))); + return C.int(thisfunc(HCONTAINER{window, filesystem}, C.GoString(text), POINTER(itemdata))); } - thisfunc := *(*func(HANDLE, string, POINTER) int)(pfunc); - return C.int(thisfunc(HGENERIC{window}, C.GoString(str), POINTER(data))); + thisfunc := *(*func(HANDLE, string, POINTER, POINTER) int)(pfunc); + return C.int(thisfunc(HGENERIC{window}, C.GoString(text), POINTER(data), POINTER(itemdata))); } //export go_int_callback_item_context
--- a/src/dw/dwglue.c Sat Aug 10 09:15:48 2013 -0500 +++ b/src/dw/dwglue.c Thu Aug 15 14:08:25 2013 -0500 @@ -910,11 +910,21 @@ dw_container_cursor((HWND)handle, text); } +static void go_container_cursor_by_data(void *handle, void *data) +{ + dw_container_cursor_by_data((HWND)handle, data); +} + static void go_container_delete_row(void *handle, char *text) { dw_container_delete_row((HWND)handle, text); } +static void go_container_delete_row_by_data(void *handle, void *data) +{ + dw_container_delete_row_by_data((HWND)handle, data); +} + static void go_container_optimize(void *handle) { dw_container_optimize((HWND)handle); @@ -1096,7 +1106,7 @@ extern int go_int_callback_keypress(void *pfunc, void *window, char ch, int vk, int state, void *data, char *utf8, unsigned int flags); extern int go_int_callback_mouse(void *pfunc, void* window, int x, int y, int mask, void *data, unsigned int flags); extern int go_int_callback_expose(void *pfunc, void* window, int x, int y, int width, int height, void *data, unsigned int flags); -extern int go_int_callback_string(void *pfunc, void* window, char *str, void *data, unsigned int flags); +extern int go_int_callback_item_enter(void *pfunc, void *window, char *text, void *data, void *itemdata, unsigned int flags); extern int go_int_callback_item_context(void *pfunc, void *window, char *text, int x, int y, void *data, void *itemdata, unsigned int flags); extern int go_int_callback_item_select(void *pfunc, void *window, void *item, char *text, void *data, void *itemdata, unsigned int flags); extern int go_int_callback_numeric(void *pfunc, void* window, int val, void *data, unsigned int flags); @@ -1157,12 +1167,12 @@ return 0; } -static int DWSIGNAL go_callback_string(HWND window, char *str, void *data) +static int DWSIGNAL go_callback_item_enter(HWND window, char *text, void *data, void *itemdata) { if(data) { void **param = (void **)data; - return go_int_callback_string(param[0], (void *)window, str, param[1], DW_POINTER_TO_INT(param[2])); + return go_int_callback_item_enter(param[0], (void *)window, text, param[1], itemdata, DW_POINTER_TO_INT(param[2])); } return 0; } @@ -1316,7 +1326,7 @@ } else if(strcmp(signame, DW_SIGNAL_ITEM_ENTER) == 0) { - func = (void *)go_callback_string; + func = (void *)go_callback_item_enter; } else if(strcmp(signame, DW_SIGNAL_ITEM_CONTEXT) == 0) {
--- a/src/dwootest/dwootest.go Sat Aug 10 09:15:48 2013 -0500 +++ b/src/dwootest/dwootest.go Thu Aug 15 14:08:25 2013 -0500 @@ -866,7 +866,8 @@ containerinfo.SetItemULong(1, z, uint(z*100)); containerinfo.SetItemTime(2, z, z+10, z+10, z+10); containerinfo.SetItemDate(3, z, z+10, z+10, z+2000); - containerinfo.SetRowTitle(z, fmt.Sprintf("Don't allocate from stack: Item: %d", z)); + containerinfo.SetRowTitle(z, fmt.Sprintf("We can now allocate from the stack: Item: %d", z)); + containerinfo.SetRowData(z, dw.POINTER(uintptr(z))); } containerinfo.Insert(); @@ -894,8 +895,8 @@ mle_point = container_mle.Import(fmt.Sprintf("[%d]\r\n\r\n", mle_point), mle_point); container_mle.SetCursor(mle_point); /* connect our event trappers... */ - container.ConnectItemEnter(func(window dw.HCONTAINER, text string) int { - container_status.SetText(fmt.Sprintf("DW_SIGNAL_ITEM_ENTER: Window: %x Text: %s", dw.HANDLE_TO_UINTPTR(window), text)); + container.ConnectItemEnter(func(window dw.HCONTAINER, text string, itemdata dw.POINTER) int { + container_status.SetText(fmt.Sprintf("DW_SIGNAL_ITEM_ENTER: Window: %x Text: %s Itemdata: %x", dw.HANDLE_TO_UINTPTR(window), text, uintptr(itemdata))); return dw.FALSE; }); container.ConnectItemContext(func(window dw.HCONTAINER, text string, x int, y int, itemdata dw.POINTER) int {
--- a/src/dwtest/dwtest.go Sat Aug 10 09:15:48 2013 -0500 +++ b/src/dwtest/dwtest.go Thu Aug 15 14:08:25 2013 -0500 @@ -647,8 +647,8 @@ } // Page 3 and 4 Callbacks -func item_enter_cb(window dw.HCONTAINER, text string, data dw.POINTER) int { - message := fmt.Sprintf("DW_SIGNAL_ITEM_ENTER: Window: %x Text: %s", dw.HANDLE_TO_UINTPTR(window), text); +func item_enter_cb(window dw.HCONTAINER, text string, data dw.POINTER, itemdata dw.POINTER) int { + message := fmt.Sprintf("DW_SIGNAL_ITEM_ENTER: Window: %x Text: %s Itemdata: %x", dw.HANDLE_TO_UINTPTR(window), text, uintptr(itemdata)); dw.Window_set_text(dw.POINTER_TO_HANDLE(data), message); return FALSE; } @@ -1152,7 +1152,8 @@ dw.Filesystem_set_item_ulong(container, containerinfo, 1, z, uint(z*100)); dw.Filesystem_set_item_time(container, containerinfo, 2, z, z+10, z+10, z+10); dw.Filesystem_set_item_date(container, containerinfo, 3, z, z+10, z+10, z+2000); - dw.Container_set_row_title(containerinfo, z, fmt.Sprintf("Don't allocate from stack: Item: %d", z)); + dw.Container_set_row_title(containerinfo, z, fmt.Sprintf("We can now allocate from the stack: Item: %d", z)); + dw.Container_set_row_data(containerinfo, z, dw.POINTER(uintptr(z))); } dw.Container_insert(container, containerinfo, 3);