/[eiffelstudio]/branches/eth/eve/Src/library/vision2/implementation/gtk/widgets/containers/ev_notebook_imp.e
ViewVC logotype

Contents of /branches/eth/eve/Src/library/vision2/implementation/gtk/widgets/containers/ev_notebook_imp.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86783 - (show annotations)
Fri Jun 24 10:21:15 2011 UTC (8 years, 8 months ago) by jasonw
File size: 10716 byte(s)
<<Merged from trunk#86782.>>
1 note
2 description:
3 "Eiffel Vision notebook. GTK implementation."
4 legal: "See notice at end of class."
5 status: "See notice at end of class."
6 date: "$Date$"
7 revision: "$Revision$"
8
9 class
10 EV_NOTEBOOK_IMP
11
12 inherit
13 EV_NOTEBOOK_I
14 undefine
15 propagate_foreground_color,
16 propagate_background_color
17 redefine
18 interface,
19 replace
20 end
21
22 EV_WIDGET_LIST_IMP
23 redefine
24 interface,
25 replace,
26 make,
27 remove_i_th,
28 needs_event_box
29 end
30
31 EV_FONTABLE_IMP
32 redefine
33 interface
34 end
35
36 EV_NOTEBOOK_ACTION_SEQUENCES_IMP
37
38 create
39 make
40
41 feature {NONE} -- Initialization
42
43 needs_event_box: BOOLEAN
44 -- Does `a_widget' need an event box?
45 do
46 Result := True
47 end
48
49 old_make (an_interface: like interface)
50 -- Create a fixed widget.
51 do
52 assign_interface (an_interface)
53 end
54
55 make
56 -- Initialize the notebook.
57 do
58 set_c_object ({GTK}.gtk_notebook_new ())
59 {GTK}.gtk_notebook_set_show_border (visual_widget, True)
60 {GTK}.gtk_notebook_set_scrollable (visual_widget, True)
61 real_signal_connect (visual_widget, "switch-page", agent (App_implementation.gtk_marshal).on_notebook_page_switch_intermediary (c_object, ?), agent (App_implementation.gtk_marshal).page_switch_translate)
62 Precursor {EV_WIDGET_LIST_IMP}
63 selected_item_index_internal := 0
64 initialize_pixmaps
65 end
66
67 feature -- Access
68
69 pointed_tab_index: INTEGER
70 -- index of tab currently under mouse pointer, or 0 if none.
71 local
72 i: INTEGER
73 gdkwin, mouse_ptr_wid, tab_label: POINTER
74 a_wid: detachable EV_WIDGET_IMP
75 do
76 from
77 i := 1
78 gdkwin := {GTK}.gdk_window_at_pointer (default_pointer, default_pointer)
79 if gdkwin /= default_pointer then
80 {GTK}.gdk_window_get_user_data (gdkwin, $mouse_ptr_wid)
81 a_wid ?= eif_object_from_c (mouse_ptr_wid)
82 end
83 until
84 Result > 0 or else i > count or else mouse_ptr_wid = default_pointer
85 loop
86 a_wid ?= interface_i_th (i).implementation
87 check a_wid /= Void end
88 tab_label := {GTK}.gtk_notebook_get_tab_label (visual_widget, a_wid.c_object)
89 if mouse_ptr_wid = tab_label or else mouse_ptr_wid = {GTK}.gtk_widget_struct_parent (mouse_ptr_wid) then
90 Result := i
91 end
92 i := i + 1
93 end
94 end
95
96 pixmaps_size_changed
97 -- The size of the displayed pixmaps has just
98 -- changed.
99 do
100 --| FIXME IEK Implement this
101 end
102
103 feature {EV_NOTEBOOK, EV_NOTEBOOK_TAB_IMP} -- Access
104
105 item_tab (an_item: EV_WIDGET): EV_NOTEBOOK_TAB
106 -- Tab associated with `an_item'.
107 do
108 create Result.make_with_widgets (attached_interface, an_item)
109 end
110
111 item_text (an_item: like item): STRING_32
112 -- Label of `an_item'.
113 local
114 item_imp: detachable EV_WIDGET_IMP
115 a_event_box, a_hbox, a_list, a_label: POINTER
116 a_cs: EV_GTK_C_STRING
117 do
118 item_imp ?= an_item.implementation
119 check item_imp /= Void end
120 a_event_box := {GTK}.gtk_notebook_get_tab_label (visual_widget, item_imp.c_object)
121 if a_event_box /= default_pointer then
122 a_hbox := {GTK}.gtk_bin_struct_child (a_event_box)
123 a_list := {GTK}.gtk_container_children (a_hbox)
124 a_label := {GTK}.g_list_nth_data (a_list, 1)
125 {GTK}.g_list_free (a_list)
126 end
127
128 if a_label /= default_pointer then
129 create a_cs.share_from_pointer ({GTK}.gtk_label_struct_label (
130 a_label
131 ))
132 Result := a_cs.string
133 else
134 Result := ""
135 end
136 end
137
138 item_pixmap (an_item: attached like item): detachable EV_PIXMAP
139 -- Pixmap of `an_item'.
140 local
141 item_imp: detachable EV_WIDGET_IMP
142 a_event_box, a_hbox, a_list, a_image, a_pixbuf: POINTER
143 pix_imp: detachable EV_PIXMAP_IMP
144 do
145 item_imp ?= an_item.implementation
146 check item_imp /= Void end
147 a_event_box := {GTK}.gtk_notebook_get_tab_label (visual_widget, item_imp.c_object)
148 if a_event_box /= default_pointer then
149 a_hbox := {GTK}.gtk_bin_struct_child (a_event_box)
150 a_list := {GTK}.gtk_container_children (a_hbox)
151 a_image := {GTK}.g_list_nth_data (a_list, 0)
152 {GTK}.g_list_free (a_list)
153 a_pixbuf := {GTK2}.gtk_image_get_pixbuf (a_image)
154 if a_pixbuf /= default_pointer then
155 create Result
156 pix_imp ?= Result.implementation
157 check pix_imp /= Void end
158 pix_imp.set_pixmap_from_pixbuf (a_pixbuf)
159 end
160 end
161 end
162
163 feature -- Status report
164
165 selected_item: like item
166 -- Page displayed topmost.
167 local
168 p: POINTER
169 pn: INTEGER
170 imp: detachable EV_WIDGET_IMP
171 do
172 if count > 0 then
173 pn := selected_item_index_internal - 1
174 p := {GTK}.gtk_notebook_get_nth_page (
175 visual_widget,
176 pn
177 )
178 imp ?= eif_object_from_c (p)
179 check imp /= Void end
180 Result ?= imp.interface
181 end
182 end
183
184 selected_item_index: INTEGER
185 -- Page index of selected item
186 do
187 if count > 0 then
188 Result := selected_item_index_internal
189 end
190 end
191
192 tab_position: INTEGER
193 -- Position of tabs.
194 local
195 gtk_pos: INTEGER
196 do
197 gtk_pos := {GTK}.gtk_notebook_struct_tab_pos (visual_widget)
198 inspect
199 gtk_pos
200 when 0 then
201 Result := attached_interface.Tab_left
202 when 1 then
203 Result := attached_interface.Tab_right
204 when 2 then
205 Result := attached_interface.Tab_top
206 when 3 then
207 Result := attached_interface.Tab_bottom
208 end
209 end
210
211 feature {EV_NOTEBOOK} -- Status setting
212
213 set_tab_position (a_tab_position: INTEGER)
214 -- Display tabs at `a_position'.
215 local
216 gtk_pos: INTEGER
217 do
218 if a_tab_position = attached_interface.Tab_left then
219 gtk_pos := 0
220 elseif a_tab_position = attached_interface.Tab_right then
221 gtk_pos := 1
222 elseif a_tab_position = attached_interface.Tab_top then
223 gtk_pos := 2
224 elseif a_tab_position = attached_interface.Tab_bottom then
225 gtk_pos := 3
226 end
227 {GTK}.gtk_notebook_set_tab_pos (visual_widget, gtk_pos)
228 end
229
230 select_item (an_item: like item)
231 -- Display `an_item' above all others.
232 local
233 item_imp: detachable EV_WIDGET_IMP
234 do
235 item_imp ?= an_item.implementation
236 check
237 an_item_has_implementation: item_imp /= Void
238 end
239 {GTK}.gtk_notebook_set_page (
240 visual_widget,
241 {GTK}.gtk_notebook_page_num (visual_widget, item_imp.c_object)
242 )
243 end
244
245 feature -- Element change
246
247 remove_i_th (i: INTEGER)
248 -- Remove item at `i'-th position.
249 do
250 Precursor {EV_WIDGET_LIST_IMP} (i)
251 if count > 0 then
252 selected_item_index_internal := {GTK}.gtk_notebook_get_current_page (visual_widget) + 1
253 else
254 selected_item_index_internal := 0
255 end
256 end
257
258 replace (v: attached like item)
259 -- Replace current item by `v'.
260 local
261 i: INTEGER
262 do
263 i := {GTK}.gtk_notebook_get_current_page (visual_widget)
264 remove_i_th (index)
265 insert_i_th (v, index)
266 {GTK}.gtk_notebook_set_page (visual_widget, i)
267 end
268
269 feature {EV_NOTEBOOK, EV_NOTEBOOK_TAB_IMP} -- Element change
270
271 ensure_tab_label (tab_widget: POINTER)
272 -- Ensure the is a tab label widget for `tab_widget'.
273 local
274 a_event_box, a_hbox, a_image, a_label: POINTER
275 do
276 if {GTK}.gtk_notebook_get_tab_label (visual_widget, tab_widget) = default_pointer then
277 a_event_box := {GTK}.gtk_event_box_new
278 {GTK2}.gtk_event_box_set_visible_window (a_event_box, False)
279 {GTK}.gtk_widget_show (a_event_box)
280 a_hbox := {GTK}.gtk_hbox_new (False, default_tab_label_spacing)
281 {GTK}.gtk_container_add (a_event_box, a_hbox)
282 {GTK}.gtk_widget_show (a_hbox)
283 a_image := {GTK2}.gtk_image_new
284 {GTK}.gtk_widget_show (a_image)
285 {GTK}.gtk_container_add (a_hbox, a_image)
286 a_label := {GTK}.gtk_label_new (default_pointer)
287 {GTK}.gtk_widget_show (a_label)
288 {GTK}.gtk_container_add (a_hbox, a_label)
289 {GTK}.gtk_notebook_set_tab_label (visual_widget, tab_widget, a_event_box)
290 end
291 end
292
293 default_tab_label_spacing: INTEGER = 2
294 -- Space between pixmap and text in the tab label.
295
296 set_item_text (an_item: like item; a_text: READABLE_STRING_GENERAL)
297 -- Assign `a_text' to the label for `an_item'.
298 local
299 item_imp: detachable EV_WIDGET_IMP
300 a_cs: EV_GTK_C_STRING
301 a_event_box, a_hbox, a_list, a_label: POINTER
302 do
303 item_imp ?= an_item.implementation
304 check item_imp /= Void end
305 a_cs := a_text
306 ensure_tab_label (item_imp.c_object)
307 a_event_box := {GTK}.gtk_notebook_get_tab_label (visual_widget, item_imp.c_object)
308 a_hbox := {GTK}.gtk_bin_struct_child (a_event_box)
309 a_list := {GTK}.gtk_container_children (a_hbox)
310 a_label := {GTK}.g_list_nth_data (a_list, 1)
311 {GTK}.gtk_label_set_text (a_label, a_cs.item)
312 {GTK}.g_list_free (a_list)
313 end
314
315 set_item_pixmap (an_item: attached like item; a_pixmap: detachable EV_PIXMAP)
316 -- Assign `a_pixmap' to the tab for `an_item'.
317 local
318 item_imp: detachable EV_WIDGET_IMP
319 a_event_box, a_hbox, a_image, a_list, a_pixbuf: POINTER
320 a_pix_imp: detachable EV_PIXMAP_IMP
321 do
322 item_imp ?= an_item.implementation
323 check item_imp /= Void end
324 ensure_tab_label (item_imp.c_object)
325 a_event_box := {GTK}.gtk_notebook_get_tab_label (visual_widget, item_imp.c_object)
326 a_hbox := {GTK}.gtk_bin_struct_child (a_event_box)
327
328 a_list := {GTK}.gtk_container_children (a_hbox)
329 a_image := {GTK}.g_list_nth_data (a_list, 0)
330 {GTK}.g_list_free (a_list)
331
332 if a_pixmap /= Void then
333 a_pix_imp ?= a_pixmap.implementation
334 check a_pix_imp /= Void end
335 a_pixbuf := a_pix_imp.pixbuf_from_drawable_with_size (pixmaps_width, pixmaps_height)
336 {GTK2}.gtk_image_set_from_pixbuf (a_image, a_pixbuf)
337 else
338 {GTK2}.gtk_image_set_from_pixbuf (a_image, default_pointer)
339 end
340 end
341
342 feature {EV_INTERMEDIARY_ROUTINES} -- Implementation
343
344 page_switch (a_page: INTEGER)
345 -- Called when the page is switched.
346 do
347 if not is_destroyed then
348 selected_item_index_internal := a_page + 1
349 if selection_actions_internal /= Void and count > 0 then
350 selection_actions_internal.call (Void)
351 end
352 end
353 end
354
355 feature {EV_ANY_I} -- Implementation
356
357 selected_item_index_internal: INTEGER
358 -- Index `selected_item'
359
360 gtk_insert_i_th (a_container, a_child: POINTER; a_position: INTEGER)
361 -- Move `a_child' to `a_position' in `a_container'.
362 do
363 {GTK}.gtk_container_add (a_container, a_child)
364 if a_position < count then
365 {GTK}.gtk_notebook_reorder_child (a_container, a_child, a_position)
366 end
367 end
368
369 feature {EV_ANY_I, EV_ANY} -- Implementation
370
371 interface: detachable EV_NOTEBOOK note option: stable attribute end;
372 -- Provides a common user interface to platform dependent
373 -- functionality implemented by `Current'
374
375 note
376 copyright: "Copyright (c) 1984-2006, Eiffel Software and others"
377 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
378 source: "[
379 Eiffel Software
380 356 Storke Road, Goleta, CA 93117 USA
381 Telephone 805-685-1006, Fax 805-685-6869
382 Website http://www.eiffel.com
383 Customer support http://support.eiffel.com
384 ]"
385
386
387
388
389 end -- class EV_NOTEBOOK_IMP
390
391
392
393
394
395
396
397
398
399
400

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23