PageRenderTime 23ms CodeModel.GetById 19ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1indexing
  2	description: "GTK_TREE_PATH, an object referring to a row."
  3	copyright: "[
  4					Copyright (C) 2006 eiffel-libraries team, GTK+ team
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hope that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20					]"
 21	date: "$Date:$"
 22	revision: "$Revision:$"
 23
 24class GTK_TREE_PATH
 25
 26inherit 
 27	C_STRUCT undefine free redefine copy end
 28	EIFFEL_OWNED undefine free end
 29
 30insert
 31	GTK
 32	GTK_TREE_MODEL_EXTERNALS 
 33		rename gtk_tree_path_free as free
 34		end
 35
 36creation
 37	make, make_first, copy_from_pointer,
 38	from_string, first, from_path, from_external_pointer
 39
 40feature {} -- Creation
 41
 42	make is
 43			-- Creates a new GtkTreePath. This structure refers to a row.
 44		require gtk_initialized: gtk.is_initialized
 45		do
 46			handle := gtk_tree_path_new
 47		end
 48
 49	copy_from_pointer (a_ptr: POINTER) is
 50		require
 51			a_ptr.is_not_null
 52		do
 53			handle := gtk_tree_path_copy (a_ptr)
 54		end
 55
 56	from_string (a_path: STRING) is
 57			-- Creates a new GtkTreePath initialized to
 58			-- `a_path'. `a_path' is expected to be a colon separated
 59			-- list of numbers. For example, the string "10:4:0" would
 60			-- create a path of depth 3 pointing to the 11th child of the
 61			-- root node, the 5th child of that 11th child, and the 1st
 62			-- child of that 5th child. If an invalid path string is
 63			-- passed in, this object will "is_null" (i.e. is_null = True)
 64		require
 65			gtk_initialized: gtk.is_initialized
 66			path_not_void: a_path /= Void
 67		do
 68			handle := gtk_tree_path_new_from_string (a_path.to_external)
 69		end
 70
 71	-- unwrappable varargs function GtkTreePath*
 72	-- gtk_tree_path_new_from_indices (gint first_index, ...); Creates
 73	-- a new path with first_index and varargs as indices.  first_index
 74	-- : first integer ... : list of integers terminated by -1 Returns
 75	-- : A newly created GtkTreePath.
 76
 77	make_first, first is
 78			-- Creates a new GtkTreePath. The string representation of
 79			-- this path is "0"
 80		require gtk_initialized: gtk.is_initialized
 81		do
 82			handle := gtk_tree_path_new_first
 83		end
 84
 85	from_path (a_path: like Current) is
 86			-- Creates a new GtkTreePath as a copy of path.
 87		require gtk_initialized: gtk.is_initialized
 88		do
 89			handle := gtk_tree_path_copy (a_path.handle)
 90		end
 91
 92feature
 93
 94	copy (a_path: like Current) is
 95			-- Makes Current a copy of `a_path'.
 96		do
 97			from_external_pointer (gtk_tree_path_copy (a_path.handle))
 98		end
 99
100	to_string: STRING is
101			-- Generates a string representation of the path. This string
102			-- is a ':' separated list of numbers. For example,
103			-- "4:10:0:3" would be an acceptable return value for this
104			-- string.
105		require is_not_null
106		do
107			create Result.from_external (gtk_tree_path_to_string (handle))
108			-- gtk_tree_path_to_string returns a newly-allocated
109			-- string. Must be freed with g_free(). TODO: check if STRING
110			-- calling just free() is a problem.
111		end
112
113	append_index (an_index: INTEGER) is
114			-- Appends a new index to a path. As a result, the depth of
115			-- the path is increased.
116		do
117			gtk_tree_path_append_index (handle, an_index)
118		ensure depth_increased: depth > old depth
119		end
120
121	prepend_index (an_index: INTEGER) is
122			-- Prepends a new index to a path. As a result, the depth of
123			-- the path is increased.
124		do
125			gtk_tree_path_prepend_index (handle, an_index)
126		ensure depth_increased: depth > old depth
127		end
128
129	depth: INTEGER is
130			-- the current depth of path.
131		require
132			is_not_null
133		do
134			Result:=gtk_tree_path_get_depth(handle)
135		end
136
137	indices: COLLECTION[INTEGER_32] is
138			-- the current indices of path. This is an array of integers,
139			-- each representing a node in a tree.
140			
141			-- Note: currently implemented as a FAST_ARRAY
142
143			-- Note: it couldn't be an ARRAYED_COLLECTION in SE 2.3/svn
144			-- since FAST_ARRAY is a non-conforming heir (i.e. inserts)
145			-- ARRAYED_COLLECTION.
146		local
147			c_array: NATIVE_ARRAY [INTEGER_32]; i: INTEGER_32
148		do
149			-- The following seems an hack. Indeed it's the "normal" way
150			-- to create a NATIVE_ARRAY from a C pointer to that array
151			c_array := c_array.from_pointer (gtk_tree_path_get_indices (handle))
152
153			-- i.e.: "10:4:0" would create a path of depth 3 pointing to
154			-- the 11th child of the root node, the 5th child of that
155			-- 11th child, and the 1st child of that 5th child.
156			create {FAST_ARRAY[INTEGER_32]} Result.make (depth)
157			from i := 0 until i >= depth loop
158				Result.put (c_array.item (i), i)
159				i := i + 1
160			end
161		ensure
162			result_not_void: Result /= Void
163			correct_result_count: Result.count = depth
164		end
165
166feature -- Disposing
167
168
169feature -- Comparing
170
171	compare (another: like Current): INTEGER is
172			-- Compares two paths. If Current appears before `another' in a tree, then
173			-- -1 is returned. If `another' appears before Current, then 1 is
174			-- returned. If the two nodes are equal, then 0 is returned.
175		require
176			exists: is_not_null
177			valid_another: another /= Void implies another.is_not_null
178		do
179			Result:= gtk_tree_path_compare (handle, another.handle)
180		end
181
182feature -- Moving
183
184	next is
185			-- Moves the path to point to the next node at the current depth.
186		do
187			gtk_tree_path_next (handle)
188		end
189
190	is_move_made: BOOLEAN
191			-- Has last command actually moved Current?
192
193	prev is
194			-- Moves the path to point to the previous node at the
195			-- current depth, if it exists. `is_move_made' is True if
196			-- path has a previous node, and the move was made.
197		do
198			is_move_made := (gtk_tree_path_prev (handle)).to_boolean
199		end
200
201	up is
202			-- Moves the path to point to its parent node, if it has a
203			-- parent. `is_move_made' is True if path has a parent, and
204			-- the move was made.
205		do
206			is_move_made := (gtk_tree_path_up (handle)).to_boolean
207		end
208
209	down is
210			-- Moves path to point to the first child of the current
211			-- path.
212		do
213			gtk_tree_path_down (handle)
214		end
215
216feature -- Queries
217
218	is_ancestor_of (another: GTK_TREE_PATH): BOOLEAN is
219			-- Is `another' a descendant of Current path?
220		require another_not_void: another /= Void
221		do
222			Result := (gtk_tree_path_is_ancestor (handle,another.handle)).to_boolean
223		end
224
225	is_descendant_of (another: GTK_TREE_PATH): BOOLEAN is
226			-- IS Current  path is a descendant of `another'?
227		require another_not_void: another /= Void
228		do
229			Result := (gtk_tree_path_is_descendant (handle,another.handle)).to_boolean
230		end
231	
232feature  -- struct size
233	struct_size: INTEGER is
234		external "C inline use <gtk/gtk.h>"
235		alias "sizeof(GtkTreePath)"
236		end
237end