/[eiffelstudio]/trunk/Src/Eiffel/interface/new_graphical/shared/editor_token_utility/eb_grid_editor_token_item.e
ViewVC logotype

Annotation of /trunk/Src/Eiffel/interface/new_graphical/shared/editor_token_utility/eb_grid_editor_token_item.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 71346 - (hide annotations)
Mon Dec 3 19:25:51 2007 UTC (12 years, 2 months ago) by paulb
File size: 24768 byte(s)
Supported optional selection exclusion for EB_GRID_EDITOR_TOKEN_ITEM to mirror that of the same functionality in EV_GRID_LABEL_ITEM.
Supported setting of selection background colors on EB_EDITOR_TOKEN_TEXT.
Updated the error list (and base implementation) tool to set correct grid selection colors and to disable selection for non applicable areas.
Error list is now-multiple select.
1 jasonw 58940 indexing
2     description: "Object that represents a grid item in which pick-and-dropable editor tokens are displayed"
3     legal: "See notice at end of class."
4     status: "See notice at end of class."
5     author: ""
6     date: "$Date$"
7     revision: "$Revision$"
8    
9     class
10     EB_GRID_EDITOR_TOKEN_ITEM
11    
12     inherit
13     EV_GRID_DRAWABLE_ITEM
14     redefine
15     initialize
16     end
17    
18 jasonw 59134 EB_SHARED_PREFERENCES
19     undefine
20     copy,
21     is_equal,
22     default_create
23     end
24    
25 jasonw 62470 EB_SHARED_WRITER
26     undefine
27     copy,
28     is_equal,
29     default_create
30     end
31    
32 jasonw 66722 ES_GRID_LISTABLE_ITEM
33 jasonw 65825 undefine
34     copy,
35     is_equal,
36     default_create
37 jasonw 66722 redefine
38     set_last_picked_item,
39     required_component_width
40 jasonw 65825 end
41    
42 jasonw 66557 EVS_GRID_SEARCHABLE_ITEM
43     undefine
44     copy,
45     is_equal,
46     default_create
47     end
48    
49 jasonw 58940 create
50     default_create,
51     make_with_text
52    
53     feature{NONE} -- Initialization
54    
55     make_with_text (a_text: STRING) is
56     -- Create `Current' and assign `a_text' to `text'
57     require
58     a_text_attached: a_text /= Void
59     do
60     default_create
61     set_text (a_text)
62     ensure
63     text_set: text.is_equal (a_text)
64     end
65    
66     initialize is
67     do
68     align_text_left
69     align_text_vertically_center
70     set_left_border (1)
71     set_right_border (1)
72     set_top_border (1)
73     set_bottom_border (1)
74 jasonw 65142 set_spacing (2)
75 paulb 71346 enable_full_select
76 jasonw 58940 expose_actions.extend (agent perform_redraw)
77     setting_change_actions.extend (agent safe_redraw)
78 jasonw 66722 initialize_item
79 jasonw 58940 Precursor
80     end
81    
82 jasonw 65741 feature -- Access
83    
84     pixmap: EV_PIXMAP
85     -- Image displayed to left of `tokens'.
86    
87     spacing: INTEGER
88     -- Spacing between `text' and `pixmap' in pixels.
89     -- If both are not visible, this value does not affect appearance of `Current'.
90    
91     text: STRING is
92     -- Text of current item.
93     do
94     Result := editor_token_text.string_representation
95     ensure
96     result_attached: Result /= Void
97     end
98    
99 jasonw 66565 stone: STONE is
100     -- Stone attached to Current item
101     -- Result `stone_internal' if `stone_function' is not set,
102 jasonw 69018 -- otherwise invoke `stone_function' to get the actual stone.
103 jasonw 66565 do
104     if stone_function = Void then
105     Result := stone_internal
106     else
107 jasonw 66834 Result := stone_function.item (Void)
108 jasonw 66565 end
109     end
110    
111     stone_function: FUNCTION [ANY, TUPLE, STONE]
112     -- Function to fetch `stone'.
113    
114 jasonw 66722 component_spacing: INTEGER
115     -- Space in pixel between text and the first trailer
116    
117 jasonw 68146 pebble_at_position: ANY is
118     -- Pebble at pointer position
119     -- Void if no pebble found at that position
120     local
121     l_index: INTEGER
122     l_component: like component
123     l_pos: EV_RECTANGLE
124     l_left_corner: EV_COORDINATE
125     do
126     l_index := token_index_at_current_position
127     if l_index > 0 then
128     Result ?= editor_token_pebble (l_index)
129     else
130     l_index := component_index_at_pointer_position
131     if l_index > 0 and then l_index <= component_position.count and then l_index <= component_count then
132     l_component := component (l_index)
133     l_pos := component_position.i_th (l_index)
134     l_left_corner := relative_pointer_position (Current)
135     Result := l_component.pebble_at_position (l_pos.x - l_left_corner.x, l_pos.y - l_left_corner.y)
136     end
137     end
138     end
139    
140 jasonw 65741 feature -- Status report
141    
142 paulb 71346 is_full_select_enabled: BOOLEAN
143     -- Does selection highlighting fill complete area of `Current'?
144     -- If `False', highlighting is only applied to area of `text'.
145    
146 jasonw 66722 is_component_adhesive_enabled: BOOLEAN
147     -- Is component adhesive?
148     -- component is adhesive means component appears right after text.
149     -- For example, following is a grid item with non-adhesive component:
150 jasonw 65741 -- +--------------------------------+
151 jasonw 66722 -- | Text component|
152 jasonw 65741 -- +--------------------------------+
153 jasonw 66722 -- And following is a grid item with adhesive component:
154 jasonw 65741 -- +--------------------------------+
155 jasonw 66722 -- | Text component |
156 jasonw 65741 -- +--------------------------------+
157    
158 jasonw 66722 is_component_display_ensured: BOOLEAN
159     -- Is display of `components' ensured?
160     -- A True value means that text wil be truncated first to ensure that all (or most) part of `components'
161 jasonw 65741 -- can be displayed. A False value means that we first ensure that text is displayed mostly.
162    
163     is_text_display_ensured: BOOLEAN is
164     -- Is display of `editor_token_text' ensured?
165 jasonw 66722 -- A True value means that all or most part of text in `editor_token_text' will be display first, and then `components'.
166     -- A False value means we try to display `components' first.
167 jasonw 65741 do
168 jasonw 66722 Result := not is_component_display_ensured
169 jasonw 65741 ensure
170 jasonw 66722 good_result: Result = not is_component_display_ensured
171 jasonw 65741 end
172    
173     is_text_truncated: BOOLEAN is
174     -- Was text of current truncated because of lack of space the last time when it is displayed?
175     do
176     Result := editor_token_text.is_text_truncated
177     end
178    
179 jasonw 58940 feature -- Setting
180    
181 paulb 71346 enable_full_select
182     -- Ensure `is_full_select_enabled' is `True'.
183     do
184     lock_update
185     is_full_select_enabled := True
186     unlock_update
187     try_call_setting_change_actions
188     ensure
189     is_full_select_enabled: is_full_select_enabled
190     end
191    
192     disable_full_select
193     -- Ensure `is_full_select_enabled' is `False'.
194     do
195     lock_update
196     is_full_select_enabled := False
197     unlock_update
198     try_call_setting_change_actions
199     ensure
200     not_is_full_select_enabled: not is_full_select_enabled
201     end
202    
203 jasonw 58940 set_pixmap (a_pixmap: EV_PIXMAP) is
204     -- Display image of `a_pixmap' on `Current'.
205     require
206     not_destroyed: not is_destroyed
207     pixmap_not_void: a_pixmap /= Void
208     do
209     lock_update
210     pixmap := a_pixmap
211     unlock_update
212     try_call_setting_change_actions
213     ensure
214     pixmap_set: pixmap = a_pixmap
215     end
216    
217     remove_pixmap is
218     -- Remove image displayed on `Current'.
219     require
220     not_destroyed: not is_destroyed
221     do
222     lock_update
223     pixmap := Void
224     unlock_update
225     try_call_setting_change_actions
226     ensure
227     pixmap_removed: pixmap = Void
228     end
229    
230     set_spacing (a_spacing: INTEGER) is
231     -- Assign `a_spacing' to `spacing'.
232     require
233     not_destroyed: not is_destroyed
234     a_spacing_non_negative: a_spacing >= 0
235     do
236     lock_update
237     spacing := a_spacing
238     unlock_update
239     try_call_setting_change_actions
240     ensure
241     spacing_set: spacing = a_spacing
242     end
243    
244     set_text_with_tokens (a_tokens: LIST [EDITOR_TOKEN]) is
245     -- Set `tokens' with `a_tokens'.
246     do
247     lock_update
248     if a_tokens = Void or else a_tokens.is_empty then
249     editor_token_text.set_tokens (create{ARRAYED_LIST [EDITOR_TOKEN]}.make (0))
250     else
251     editor_token_text.set_tokens (a_tokens)
252     end
253     unlock_update
254     try_call_setting_change_actions
255     end
256    
257     set_text (a_text: STRING) is
258     -- Set `text' with `a_text'.
259     require
260     a_text_attached: a_text /= Void
261     local
262     l_writer: like token_writer
263     do
264     lock_update
265     l_writer := token_writer
266     l_writer.new_line
267     l_writer.add (a_text)
268     set_text_with_tokens (l_writer.last_line.content)
269     unlock_update
270     try_call_setting_change_actions
271     ensure
272     text_set: text.is_equal (a_text)
273     end
274    
275 paulb 69723 set_text_wrap (a_wrap: BOOLEAN) is
276     -- If `a_wrap' is True, enable text wrap, otherwise disable text wrap.
277     do
278     if a_wrap then
279     editor_token_text.enable_text_wrap
280     else
281     editor_token_text.disable_text_wrap
282     end
283     ensure
284     text_wrap_set: editor_token_text.is_text_wrap_enabled = a_wrap
285     end
286    
287 jasonw 69018 set_overriden_fonts (a_fonts: SPECIAL [EV_FONT]; a_height: INTEGER) is
288     -- Set fonts of current tokens with `a_fonts' and according height.
289 jasonw 59908 -- If `a_fonts' is Void, tokens will be displayed in default editor token fonts.
290     do
291     lock_update
292 jasonw 69018 editor_token_text.set_overriden_font (a_fonts, a_height)
293 jasonw 59908 unlock_update
294     try_call_setting_change_actions
295     end
296    
297 jasonw 66722 set_component_spacing (a_spacing: INTEGER_32)
298     -- Set `component_spacing' with `a_spacing'.
299 jasonw 65379 do
300     lock_update
301 jasonw 66722 component_spacing := a_spacing
302 jasonw 65379 unlock_update
303     try_call_setting_change_actions
304     ensure
305 jasonw 66722 component_spacing_set: component_spacing = a_spacing
306 jasonw 65379 end
307    
308 jasonw 66722 enable_adhesive_component
309     -- Enable adhesive component.
310 jasonw 65379 do
311     lock_update
312 jasonw 66722 is_component_adhesive_enabled := True
313 jasonw 65379 unlock_update
314     try_call_setting_change_actions
315     ensure
316 jasonw 66722 adhesive_component_enabled: is_component_adhesive_enabled
317 jasonw 65379 end
318    
319 jasonw 66722 disable_adhesive_component
320     -- Disable adhesive component.
321 jasonw 65379 do
322     lock_update
323 jasonw 66722 is_component_adhesive_enabled := False
324 jasonw 65379 unlock_update
325     try_call_setting_change_actions
326     ensure
327 jasonw 66722 adhesive_component_disabled: not is_component_adhesive_enabled
328 jasonw 65379 end
329    
330 jasonw 66722 ensure_component_display is
331     -- Ensure display of `components'.
332     -- See `is_component_display_ensured' for more information.
333 jasonw 65379 do
334 jasonw 66722 is_component_display_ensured := True
335 jasonw 65379 ensure
336 jasonw 66722 component_display_ensured: is_component_display_ensured
337 jasonw 65379 end
338    
339     ensure_text_display is
340     -- Ensure display of `editor_token_text'.
341 jasonw 66722 -- See `is_component_display_ensured' for more information.
342 jasonw 65379 do
343 jasonw 66722 is_component_display_ensured := False
344 jasonw 65379 ensure
345 jasonw 66722 text_display_ensured: not is_component_display_ensured
346 jasonw 65379 end
347    
348 jasonw 66565 set_stone (a_stone: like stone) is
349     -- Set `stone' with `a_stone'.
350     do
351     stone_internal := a_stone
352     ensure
353     stone_set: stone_internal = a_stone
354     end
355    
356     set_stone_function (a_function: like stone_function) is
357     -- Set `stone_function' with `a_function'.
358     do
359     stone_function := a_function
360     ensure
361     stone_function_set: stone_function = a_function
362     end
363 paulb 71346
364 jasonw 66557 feature -- Searchable
365    
366     set_image (a_image: like image) is
367     -- Set `image' with `a_image'.
368     require
369     a_image_attached: a_image /= Void
370     do
371     create image_internal.make_from_string (a_image)
372     ensure
373     image_set: image /= Void and then image.is_equal (a_image)
374     end
375    
376     image: STRING is
377     -- Image of current used in search
378     do
379     Result := image_internal
380     if Result = Void then
381     Result := ""
382     end
383     end
384    
385     feature{NONE} -- Implementation
386    
387     image_internal: like image
388     -- Implementation of `image'
389    
390     internal_replace (original, new: STRING) is
391     -- Replace every occurrence of `original' with `new' in `image'.
392     do
393     end
394    
395 jasonw 66722 required_component_width: INTEGER_32
396     -- Required width in pixel for displaying all attached `components'
397     do
398     Result := Precursor + component_spacing
399     end
400    
401 jasonw 58940 feature{NONE} -- Redraw
402    
403 jasonw 65379 perform_redraw (a_drawable: EV_DRAWABLE)
404     local
405     l_x_offset: INTEGER
406     l_required_text_width: INTEGER
407 jasonw 66722 l_required_component_width: INTEGER
408 jasonw 65379 l_token_text: like editor_token_text
409     l_left_width: INTEGER
410     l_text_start_x: INTEGER
411 jasonw 66722 l_component_start_x: INTEGER
412     l_width_for_text_and_component: INTEGER
413 jasonw 65379 l_max_text_width: INTEGER
414     do
415     prepare_grid_area (a_drawable)
416     l_x_offset := border_line_width + left_border
417     if pixmap /= Void then
418     draw_pixmap (a_drawable, l_x_offset)
419     l_x_offset := pixmap.width + spacing
420     end
421 paulb 71346 l_token_text := editor_token_text
422     l_token_text.set_overriden_selection_colors (parent.focused_selection_color, parent.non_focused_selection_color)
423    
424 jasonw 66722 -- Calculate text position and component position.
425 jasonw 65379 l_required_text_width := l_token_text.required_width
426 jasonw 66722 l_required_component_width := required_component_width
427 jasonw 65379 l_left_width := (width - l_x_offset - right_border - border_line_width).max (1)
428 jasonw 66722 l_width_for_text_and_component := l_required_text_width + l_required_component_width
429     if l_required_component_width = 0 then
430 jasonw 65379 if is_center_aligned then
431     l_text_start_x := ((l_left_width - l_required_text_width) // 2).max (0)
432     elseif is_right_aligned then
433     l_text_start_x := (l_left_width - l_required_text_width).max (0)
434     end
435     l_max_text_width := l_left_width.max (1)
436 jasonw 66722 elseif l_left_width >= l_width_for_text_and_component then
437 jasonw 65379 l_max_text_width := l_required_text_width
438     if is_left_aligned then
439     l_text_start_x := 0
440 jasonw 66722 if is_component_adhesive_enabled then
441     l_component_start_x := l_required_text_width
442 jasonw 65379 else
443 jasonw 66722 l_component_start_x := (l_left_width - l_required_component_width).max (1)
444 jasonw 65379 end
445     elseif is_center_aligned then
446 jasonw 66722 l_text_start_x := ((l_left_width - l_width_for_text_and_component) // 2).max (0)
447     if is_component_adhesive_enabled then
448     l_component_start_x := (l_text_start_x + l_required_text_width).max (1)
449 jasonw 65379 else
450 jasonw 66722 l_component_start_x := (l_left_width - l_required_component_width).max (1)
451 jasonw 65379 end
452     elseif is_right_aligned then
453 jasonw 66722 l_text_start_x := (l_left_width - l_width_for_text_and_component).max (0)
454     l_component_start_x := (l_left_width - l_required_component_width).max (1)
455 jasonw 65379 end
456 jasonw 66722 elseif l_width_for_text_and_component > l_left_width and then l_left_width >= l_required_text_width then
457 jasonw 65379 l_text_start_x := 0
458 jasonw 66722 if is_component_display_ensured then
459     l_component_start_x := (l_left_width - l_required_component_width).max (1)
460     l_max_text_width := l_component_start_x
461 jasonw 65379 else
462 jasonw 66722 l_component_start_x := l_required_text_width
463 jasonw 65379 l_max_text_width := l_required_text_width
464     end
465     elseif l_left_width < l_required_text_width then
466     l_text_start_x := 0
467 jasonw 66722 if is_component_display_ensured then
468     l_component_start_x := (l_left_width - l_required_component_width).max (1)
469     l_max_text_width := l_component_start_x
470 jasonw 65379 else
471     l_max_text_width := l_left_width
472 jasonw 66722 l_component_start_x := l_left_width
473 jasonw 65379 end
474     else
475     check False end
476     end
477     l_text_start_x := l_text_start_x + l_x_offset
478 jasonw 66722 l_component_start_x := l_component_start_x + l_x_offset
479 jasonw 65379 draw_text (a_drawable, l_text_start_x, l_max_text_width + l_text_start_x, parent.has_focus)
480 jasonw 66722 if l_required_component_width > 0 then
481     draw_components (a_drawable, l_component_start_x)
482 jasonw 65379 end
483     end
484    
485     prepare_grid_area (a_drawable: EV_DRAWABLE)
486     -- Prepare area in `a_drawable' for drawing current item.
487     -- i.e., clean area and draw background and draw borders.
488 jasonw 58940 require
489 jasonw 65379 a_drawable_attached: a_drawable /= Void
490 jasonw 58940 local
491     l_parent: EV_GRID
492 paulb 71346 l_gap: INTEGER
493 jasonw 58940 do
494 paulb 71346 if pixmap /= Void and then not is_full_select_enabled then
495     -- Determine selection render gap, and erase background
496     l_gap := pixmap.width + left_border + 2
497     a_drawable.set_foreground_color (parent.background_color)
498     a_drawable.fill_rectangle (0, 0, l_gap, height)
499     end
500    
501 jasonw 58940 l_parent := parent
502     if is_selected then
503 jasonw 59134 if l_parent.has_focus then
504 jasonw 67445 a_drawable.set_foreground_color (parent.focused_selection_color)
505 jasonw 59134 else
506 jasonw 67445 a_drawable.set_foreground_color (parent.non_focused_selection_color)
507 jasonw 59134 end
508 jasonw 65825 else
509     if background_color /= Void then
510     a_drawable.set_foreground_color (background_color)
511     elseif row.background_color /= Void then
512     a_drawable.set_foreground_color (row.background_color)
513     else
514     a_drawable.set_foreground_color (parent.background_color)
515     end
516 jasonw 58940 end
517 paulb 71346 a_drawable.fill_rectangle (l_gap, 0, width, height)
518 jasonw 58940 end
519    
520     feature{NONE} -- Implementation
521    
522     editor_token_text_internal: like editor_token_text
523     -- Internal `editor_token_text'
524    
525     safe_redraw is
526     -- Redraw current item if it's parented
527     require
528     not_destroyed: not is_destroyed
529     local
530     l_required_width: INTEGER
531     do
532 jasonw 66722 l_required_width := border_line_width * 2 + left_border + right_border + editor_token_text.required_width + required_component_width
533 jasonw 58940 if pixmap /= Void then
534     l_required_width := l_required_width + pixmap.width + spacing
535     end
536     set_required_width (l_required_width)
537     if is_parented then
538     redraw
539     end
540     end
541    
542 jasonw 59908 editor_token_text: EB_EDITOR_TOKEN_TEXT is
543     -- Editor token text
544     require
545     not_destroyed: not is_destroyed
546     do
547 paulb 71346 Result := editor_token_text_internal
548     if Result = Void then
549     create Result
550     editor_token_text_internal := Result
551 jasonw 59908 end
552     ensure
553     result_attached: Result /= Void
554 paulb 71346 result_consistent: Result = editor_token_text
555 jasonw 59908 end
556    
557 jasonw 58940 feature -- Pick and drop
558    
559 jasonw 66722 set_last_picked_item (a_index: INTEGER) is
560     -- Set `last_picked_item' with `a_index'.
561 jasonw 58940 do
562 jasonw 59908 check a_index <= editor_token_text.tokens.count end
563 jasonw 66722 last_picked_item := a_index
564     Precursor (a_index)
565 jasonw 58940 end
566    
567     token_index_at_current_position: INTEGER is
568 jasonw 59342 -- Index of token that is current position
569     -- 0 if no token is below that position.
570 jasonw 58940 local
571     l_editor_token_text: like editor_token_text
572 jasonw 65379 l_relative_position: like relative_pointer_position
573 jasonw 58940 do
574     l_editor_token_text := editor_token_text
575     if not l_editor_token_text.tokens.is_empty then
576 jasonw 65825 l_relative_position := relative_pointer_position (Current)
577 jasonw 65379 Result := l_editor_token_text.token_index_at_position (l_relative_position.x, l_relative_position.y)
578 jasonw 58940 end
579     end
580    
581     editor_token_pebble (a_index: INTEGER): ANY is
582     -- Pebble of token item indicated by `a_index'
583     -- Void if no pebble available.
584     do
585 jasonw 65825 Result := editor_token_text.pebble (a_index)
586 jasonw 58940 end
587    
588 jasonw 66722 feature -- Pick and drop
589 jasonw 65360
590 jasonw 67158 is_pick_on_text: BOOLEAN
591     -- Did last pick happen on `editor_token_text' area?
592    
593     set_is_pick_on_text (b: BOOLEAN) is
594     -- Set `is_pick_on_text' with `b'.
595     do
596     is_pick_on_text := b
597     ensure
598     is_pick_on_text_set: is_pick_on_text = b
599     end
600    
601 jasonw 66722 on_pick: ANY is
602     -- Action to be performed when pick starts
603     -- Return value is the picked pebble if any.
604 jasonw 65379 local
605 jasonw 66722 l_index: INTEGER
606     l_stone: STONE
607 jasonw 65379 do
608 jasonw 67158 l_index := token_index_at_current_position
609     if l_index > 0 then
610     l_stone ?= editor_token_pebble (l_index)
611     if l_stone /= Void then
612     Result := l_stone
613     set_is_pick_on_text (True)
614     set_last_picked_item (l_index)
615     end
616     elseif is_component_pebble_enabled then
617     l_index := component_index_at_pointer_position
618 jasonw 66722 if l_index > 0 then
619 jasonw 67158 set_last_picked_item (l_index)
620     Result := pick_component (l_index)
621     if Result = Void then
622     set_last_picked_item (0)
623     else
624     set_is_pick_on_text (False)
625 jasonw 66722 end
626 jasonw 65379 end
627     end
628     end
629    
630 jasonw 66722 on_pick_ends is
631     -- Action to be performed hwne pick-and-drop finishes
632 jasonw 65379 do
633 jasonw 67158 if not is_pick_on_text then
634     if last_picked_item > 0 and then last_picked_item <= component_count then
635     component (last_picked_item).on_pick_ended
636     end
637 jasonw 65379 end
638 jasonw 67158 set_last_picked_item (0)
639 jasonw 65379 end
640    
641 jasonw 66722 feature{NONE} -- Implementation
642    
643     required_width_for_text_and_component: INTEGER_32
644     -- Required width in pixel to display text and components.
645 jasonw 65379 do
646 jasonw 66722 Result := editor_token_text.required_width + required_component_width
647 jasonw 65379 ensure
648     result_attached: Result >= 0
649     end
650    
651 jasonw 66722 required_height_for_text_and_component: INTEGER_32
652     -- Required height in pixel to display text and components.
653 jasonw 65379 do
654 jasonw 66722 Result := editor_token_text.required_height.max (required_component_height)
655 jasonw 65379 ensure
656     result_attached: Result >= 0
657     end
658    
659     draw_pixmap (a_drawable: EV_DRAWABLE; a_start_x: INTEGER_32)
660     -- Display `pixmap' in `a_drawable' from `a_start_x'.
661     -- Pixmap is always vertically center aligned.
662     require
663     a_drawable_attached: a_drawable /= Void
664     pixmap_attached: pixmap /= Void
665     do
666     a_drawable.draw_pixmap (a_start_x, vertical_starting_position (pixmap.height, 2, False), pixmap)
667     end
668    
669     draw_text (a_drawable: EV_DRAWABLE; a_start_x: INTEGER_32; a_max_width: INTEGER_32; a_focused: BOOLEAN)
670     -- Draw text in `a_drawable' starting from `a_start_x'.
671     -- The maximum width in pixel for text is `a_max_width'.
672     -- `a_focused' indicates whether current item is selected.
673     require
674     a_drawable_attached: a_drawable /= Void
675     local
676     y: INTEGER_32
677     l_token_text: like editor_token_text
678     l_should_update: BOOLEAN
679 jasonw 67158 l_picked_item_index: INTEGER
680 jasonw 65379 do
681     l_token_text := editor_token_text
682     if not l_token_text.tokens.is_empty then
683     y := vertical_starting_position (l_token_text.required_height, alignment_index, True)
684     l_token_text.lock_update
685     if a_start_x /= l_token_text.x_offset or y /= l_token_text.y_offset then
686     l_token_text.set_x_y_offset (a_start_x, y)
687     l_should_update := True
688     end
689     if a_max_width /= l_token_text.maximum_width then
690     l_token_text.set_maximum_width (a_max_width)
691     l_should_update := True
692     end
693     l_token_text.unlock_update
694     if l_should_update then
695     l_token_text.try_call_setting_change_actions
696     end
697     if is_selected then
698     l_token_text.display_selected (0, 0, a_drawable, a_focused)
699     else
700 jasonw 67158 if is_pick_on_text then
701     l_picked_item_index := last_picked_item
702     end
703     l_token_text.display (0, 0, a_drawable, l_picked_item_index, a_focused)
704 jasonw 65379 end
705     end
706     end
707    
708     alignment_index: INTEGER_32
709     -- Index of alignment
710     do
711     if is_vertically_center_aligned then
712     Result := 2
713     elseif is_top_aligned then
714     Result := 3
715     elseif is_bottom_aligned then
716     Result := 1
717     end
718     ensure
719     good_result: Result = 1 or Result = 2 or Result = 3
720     end
721    
722 jasonw 66722 draw_components (a_drawable: EV_DRAWABLE; a_start_x: INTEGER_32)
723     -- Draw `components' in `a_drawable' starting from `a_start_x'.
724     -- `components' are always vertically center aligned.
725 jasonw 65379 require
726     a_drawable_attached: a_drawable /= Void
727     local
728 jasonw 66722 l_components: like components
729 jasonw 65379 x, y: INTEGER_32
730     l_count: INTEGER_32
731 jasonw 66722 l_component_padding: INTEGER_32
732     l_component: like component_type
733     l_component_position: like component_position
734 jasonw 65379 l_width, l_height: INTEGER
735     do
736 jasonw 66722 l_components := components
737     if not l_components.is_empty then
738 jasonw 65379
739     end
740 jasonw 66722 l_component_position := component_position
741     if not l_components.is_empty then
742     l_component_position.wipe_out
743     l_component_padding := component_padding
744 jasonw 65379 from
745 jasonw 66722 x := a_start_x + component_spacing
746     l_count := l_components.count
747     l_components.start
748 jasonw 65379 until
749 jasonw 66722 l_components.after
750 jasonw 65379 loop
751 jasonw 66722 l_component := l_components.item
752     y := vertical_starting_position (l_component.required_height, 2, False)
753     l_width := l_component.required_width
754     l_height := l_component.required_height
755     l_component.display (a_drawable, x, y, l_width, l_height)
756     l_component_position.extend (create {EV_RECTANGLE}.make (x, y, l_width, l_height))
757     x := x + l_component.required_width
758     if l_components.index < l_count then
759     x := x + l_component_padding
760 jasonw 65379 end
761 jasonw 66722 l_components.forth
762 jasonw 65379 end
763     end
764     end
765    
766     vertical_starting_position (a_required_height: INTEGER_32; a_align: INTEGER_32; a_border_enabled: BOOLEAN): INTEGER_32
767     -- Vertical starting position for an object to be displayed which is `a_required_height' pixel high.
768     -- `a_align' is vertical alignment policy whose value has the following meaning:
769     -- 1. Bottom aligned
770     -- 2. Center aligned
771     -- 3. Top aligned
772     -- If `a_border_enabled' is False, do take `border_line_width' and `top_border' into consideration.
773     require
774     a_align_valid: a_align = 1 or a_align = 2 or a_align = 3
775     local
776     l_space_left: INTEGER_32
777     l_vertical_base: INTEGER_32
778     l_y_offset: INTEGER_32
779     do
780     if a_border_enabled then
781     l_vertical_base := border_line_width + top_border
782     l_space_left := height - 2 * border_line_width - top_border - bottom_border
783     else
784     l_space_left := height
785     end
786     if l_space_left < 0 or else a_align = 3 then
787     Result := l_vertical_base
788     else
789     l_y_offset := ((l_space_left - a_required_height) // a_align).max (0)
790     Result := l_vertical_base + l_y_offset
791     end
792     end
793    
794 jasonw 66722 stone_internal: like stone
795     -- Implementation of `stone' if `stone_function' is not Set.
796 jasonw 65379
797 jasonw 66565 grid_item: EV_GRID_ITEM is
798     -- EV_GRID item associated with current
799     do
800     Result := Current
801     end
802    
803 jasonw 58940 indexing
804     copyright: "Copyright (c) 1984-2006, Eiffel Software"
805     license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
806     licensing_options: "http://www.eiffel.com/licensing"
807     copying: "[
808     This file is part of Eiffel Software's Eiffel Development Environment.
809    
810     Eiffel Software's Eiffel Development Environment is free
811     software; you can redistribute it and/or modify it under
812     the terms of the GNU General Public License as published
813     by the Free Software Foundation, version 2 of the License
814     (available at the URL listed under "license" above).
815    
816     Eiffel Software's Eiffel Development Environment is
817     distributed in the hope that it will be useful, but
818     WITHOUT ANY WARRANTY; without even the implied warranty
819     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
820     See the GNU General Public License for more details.
821    
822     You should have received a copy of the GNU General Public
823     License along with Eiffel Software's Eiffel Development
824     Environment; if not, write to the Free Software Foundation,
825     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
826     ]"
827     source: "[
828     Eiffel Software
829     356 Storke Road, Goleta, CA 93117 USA
830     Telephone 805-685-1006, Fax 805-685-6869
831     Website http://www.eiffel.com
832     Customer support http://support.eiffel.com
833     ]"
834    
835     end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23