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"
37 #include "lib/event.h" /* mc_event_raise() */
39 /*** global variables ****************************************************************************/
41 /*** file scope macro definitions ****************************************************************/
43 /*** file scope type declarations ****************************************************************/
45 /*** file scope variables ************************************************************************/
47 static cb_ret_t
menubar_callback (Widget
* w
, widget_msg_t msg
, int parm
);
49 /*** file scope functions ************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
53 menu_arrange (Menu
* menu
, dlg_shortcut_str get_shortcut
)
58 size_t max_shortcut_len
= 0;
60 menu
->max_entry_len
= 1;
61 menu
->max_hotkey_len
= 1;
63 for (i
= menu
->entries
; i
!= NULL
; i
= g_list_next (i
))
65 menu_entry_t
*entry
= i
->data
;
71 len
= (size_t) hotkey_width (entry
->text
);
72 menu
->max_hotkey_len
= max (menu
->max_hotkey_len
, len
);
74 if (get_shortcut
!= NULL
)
75 entry
->shortcut
= get_shortcut (entry
->command
);
77 if (entry
->shortcut
!= NULL
)
79 len
= (size_t) str_term_width1 (entry
->shortcut
);
80 max_shortcut_len
= max (max_shortcut_len
, len
);
85 menu
->max_entry_len
= menu
->max_hotkey_len
+ max_shortcut_len
;
89 /* --------------------------------------------------------------------------------------------- */
92 menubar_paint_idx (WMenuBar
* menubar
, unsigned int idx
, int color
)
94 const Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
95 const menu_entry_t
*entry
= g_list_nth_data (menu
->entries
, idx
);
96 const int y
= 2 + idx
;
97 int x
= menu
->start_x
;
99 if (x
+ menu
->max_entry_len
+ 4 > (gsize
) menubar
->widget
.cols
)
100 x
= menubar
->widget
.cols
- menu
->max_entry_len
- 4;
105 tty_setcolor (MENU_ENTRY_COLOR
);
107 widget_move (&menubar
->widget
, y
, x
- 1);
108 tty_print_alt_char (ACS_LTEE
, FALSE
);
110 tty_draw_hline (menubar
->widget
.y
+ y
, menubar
->widget
.x
+ x
,
111 ACS_HLINE
, menu
->max_entry_len
+ 3);
113 widget_move (&menubar
->widget
, y
, x
+ menu
->max_entry_len
+ 3);
114 tty_print_alt_char (ACS_RTEE
, FALSE
);
119 tty_setcolor (color
);
120 widget_move (&menubar
->widget
, y
, x
);
121 tty_print_char ((unsigned char) entry
->first_letter
);
122 tty_draw_hline (-1, -1, ' ', menu
->max_entry_len
+ 2); /* clear line */
123 tty_print_string (entry
->text
.start
);
125 if (entry
->text
.hotkey
!= NULL
)
127 tty_setcolor (color
== MENU_SELECTED_COLOR
? MENU_HOTSEL_COLOR
: MENU_HOT_COLOR
);
128 tty_print_string (entry
->text
.hotkey
);
129 tty_setcolor (color
);
132 if (entry
->text
.end
!= NULL
)
133 tty_print_string (entry
->text
.end
);
135 if (entry
->shortcut
!= NULL
)
137 widget_move (&menubar
->widget
, y
, x
+ menu
->max_hotkey_len
+ 3);
138 tty_print_string (entry
->shortcut
);
141 /* move cursor to the start of entry text */
142 widget_move (&menubar
->widget
, y
, x
+ 1);
146 /* --------------------------------------------------------------------------------------------- */
149 menubar_draw_drop (WMenuBar
* menubar
)
151 const Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
152 const unsigned int count
= g_list_length (menu
->entries
);
153 int column
= menu
->start_x
- 1;
156 if (column
+ menu
->max_entry_len
+ 5 > (gsize
) menubar
->widget
.cols
)
157 column
= menubar
->widget
.cols
- menu
->max_entry_len
- 5;
159 tty_setcolor (MENU_ENTRY_COLOR
);
160 draw_box (menubar
->widget
.owner
,
161 menubar
->widget
.y
+ 1, menubar
->widget
.x
+ column
,
162 count
+ 2, menu
->max_entry_len
+ 5, FALSE
);
164 for (i
= 0; i
< count
; i
++)
165 menubar_paint_idx (menubar
, i
,
166 i
== menu
->selected
? MENU_SELECTED_COLOR
: MENU_ENTRY_COLOR
);
169 /* --------------------------------------------------------------------------------------------- */
172 menubar_set_color (WMenuBar
* menubar
, gboolean current
, gboolean hotkey
)
174 if (!menubar
->is_active
)
175 tty_setcolor (MENU_INACTIVE_COLOR
);
177 tty_setcolor (hotkey
? MENU_HOTSEL_COLOR
: MENU_SELECTED_COLOR
);
179 tty_setcolor (hotkey
? MENU_HOT_COLOR
: MENU_ENTRY_COLOR
);
182 /* --------------------------------------------------------------------------------------------- */
185 menubar_draw (WMenuBar
* menubar
)
189 /* First draw the complete menubar */
190 tty_setcolor (menubar
->is_active
? MENU_ENTRY_COLOR
: MENU_INACTIVE_COLOR
);
191 tty_draw_hline (menubar
->widget
.y
, menubar
->widget
.x
, ' ', menubar
->widget
.cols
);
193 /* Now each one of the entries */
194 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
196 Menu
*menu
= i
->data
;
197 gboolean is_selected
= (menubar
->selected
== (gsize
) g_list_position (menubar
->menu
, i
));
199 menubar_set_color (menubar
, is_selected
, FALSE
);
200 widget_move (&menubar
->widget
, 0, menu
->start_x
);
202 tty_print_char (' ');
203 tty_print_string (menu
->text
.start
);
205 if (menu
->text
.hotkey
!= NULL
)
207 menubar_set_color (menubar
, is_selected
, TRUE
);
208 tty_print_string (menu
->text
.hotkey
);
209 menubar_set_color (menubar
, is_selected
, FALSE
);
212 if (menu
->text
.end
!= NULL
)
213 tty_print_string (menu
->text
.end
);
215 tty_print_char (' ');
218 if (menubar
->is_dropped
)
219 menubar_draw_drop (menubar
);
221 widget_move (&menubar
->widget
, 0,
222 ((Menu
*) g_list_nth_data (menubar
->menu
, menubar
->selected
))->start_x
);
225 /* --------------------------------------------------------------------------------------------- */
228 menubar_remove (WMenuBar
* menubar
)
230 if (menubar
->is_dropped
)
232 menubar
->is_dropped
= FALSE
;
234 menubar
->is_dropped
= TRUE
;
238 /* --------------------------------------------------------------------------------------------- */
241 menubar_left (WMenuBar
* menubar
)
243 menubar_remove (menubar
);
244 if (menubar
->selected
== 0)
245 menubar
->selected
= g_list_length (menubar
->menu
) - 1;
248 menubar_draw (menubar
);
251 /* --------------------------------------------------------------------------------------------- */
254 menubar_right (WMenuBar
* menubar
)
256 menubar_remove (menubar
);
257 menubar
->selected
= (menubar
->selected
+ 1) % g_list_length (menubar
->menu
);
258 menubar_draw (menubar
);
261 /* --------------------------------------------------------------------------------------------- */
264 menubar_finish (WMenuBar
* menubar
)
266 menubar
->is_dropped
= FALSE
;
267 menubar
->is_active
= FALSE
;
268 menubar
->widget
.lines
= 1;
269 widget_want_hotkey (menubar
->widget
, 0);
271 dlg_select_by_id (menubar
->widget
.owner
, menubar
->previous_widget
);
275 /* --------------------------------------------------------------------------------------------- */
278 menubar_drop (WMenuBar
* menubar
, unsigned int selected
)
280 menubar
->is_dropped
= TRUE
;
281 menubar
->selected
= selected
;
282 menubar_draw (menubar
);
285 /* --------------------------------------------------------------------------------------------- */
288 menubar_execute (WMenuBar
* menubar
)
290 const Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
291 const menu_entry_t
*entry
= g_list_nth_data (menu
->entries
, menu
->selected
);
293 if ((entry
!= NULL
) && (entry
->command
!= CK_IgnoreKey
))
295 mc_global
.is_right
= (menubar
->selected
!= 0);
296 menubar_finish (menubar
);
297 menubar
->widget
.owner
->callback (menubar
->widget
.owner
, &menubar
->widget
,
298 DLG_ACTION
, entry
->command
, NULL
);
303 /* --------------------------------------------------------------------------------------------- */
306 menubar_down (WMenuBar
* menubar
)
308 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
309 const unsigned int len
= g_list_length (menu
->entries
);
312 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
316 menu
->selected
= (menu
->selected
+ 1) % len
;
317 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
319 while ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
));
321 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
324 /* --------------------------------------------------------------------------------------------- */
327 menubar_up (WMenuBar
* menubar
)
329 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
330 const unsigned int len
= g_list_length (menu
->entries
);
333 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
337 if (menu
->selected
== 0)
338 menu
->selected
= len
- 1;
341 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
343 while ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
));
345 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
348 /* --------------------------------------------------------------------------------------------- */
351 menubar_first (WMenuBar
* menubar
)
353 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
356 if (menu
->selected
== 0)
359 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
365 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
367 if ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
))
373 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
376 /* --------------------------------------------------------------------------------------------- */
379 menubar_last (WMenuBar
* menubar
)
381 Menu
*menu
= g_list_nth_data (menubar
->menu
, menubar
->selected
);
382 const unsigned int len
= g_list_length (menu
->entries
);
385 if (menu
->selected
== len
- 1)
388 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
390 menu
->selected
= len
;
395 entry
= (menu_entry_t
*) g_list_nth_data (menu
->entries
, menu
->selected
);
397 while ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
));
399 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
402 /* --------------------------------------------------------------------------------------------- */
405 menubar_handle_key (WMenuBar
* menubar
, int key
)
409 key
= g_ascii_tolower (key
);
411 if (is_abort_char (key
))
413 menubar_finish (menubar
);
417 /* menubar help or menubar navigation */
422 ev_help_t event_data
= { NULL
, NULL
};
424 if (menubar
->is_dropped
)
426 ((Menu
*) g_list_nth_data (menubar
->menu
, menubar
->selected
))->help_node
;
428 event_data
.node
= "[Menu Bar]";
430 mc_event_raise (MCEVENT_GROUP_CORE
, "help", &event_data
);
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_IgnoreKey
)
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_IgnoreKey
))
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_nwxt (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_nwxt (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 /* --------------------------------------------------------------------------------------------- */