/src/wrappers/gtk/library/gtk_tree_select_function.e

http://github.com/tybor/Liberty · Specman e · 93 lines · 73 code · 14 blank · 6 comment · 3 complexity · d86c0f839839d1b51715a5ae051408f4 MD5 · raw file

  1. indexing
  2. description: "Callback for tree selection functions"
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. date: "$Date:$"
  19. revision "$Revision:$"
  20. class GTK_TREE_SELECT_FUNCTION
  21. inherit
  22. WRAPPER_HANDLER -- It wraps a callback function
  23. insert
  24. ANY
  25. GTK
  26. G_OBJECT_FACTORY [GTK_TREE_MODEL]
  27. GTK_TREE_SELECTION_EXTERNALS
  28. creation make
  29. feature
  30. make (a_selection: GTK_TREE_SELECTION; a_function: FUNCTION[ANY,TUPLE[GTK_TREE_SELECTION, GTK_TREE_MODEL, GTK_TREE_PATH, BOOLEAN],BOOLEAN]) is
  31. require gtk_initialized: gtk.is_initialized
  32. local array: NATIVE_ARRAY [POINTER]; callback_ptr: POINTER
  33. do
  34. function := a_function
  35. gtk_tree_selection_set_select_function (a_selection.handle,
  36. $low_level_callback, -- selection function
  37. callback_array ($callback), -- The selection function's data.
  38. default_pointer -- destroy function for user data. May be and indeed it is NULL.
  39. )
  40. end
  41. feature {} --
  42. callback_array (a_callback_pointer: POINTER): POINTER is
  43. -- This call is required because we need to build an array with
  44. -- the address of an Eiffel feature (namely callback). `$'
  45. -- operator thought can be used only in a feature call. Hence this.
  46. do
  47. Result:= {NATIVE_ARRAY[POINTER] <<a_callback_pointer ,Current.to_pointer>>}.to_external
  48. end
  49. low_level_callback (selection, model, path: POINTER; path_currently_selected: INTEGER; data: POINTER): INTEGER is
  50. -- Low level callback will be called by GTK; it will call
  51. -- `callback'.
  52. external "C use <callbacks.h>"
  53. alias "EiffelGtkTreeSelectionFunc"
  54. end
  55. feature
  56. callback (selection_ptr, model_ptr,path_ptr: POINTER; path_currently_selected: INTEGER): INTEGER is --; instance: POINTER) is
  57. local
  58. a_selection: GTK_TREE_SELECTION;
  59. a_model: GTK_TREE_MODEL
  60. a_path: GTK_TREE_PATH
  61. selection_factory: G_OBJECT_EXPANDED_FACTORY [GTK_TREE_SELECTION]
  62. do
  63. debug
  64. print ("Gtk tree select function callback:")
  65. print (" selection=") print(selection_ptr.to_string)
  66. print (" model=") print(model_ptr.to_string)
  67. print (" path=") print(path_ptr.to_string)
  68. print (" path_currently_selected=") print(path_currently_selected.to_string)
  69. --print (" instance=") print (instance.to_string)
  70. print ("%N")
  71. end
  72. a_selection := selection_factory.wrapper(selection_ptr)
  73. a_model := wrapper (model_ptr)
  74. create a_path.from_external_pointer (path_ptr)
  75. Result := (function.item ([a_selection,a_model,a_path,
  76. path_currently_selected.to_boolean]).to_integer)
  77. end
  78. function: FUNCTION[ANY,TUPLE[GTK_TREE_SELECTION, GTK_TREE_MODEL, GTK_TREE_PATH, BOOLEAN],BOOLEAN]
  79. end