1 /* Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2 2007, 2009 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 * \brief Source: pulldown menu code
27 #include <sys/types.h>
29 #include "lib/global.h"
31 #include "lib/tty/tty.h"
33 #include "lib/tty/mouse.h"
34 #include "lib/tty/key.h" /* key macros */
35 #include "lib/strutil.h"
36 #include "lib/widget.h"
38 /* TODO: these includes should be removed! */
39 #include "src/keybind-defaults.h" /* CK_Ignore_Key */
41 #include "src/filemanager/midnight.h" /* is_right */
43 /*** global variables ****************************************************************************/
45 /*** file scope macro definitions ****************************************************************/
47 /*** file scope type declarations ****************************************************************/
49 /*** file scope variables ************************************************************************/
51 static cb_ret_t
menubar_callback (Widget
* w
, widget_msg_t msg
, int parm
);
53 /*** file scope functions ************************************************************************/
54 /* --------------------------------------------------------------------------------------------- */
57 menu_arrange (Menu
* menu
, dlg_shortcut_str get_shortcut
)
62 size_t max_shortcut_len
= 0;
64 menu
->max_entry_len
= 1;
65 menu
->max_hotkey_len
= 1;
67 for (i
= menu
->entries
; i
!= NULL
; i
= g_list_next (i
))
69 menu_entry_t
*entry
= i
->data
;
75 len
= (size_t) hotkey_width (entry
->text
);
76 menu
->max_hotkey_len
= max (menu
->max_hotkey_len
, len
);
78 if (get_shortcut
!= NULL
)
79 entry
->shortcut
= get_shortcut (entry
->command
);
81 if (entry
->shortcut
!= NULL
)
83 len
= (size_t) str_term_width1 (entry
->shortcut
);
84 max_shortcut_len
= max (max_shortcut_len
, len
);
89 menu
->max_entry_len
= menu
->max_hotkey_len
+ max_shortcut_len
;
93 /* --------------------------------------------------------------------------------------------- */
96 menubar_paint_idx (WMenuBar
* menubar
, unsigned int idx
, int color
)
98 const Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
99 const menu_entry_t
*entry
= g_list_nth_data (menu
->entries
, idx
);
100 const int y
= 2 + idx
;
101 int x
= menu
->start_x
;
103 if (x
+ menu
->max_entry_len
+ 4 > (gsize
) menubar
->widget
.cols
)
104 x
= menubar
->widget
.cols
- menu
->max_entry_len
- 4;
109 tty_setcolor (MENU_ENTRY_COLOR
);
111 widget_move (&menubar
->widget
, y
, x
- 1);
112 tty_print_alt_char (ACS_LTEE
, FALSE
);
114 tty_draw_hline (menubar
->widget
.y
+ y
, menubar
->widget
.x
+ x
,
115 ACS_HLINE
, menu
->max_entry_len
+ 3);
117 widget_move (&menubar
->widget
, y
, x
+ menu
->max_entry_len
+ 3);
118 tty_print_alt_char (ACS_RTEE
, FALSE
);
123 tty_setcolor (color
);
124 widget_move (&menubar
->widget
, y
, x
);
125 tty_print_char ((unsigned char) entry
->first_letter
);
126 tty_draw_hline (-1, -1, ' ', menu
->max_entry_len
+ 2); /* clear line */
127 tty_print_string (entry
->text
.start
);
129 if (entry
->text
.hotkey
!= NULL
)
131 tty_setcolor (color
== MENU_SELECTED_COLOR
? MENU_HOTSEL_COLOR
: MENU_HOT_COLOR
);
132 tty_print_string (entry
->text
.hotkey
);
133 tty_setcolor (color
);
136 if (entry
->text
.end
!= NULL
)
137 tty_print_string (entry
->text
.end
);
139 if (entry
->shortcut
!= NULL
)
141 widget_move (&menubar
->widget
, y
, x
+ menu
->max_hotkey_len
+ 3);
142 tty_print_string (entry
->shortcut
);
145 /* move cursor to the start of entry text */
146 widget_move (&menubar
->widget
, y
, x
+ 1);
150 /* --------------------------------------------------------------------------------------------- */
153 menubar_draw_drop (WMenuBar
* menubar
)
155 const Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
156 const unsigned int count
= g_list_length (menu
->entries
);
157 int column
= menu
->start_x
- 1;
160 if (column
+ menu
->max_entry_len
+ 5 > (gsize
) menubar
->widget
.cols
)
161 column
= menubar
->widget
.cols
- menu
->max_entry_len
- 5;
163 tty_setcolor (MENU_ENTRY_COLOR
);
164 draw_box (menubar
->widget
.owner
,
165 menubar
->widget
.y
+ 1, menubar
->widget
.x
+ column
,
166 count
+ 2, menu
->max_entry_len
+ 5, FALSE
);
168 for (i
= 0; i
< count
; i
++)
169 menubar_paint_idx (menubar
, i
,
170 i
== menu
->selected
? MENU_SELECTED_COLOR
: MENU_ENTRY_COLOR
);
173 /* --------------------------------------------------------------------------------------------- */
176 menubar_set_color (WMenuBar
* menubar
, gboolean current
, gboolean hotkey
)
178 if (!menubar
->is_active
)
179 tty_setcolor (MENU_INACTIVE_COLOR
);
181 tty_setcolor (hotkey
? MENU_HOTSEL_COLOR
: MENU_SELECTED_COLOR
);
183 tty_setcolor (hotkey
? MENU_HOT_COLOR
: MENU_ENTRY_COLOR
);
186 /* --------------------------------------------------------------------------------------------- */
189 menubar_draw (WMenuBar
* menubar
)
193 /* First draw the complete menubar */
194 tty_setcolor (menubar
->is_active
? MENU_ENTRY_COLOR
: MENU_INACTIVE_COLOR
);
195 tty_draw_hline (menubar
->widget
.y
, menubar
->widget
.x
, ' ', menubar
->widget
.cols
);
197 /* Now each one of the entries */
198 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
200 Menu
*menu
= i
->data
;
201 gboolean is_selected
= (menubar
->selected
== (gsize
) g_list_position (menubar
->menu
, i
));
203 menubar_set_color (menubar
, is_selected
, FALSE
);
204 widget_move (&menubar
->widget
, 0, menu
->start_x
);
206 tty_print_char (' ');
207 tty_print_string (menu
->text
.start
);
209 if (menu
->text
.hotkey
!= NULL
)
211 menubar_set_color (menubar
, is_selected
, TRUE
);
212 tty_print_string (menu
->text
.hotkey
);
213 menubar_set_color (menubar
, is_selected
, FALSE
);
216 if (menu
->text
.end
!= NULL
)
217 tty_print_string (menu
->text
.end
);
219 tty_print_char (' ');
222 if (menubar
->is_dropped
)
223 menubar_draw_drop (menubar
);
225 widget_move (&menubar
->widget
, 0,
226 ((Menu
*) g_list_nth_data (menubar
->menu
, menubar
->selected
))->start_x
);
229 /* --------------------------------------------------------------------------------------------- */
232 menubar_remove (WMenuBar
* menubar
)
234 if (menubar
->is_dropped
)
236 menubar
->is_dropped
= FALSE
;
238 menubar
->is_dropped
= TRUE
;
242 /* --------------------------------------------------------------------------------------------- */
245 menubar_left (WMenuBar
* menubar
)
247 menubar_remove (menubar
);
248 if (menubar
->selected
== 0)
249 menubar
->selected
= g_list_length (menubar
->menu
) - 1;
252 menubar_draw (menubar
);
255 /* --------------------------------------------------------------------------------------------- */
258 menubar_right (WMenuBar
* menubar
)
260 menubar_remove (menubar
);
261 menubar
->selected
= (menubar
->selected
+ 1) % g_list_length (menubar
->menu
);
262 menubar_draw (menubar
);
265 /* --------------------------------------------------------------------------------------------- */
268 menubar_finish (WMenuBar
* menubar
)
270 menubar
->is_dropped
= FALSE
;
271 menubar
->is_active
= FALSE
;
272 menubar
->widget
.lines
= 1;
273 widget_want_hotkey (menubar
->widget
, 0);
275 dlg_select_by_id (menubar
->widget
.owner
, menubar
->previous_widget
);
279 /* --------------------------------------------------------------------------------------------- */
282 menubar_drop (WMenuBar
* menubar
, unsigned int selected
)
284 menubar
->is_dropped
= TRUE
;
285 menubar
->selected
= selected
;
286 menubar_draw (menubar
);
289 /* --------------------------------------------------------------------------------------------- */
292 menubar_execute (WMenuBar
* menubar
)
294 const Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
295 const menu_entry_t
*entry
= g_list_nth_data (menu
->entries
, menu
->selected
);
297 if ((entry
!= NULL
) && (entry
->command
!= CK_Ignore_Key
))
299 is_right
= (menubar
->selected
!= 0);
300 menubar_finish (menubar
);
301 menubar
->widget
.owner
->callback (menubar
->widget
.owner
, &menubar
->widget
,
302 DLG_ACTION
, entry
->command
, NULL
);
307 /* --------------------------------------------------------------------------------------------- */
310 menubar_down (WMenuBar
* menubar
)
312 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
313 const unsigned int len
= g_list_length (menu
->entries
);
316 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
320 menu
->selected
= (menu
->selected
+ 1) % len
;
321 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
323 while ((entry
== NULL
) || (entry
->command
== CK_Ignore_Key
));
325 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
328 /* --------------------------------------------------------------------------------------------- */
331 menubar_up (WMenuBar
* menubar
)
333 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
334 const unsigned int len
= g_list_length (menu
->entries
);
337 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
341 if (menu
->selected
== 0)
342 menu
->selected
= len
- 1;
345 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
347 while ((entry
== NULL
) || (entry
->command
== CK_Ignore_Key
));
349 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
352 /* --------------------------------------------------------------------------------------------- */
355 menubar_first (WMenuBar
* menubar
)
357 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
360 if (menu
->selected
== 0)
363 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
369 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
371 if ((entry
== NULL
) || (entry
->command
== CK_Ignore_Key
))
377 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
380 /* --------------------------------------------------------------------------------------------- */
383 menubar_last (WMenuBar
* menubar
)
385 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
386 const unsigned int len
= g_list_length (menu
->entries
);
389 if (menu
->selected
== len
- 1)
392 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
394 menu
->selected
= len
;
399 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
401 while ((entry
== NULL
) || (entry
->command
== CK_Ignore_Key
));
403 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
406 /* --------------------------------------------------------------------------------------------- */
409 menubar_handle_key (WMenuBar
* menubar
, int key
)
413 key
= g_ascii_tolower (key
);
415 if (is_abort_char (key
))
417 menubar_finish (menubar
);
421 /* menubar help or menubar navigation */
425 if (menubar
->is_dropped
)
426 interactive_display (NULL
,
427 ((Menu
*) g_list_nth_data (menubar
->menu
,
428 menubar
->selected
))->help_node
);
430 interactive_display (NULL
, "[Menu Bar]");
431 menubar_draw (menubar
);
436 menubar_left (menubar
);
441 menubar_right (menubar
);
445 if (!menubar
->is_dropped
)
449 /* drop menu by hotkey */
450 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
452 Menu
*menu
= i
->data
;
454 if ((menu
->text
.hotkey
!= NULL
) && (key
== g_ascii_tolower (menu
->text
.hotkey
[0])))
456 menubar_drop (menubar
, g_list_position (menubar
->menu
, i
));
461 /* drop menu by Enter or Dowwn key */
462 if (key
== KEY_ENTER
|| key
== XCTRL ('n') || key
== KEY_DOWN
|| key
== '\n')
463 menubar_drop (menubar
, menubar
->selected
);
469 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
472 /* execute menu command by hotkey */
473 for (i
= menu
->entries
; i
!= NULL
; i
= g_list_next (i
))
475 const menu_entry_t
*entry
= i
->data
;
477 if ((entry
!= NULL
) && (entry
->command
!= CK_Ignore_Key
)
478 && (entry
->text
.hotkey
!= NULL
) && (key
== g_ascii_tolower (entry
->text
.hotkey
[0])))
480 menu
->selected
= g_list_position (menu
->entries
, i
);
481 menubar_execute (menubar
);
486 /* menu execute by Enter or menu navigation */
491 menubar_execute (menubar
);
496 menubar_first (menubar
);
501 menubar_last (menubar
);
506 menubar_down (menubar
);
511 menubar_up (menubar
);
519 /* --------------------------------------------------------------------------------------------- */
522 menubar_callback (Widget
* w
, widget_msg_t msg
, int parm
)
524 WMenuBar
*menubar
= (WMenuBar
*) w
;
528 /* We do not want the focus unless we have been activated */
530 if (!menubar
->is_active
)
531 return MSG_NOT_HANDLED
;
533 /* Trick to get all the mouse events */
534 menubar
->widget
.lines
= LINES
;
536 /* Trick to get all of the hotkeys */
537 widget_want_hotkey (menubar
->widget
, 1);
538 menubar_draw (menubar
);
541 /* We don't want the buttonbar to activate while using the menubar */
544 if (menubar
->is_active
)
546 menubar_handle_key (menubar
, parm
);
549 return MSG_NOT_HANDLED
;
552 /* Put the cursor in a suitable place */
553 return MSG_NOT_HANDLED
;
556 return menubar
->is_active
? MSG_NOT_HANDLED
: MSG_HANDLED
;
559 if (menubar
->is_visible
)
561 menubar_draw (menubar
);
567 /* try show menu after screen resize */
568 send_message (w
, WIDGET_FOCUS
, 0);
573 menubar_set_menu (menubar
, NULL
);
577 return default_proc (msg
, parm
);
581 /* --------------------------------------------------------------------------------------------- */
584 menubar_event (Gpm_Event
* event
, void *data
)
586 WMenuBar
*menubar
= data
;
587 gboolean was_active
= TRUE
;
588 int left_x
, right_x
, bottom_y
;
591 /* ignore unsupported events */
592 if ((event
->type
& (GPM_UP
| GPM_DOWN
| GPM_DRAG
)) == 0)
595 /* ignore wheel events if menu is inactive */
596 if (!menubar
->is_active
&& ((event
->buttons
& (GPM_B_MIDDLE
| GPM_B_UP
| GPM_B_DOWN
)) != 0))
599 if (!menubar
->is_dropped
)
601 menubar
->previous_widget
= dlg_get_current_widget_id (menubar
->widget
.owner
);
602 menubar
->is_active
= TRUE
;
603 menubar
->is_dropped
= TRUE
;
607 /* Mouse operations on the menubar */
608 if (event
->y
== 1 || !was_active
)
610 if ((event
->type
& GPM_UP
) != 0)
613 /* wheel events on menubar */
614 if (event
->buttons
& GPM_B_UP
)
615 menubar_left (menubar
);
616 else if (event
->buttons
& GPM_B_DOWN
)
617 menubar_right (menubar
);
620 const unsigned int len
= g_list_length (menubar
->menu
);
621 unsigned int new_selection
= 0;
623 while ((new_selection
< len
)
624 && (event
->x
> ((Menu
*) g_list_nth_data (menubar
->menu
,
625 new_selection
))->start_x
))
628 if (new_selection
!= 0) /* Don't set the invalid value -1 */
633 menubar
->selected
= new_selection
;
634 dlg_select_widget (menubar
);
638 menubar_remove (menubar
);
639 menubar
->selected
= new_selection
;
641 menubar_draw (menubar
);
646 if (!menubar
->is_dropped
|| (event
->y
< 2))
649 /* middle click -- everywhere */
650 if (((event
->buttons
& GPM_B_MIDDLE
) != 0) && ((event
->type
& GPM_DOWN
) != 0))
652 menubar_execute (menubar
);
656 /* the mouse operation is on the menus or it is not */
657 menu
= (Menu
*) g_list_nth_data (menubar
->menu
, menubar
->selected
);
658 left_x
= menu
->start_x
;
659 right_x
= left_x
+ menu
->max_entry_len
+ 3;
660 if (right_x
> menubar
->widget
.cols
)
662 left_x
= menubar
->widget
.cols
- menu
->max_entry_len
- 3;
663 right_x
= menubar
->widget
.cols
;
666 bottom_y
= g_list_length (menu
->entries
) + 3;
668 if ((event
->x
>= left_x
) && (event
->x
<= right_x
) && (event
->y
<= bottom_y
))
670 int pos
= event
->y
- 3;
671 const menu_entry_t
*entry
= g_list_nth_data (menu
->entries
, pos
);
674 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
))
676 menubar_up (menubar
);
679 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
))
681 menubar_down (menubar
);
685 /* ignore events above and below dropped down menu */
686 if ((pos
< 0) || (pos
>= bottom_y
- 3))
689 if ((entry
!= NULL
) && (entry
->command
!= CK_Ignore_Key
))
691 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
692 menu
->selected
= pos
;
693 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
695 if ((event
->type
& GPM_UP
) != 0)
696 menubar_execute (menubar
);
700 /* use click not wheel to close menu */
701 if (((event
->type
& GPM_DOWN
) != 0) && ((event
->buttons
& (GPM_B_UP
| GPM_B_DOWN
)) == 0))
702 menubar_finish (menubar
);
707 /* --------------------------------------------------------------------------------------------- */
708 /*** public functions ****************************************************************************/
709 /* --------------------------------------------------------------------------------------------- */
712 menu_entry_create (const char *name
, unsigned long command
)
716 entry
= g_new (menu_entry_t
, 1);
717 entry
->first_letter
= ' ';
718 entry
->text
= parse_hotkey (name
);
719 entry
->command
= command
;
720 entry
->shortcut
= NULL
;
725 /* --------------------------------------------------------------------------------------------- */
728 menu_entry_free (menu_entry_t
* entry
)
732 release_hotkey (entry
->text
);
733 g_free (entry
->shortcut
);
738 /* --------------------------------------------------------------------------------------------- */
741 create_menu (const char *name
, GList
* entries
, const char *help_node
)
745 menu
= g_new (Menu
, 1);
747 menu
->text
= parse_hotkey (name
);
748 menu
->entries
= entries
;
749 menu
->max_entry_len
= 1;
750 menu
->max_hotkey_len
= 0;
752 menu
->help_node
= g_strdup (help_node
);
757 /* --------------------------------------------------------------------------------------------- */
760 menu_set_name (Menu
* menu
, const char *name
)
762 release_hotkey (menu
->text
);
763 menu
->text
= parse_hotkey (name
);
766 /* --------------------------------------------------------------------------------------------- */
769 destroy_menu (Menu
* menu
)
771 release_hotkey (menu
->text
);
772 g_list_foreach (menu
->entries
, (GFunc
) menu_entry_free
, NULL
);
773 g_list_free (menu
->entries
);
774 g_free (menu
->help_node
);
778 /* --------------------------------------------------------------------------------------------- */
781 menubar_new (int y
, int x
, int cols
, GList
* menu
)
785 menubar
= g_new0 (WMenuBar
, 1);
786 init_widget (&menubar
->widget
, y
, x
, 1, cols
, menubar_callback
, menubar_event
);
787 widget_want_cursor (menubar
->widget
, FALSE
);
788 menubar
->is_visible
= TRUE
; /* by default */
789 menubar_set_menu (menubar
, menu
);
794 /* --------------------------------------------------------------------------------------------- */
797 menubar_set_menu (WMenuBar
* menubar
, GList
* menu
)
799 /* delete previous menu */
800 if (menubar
->menu
!= NULL
)
802 g_list_foreach (menubar
->menu
, (GFunc
) destroy_menu
, NULL
);
803 g_list_free (menubar
->menu
);
806 menubar
->is_active
= FALSE
;
807 menubar
->is_dropped
= FALSE
;
808 menubar
->menu
= menu
;
809 menubar
->selected
= 0;
810 menubar_arrange (menubar
);
813 /* --------------------------------------------------------------------------------------------- */
816 menubar_add_menu (WMenuBar
* menubar
, Menu
* menu
)
820 menu_arrange (menu
, menubar
->widget
.owner
->get_shortcut
);
821 menubar
->menu
= g_list_append (menubar
->menu
, menu
);
824 menubar_arrange (menubar
);
827 /* --------------------------------------------------------------------------------------------- */
829 * Properly space menubar items. Should be called when menubar is created
830 * and also when widget width is changed (i.e. upon xterm resize).
834 menubar_arrange (WMenuBar
* menubar
)
840 if (menubar
->menu
== NULL
)
843 #ifndef RESIZABLE_MENUBAR
846 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
848 Menu
*menu
= i
->data
;
849 int len
= hotkey_width (menu
->text
) + 2;
851 menu
->start_x
= start_x
;
852 start_x
+= len
+ gap
;
854 #else /* RESIZABLE_MENUBAR */
855 gap
= menubar
->widget
.cols
- 2;
857 /* First, calculate gap between items... */
858 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
860 Menu
*menu
= i
->data
;
861 /* preserve length here, to be used below */
862 menu
->start_x
= hotkey_width (menu
->text
) + 2;
863 gap
-= menu
->start_x
;
866 gap
/= (menubar
->menu
->len
- 1);
870 /* We are out of luck - window is too narrow... */
874 /* ...and now fix start positions of menubar items */
875 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
877 Menu
*menu
= i
->data
;
878 int len
= menu
->start_x
;
880 menu
->start_x
= start_x
;
881 start_x
+= len
+ gap
;
883 #endif /* RESIZABLE_MENUBAR */
886 /* --------------------------------------------------------------------------------------------- */
887 /** Find MenuBar widget in the dialog */
890 find_menubar (const Dlg_head
* h
)
892 return (WMenuBar
*) find_widget_type (h
, menubar_callback
);
895 /* --------------------------------------------------------------------------------------------- */