/src/wrappers/gtk/library/gtk_tree_path.e

http://github.com/tybor/Liberty · Specman e · 237 lines · 144 code · 38 blank · 55 comment · 2 complexity · df4a7a8c80be531eba207b2530f5d455 MD5 · raw file

  1. indexing
  2. description: "GTK_TREE_PATH, an object referring to a row."
  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_PATH
  21. inherit
  22. C_STRUCT undefine free redefine copy end
  23. EIFFEL_OWNED undefine free end
  24. insert
  25. GTK
  26. GTK_TREE_MODEL_EXTERNALS
  27. rename gtk_tree_path_free as free
  28. end
  29. creation
  30. make, make_first, copy_from_pointer,
  31. from_string, first, from_path, from_external_pointer
  32. feature {} -- Creation
  33. make is
  34. -- Creates a new GtkTreePath. This structure refers to a row.
  35. require gtk_initialized: gtk.is_initialized
  36. do
  37. handle := gtk_tree_path_new
  38. end
  39. copy_from_pointer (a_ptr: POINTER) is
  40. require
  41. a_ptr.is_not_null
  42. do
  43. handle := gtk_tree_path_copy (a_ptr)
  44. end
  45. from_string (a_path: STRING) is
  46. -- Creates a new GtkTreePath initialized to
  47. -- `a_path'. `a_path' is expected to be a colon separated
  48. -- list of numbers. For example, the string "10:4:0" would
  49. -- create a path of depth 3 pointing to the 11th child of the
  50. -- root node, the 5th child of that 11th child, and the 1st
  51. -- child of that 5th child. If an invalid path string is
  52. -- passed in, this object will "is_null" (i.e. is_null = True)
  53. require
  54. gtk_initialized: gtk.is_initialized
  55. path_not_void: a_path /= Void
  56. do
  57. handle := gtk_tree_path_new_from_string (a_path.to_external)
  58. end
  59. -- unwrappable varargs function GtkTreePath*
  60. -- gtk_tree_path_new_from_indices (gint first_index, ...); Creates
  61. -- a new path with first_index and varargs as indices. first_index
  62. -- : first integer ... : list of integers terminated by -1 Returns
  63. -- : A newly created GtkTreePath.
  64. make_first, first is
  65. -- Creates a new GtkTreePath. The string representation of
  66. -- this path is "0"
  67. require gtk_initialized: gtk.is_initialized
  68. do
  69. handle := gtk_tree_path_new_first
  70. end
  71. from_path (a_path: like Current) is
  72. -- Creates a new GtkTreePath as a copy of path.
  73. require gtk_initialized: gtk.is_initialized
  74. do
  75. handle := gtk_tree_path_copy (a_path.handle)
  76. end
  77. feature
  78. copy (a_path: like Current) is
  79. -- Makes Current a copy of `a_path'.
  80. do
  81. from_external_pointer (gtk_tree_path_copy (a_path.handle))
  82. end
  83. to_string: STRING is
  84. -- Generates a string representation of the path. This string
  85. -- is a ':' separated list of numbers. For example,
  86. -- "4:10:0:3" would be an acceptable return value for this
  87. -- string.
  88. require is_not_null
  89. do
  90. create Result.from_external (gtk_tree_path_to_string (handle))
  91. -- gtk_tree_path_to_string returns a newly-allocated
  92. -- string. Must be freed with g_free(). TODO: check if STRING
  93. -- calling just free() is a problem.
  94. end
  95. append_index (an_index: INTEGER) is
  96. -- Appends a new index to a path. As a result, the depth of
  97. -- the path is increased.
  98. do
  99. gtk_tree_path_append_index (handle, an_index)
  100. ensure depth_increased: depth > old depth
  101. end
  102. prepend_index (an_index: INTEGER) is
  103. -- Prepends a new index to a path. As a result, the depth of
  104. -- the path is increased.
  105. do
  106. gtk_tree_path_prepend_index (handle, an_index)
  107. ensure depth_increased: depth > old depth
  108. end
  109. depth: INTEGER is
  110. -- the current depth of path.
  111. require
  112. is_not_null
  113. do
  114. Result:=gtk_tree_path_get_depth(handle)
  115. end
  116. indices: COLLECTION[INTEGER_32] is
  117. -- the current indices of path. This is an array of integers,
  118. -- each representing a node in a tree.
  119. -- Note: currently implemented as a FAST_ARRAY
  120. -- Note: it couldn't be an ARRAYED_COLLECTION in SE 2.3/svn
  121. -- since FAST_ARRAY is a non-conforming heir (i.e. inserts)
  122. -- ARRAYED_COLLECTION.
  123. local
  124. c_array: NATIVE_ARRAY [INTEGER_32]; i: INTEGER_32
  125. do
  126. -- The following seems an hack. Indeed it's the "normal" way
  127. -- to create a NATIVE_ARRAY from a C pointer to that array
  128. c_array := c_array.from_pointer (gtk_tree_path_get_indices (handle))
  129. -- i.e.: "10:4:0" would create a path of depth 3 pointing to
  130. -- the 11th child of the root node, the 5th child of that
  131. -- 11th child, and the 1st child of that 5th child.
  132. create {FAST_ARRAY[INTEGER_32]} Result.make (depth)
  133. from i := 0 until i >= depth loop
  134. Result.put (c_array.item (i), i)
  135. i := i + 1
  136. end
  137. ensure
  138. result_not_void: Result /= Void
  139. correct_result_count: Result.count = depth
  140. end
  141. feature -- Disposing
  142. feature -- Comparing
  143. compare (another: like Current): INTEGER is
  144. -- Compares two paths. If Current appears before `another' in a tree, then
  145. -- -1 is returned. If `another' appears before Current, then 1 is
  146. -- returned. If the two nodes are equal, then 0 is returned.
  147. require
  148. exists: is_not_null
  149. valid_another: another /= Void implies another.is_not_null
  150. do
  151. Result:= gtk_tree_path_compare (handle, another.handle)
  152. end
  153. feature -- Moving
  154. next is
  155. -- Moves the path to point to the next node at the current depth.
  156. do
  157. gtk_tree_path_next (handle)
  158. end
  159. is_move_made: BOOLEAN
  160. -- Has last command actually moved Current?
  161. prev is
  162. -- Moves the path to point to the previous node at the
  163. -- current depth, if it exists. `is_move_made' is True if
  164. -- path has a previous node, and the move was made.
  165. do
  166. is_move_made := (gtk_tree_path_prev (handle)).to_boolean
  167. end
  168. up is
  169. -- Moves the path to point to its parent node, if it has a
  170. -- parent. `is_move_made' is True if path has a parent, and
  171. -- the move was made.
  172. do
  173. is_move_made := (gtk_tree_path_up (handle)).to_boolean
  174. end
  175. down is
  176. -- Moves path to point to the first child of the current
  177. -- path.
  178. do
  179. gtk_tree_path_down (handle)
  180. end
  181. feature -- Queries
  182. is_ancestor_of (another: GTK_TREE_PATH): BOOLEAN is
  183. -- Is `another' a descendant of Current path?
  184. require another_not_void: another /= Void
  185. do
  186. Result := (gtk_tree_path_is_ancestor (handle,another.handle)).to_boolean
  187. end
  188. is_descendant_of (another: GTK_TREE_PATH): BOOLEAN is
  189. -- IS Current path is a descendant of `another'?
  190. require another_not_void: another /= Void
  191. do
  192. Result := (gtk_tree_path_is_descendant (handle,another.handle)).to_boolean
  193. end
  194. feature -- struct size
  195. struct_size: INTEGER is
  196. external "C inline use <gtk/gtk.h>"
  197. alias "sizeof(GtkTreePath)"
  198. end
  199. end