widgetproxy_ccgo.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2025 The tk9.0-go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build linux && (386 || arm || loong64 || ppc64le || riscv64 || s390x)
  5. package tk9_0 // import "modernc.org/tk9.0"
  6. import (
  7. "fmt"
  8. tcl "modernc.org/tcl9.0"
  9. )
  10. // func (proxy *widgetProxy) eventDispatcher(clientData, in uintptr, argc int32, argv uintptr) uintptr {
  11. func (proxy *widgetProxy) eventDispatcher(clientData any, in *tcl.Interp, args []string) int {
  12. // Expect at least arguments for the path and the operation.
  13. if len(args) < 2 {
  14. setResult(fmt.Sprintf("WidgetProxy eventDispatcher internal error: args=%q", args))
  15. return tcl_error
  16. }
  17. args = args[1:]
  18. operation := args[0]
  19. if callback, ok := proxy.operations[operation]; ok {
  20. // Dispatch to the operation's registered callback.
  21. callback(args)
  22. } else {
  23. // Process as normal.
  24. proxy.EvalWrapped(args)
  25. }
  26. return tcl_ok
  27. }
  28. // Create a new Tcl command whose name is the widget's pathname, and
  29. // whose action is to dispatch on the operation passed to the widget:
  30. func (proxy *widgetProxy) registerEventDispatcher() {
  31. if err := interp.RegisterCommand(proxy.window.String(), proxy.eventDispatcher, nil, nil); err != nil {
  32. fail(fmt.Errorf("registering widget proxy event dispatcher proxy failed: %v", err))
  33. }
  34. }
  35. func (proxy *widgetProxy) unregisterEventDispatcher() {
  36. evalErr(fmt.Sprintf("rename %s {}", proxy.window))
  37. }