From aa9cb6d3200d2a5aafbe808db4c4a1ae99742614 Mon Sep 17 00:00:00 2001 From: Egmont Koblinger Date: Tue, 12 Oct 2010 12:33:09 +0300 Subject: [PATCH] Ticket #2170: Color collisions Midnight Commander's color/skin engine often reuses the same color definition for multiple elements on the UI. This unnecessarily limits the possibilities when playing with colors. Signed-off-by: Slava Zanko Signed-off-by: Andrew Borodin --- lib/skin.h | 92 ++++++++++++++++-------------- lib/skin/colors.c | 9 +++ lib/tty/color.c | 2 +- misc/skins/darkfar.ini | 9 +++ misc/skins/default.ini | 10 ++++ misc/skins/double-lines.ini | 9 +++ misc/skins/featured.ini | 9 +++ misc/skins/gotar.ini | 9 +++ src/boxes.c | 19 +++---- src/command.c | 5 +- src/dialog.c | 32 +++++------ src/dialog.h | 21 ++++--- src/editor/editcmd_dialogs.c | 8 +-- src/find.c | 15 ++--- src/help.c | 7 ++- src/main.c | 11 ++-- src/panelize.c | 9 +-- src/screen.c | 2 +- src/tree.c | 4 +- src/viewer/display.c | 2 +- src/viewer/hex.c | 10 ++-- src/viewer/nroff.c | 2 +- src/widget.c | 132 ++++++++++++++++++++++++++----------------- src/widget.h | 17 ++++-- src/wtools.c | 11 +--- 25 files changed, 269 insertions(+), 187 deletions(-) diff --git a/lib/skin.h b/lib/skin.h index c55be9954..ce2287dac 100644 --- a/lib/skin.h +++ b/lib/skin.h @@ -21,70 +21,80 @@ #define DISABLED_COLOR mc_skin_color__cache[5] #define REVERSE_COLOR mc_skin_color__cache[6] #define COMMAND_MARK_COLOR mc_skin_color__cache[7] +#define HEADER_COLOR mc_skin_color__cache[8] /* Dialog colors */ -#define COLOR_NORMAL mc_skin_color__cache[8] -#define COLOR_FOCUS mc_skin_color__cache[9] -#define COLOR_HOT_NORMAL mc_skin_color__cache[10] -#define COLOR_HOT_FOCUS mc_skin_color__cache[11] +#define COLOR_NORMAL mc_skin_color__cache[9] +#define COLOR_FOCUS mc_skin_color__cache[10] +#define COLOR_HOT_NORMAL mc_skin_color__cache[11] +#define COLOR_HOT_FOCUS mc_skin_color__cache[12] +#define COLOR_TITLE mc_skin_color__cache[13] /* Error dialog colors */ -#define ERROR_COLOR mc_skin_color__cache[12] -#define ERROR_HOT_NORMAL mc_skin_color__cache[13] -#define ERROR_HOT_FOCUS mc_skin_color__cache[14] +#define ERROR_COLOR mc_skin_color__cache[14] +#define ERROR_FOCUS mc_skin_color__cache[15] +#define ERROR_HOT_NORMAL mc_skin_color__cache[16] +#define ERROR_HOT_FOCUS mc_skin_color__cache[17] +#define ERROR_TITLE mc_skin_color__cache[18] /* Menu colors */ -#define MENU_ENTRY_COLOR mc_skin_color__cache[15] -#define MENU_SELECTED_COLOR mc_skin_color__cache[16] -#define MENU_HOT_COLOR mc_skin_color__cache[17] -#define MENU_HOTSEL_COLOR mc_skin_color__cache[18] -#define MENU_INACTIVE_COLOR mc_skin_color__cache[19] +#define MENU_ENTRY_COLOR mc_skin_color__cache[19] +#define MENU_SELECTED_COLOR mc_skin_color__cache[20] +#define MENU_HOT_COLOR mc_skin_color__cache[21] +#define MENU_HOTSEL_COLOR mc_skin_color__cache[22] +#define MENU_INACTIVE_COLOR mc_skin_color__cache[23] /* * This should be selectable independently. Default has to be black background * foreground does not matter at all. */ -#define GAUGE_COLOR mc_skin_color__cache[20] -#define INPUT_COLOR mc_skin_color__cache[21] -#define INPUT_UNCHANGED_COLOR mc_skin_color__cache[22] -#define INPUT_MARK_COLOR mc_skin_color__cache[23] +#define GAUGE_COLOR mc_skin_color__cache[24] +#define INPUT_COLOR mc_skin_color__cache[25] +#define INPUT_UNCHANGED_COLOR mc_skin_color__cache[26] +#define INPUT_MARK_COLOR mc_skin_color__cache[27] +#define INPUT_HISTORY_COLOR mc_skin_color__cache[28] +#define COMMAND_HISTORY_COLOR mc_skin_color__cache[29] -#define HELP_NORMAL_COLOR mc_skin_color__cache[24] -#define HELP_ITALIC_COLOR mc_skin_color__cache[25] -#define HELP_BOLD_COLOR mc_skin_color__cache[26] -#define HELP_LINK_COLOR mc_skin_color__cache[27] -#define HELP_SLINK_COLOR mc_skin_color__cache[28] +#define HELP_NORMAL_COLOR mc_skin_color__cache[30] +#define HELP_ITALIC_COLOR mc_skin_color__cache[31] +#define HELP_BOLD_COLOR mc_skin_color__cache[32] +#define HELP_LINK_COLOR mc_skin_color__cache[33] +#define HELP_SLINK_COLOR mc_skin_color__cache[34] +#define HELP_TITLE_COLOR mc_skin_color__cache[35] -#define VIEW_UNDERLINED_COLOR mc_skin_color__cache[29] + +#define VIEW_BOLD_COLOR mc_skin_color__cache[36] +#define VIEW_UNDERLINED_COLOR mc_skin_color__cache[37] +#define VIEW_SELECTED_COLOR mc_skin_color__cache[38] /* * editor colors - only 4 for normal, search->found, select, and whitespace * respectively * Last is defined to view color. */ -#define EDITOR_NORMAL_COLOR mc_skin_color__cache[30] -#define EDITOR_BOLD_COLOR mc_skin_color__cache[31] -#define EDITOR_MARKED_COLOR mc_skin_color__cache[32] -#define EDITOR_WHITESPACE_COLOR mc_skin_color__cache[33] -#define EDITOR_RIGHT_MARGIN_COLOR mc_skin_color__cache[34] +#define EDITOR_NORMAL_COLOR mc_skin_color__cache[39] +#define EDITOR_BOLD_COLOR mc_skin_color__cache[40] +#define EDITOR_MARKED_COLOR mc_skin_color__cache[41] +#define EDITOR_WHITESPACE_COLOR mc_skin_color__cache[42] +#define EDITOR_RIGHT_MARGIN_COLOR mc_skin_color__cache[43] /* color of left 8 char status per line */ -#define LINE_STATE_COLOR mc_skin_color__cache[35] -#define BOOK_MARK_COLOR mc_skin_color__cache[36] -#define BOOK_MARK_FOUND_COLOR mc_skin_color__cache[37] +#define LINE_STATE_COLOR mc_skin_color__cache[44] +#define BOOK_MARK_COLOR mc_skin_color__cache[45] +#define BOOK_MARK_FOUND_COLOR mc_skin_color__cache[46] -#define BUTTONBAR_HOTKEY_COLOR mc_skin_color__cache[38] -#define BUTTONBAR_BUTTON_COLOR mc_skin_color__cache[39] +#define BUTTONBAR_HOTKEY_COLOR mc_skin_color__cache[47] +#define BUTTONBAR_BUTTON_COLOR mc_skin_color__cache[48] /* Diff colors */ -#define DFF_ADD_COLOR mc_skin_color__cache[40] -#define DFF_CHG_COLOR mc_skin_color__cache[41] -#define DFF_CHH_COLOR mc_skin_color__cache[42] -#define DFF_CHD_COLOR mc_skin_color__cache[43] -#define DFF_DEL_COLOR mc_skin_color__cache[44] -#define DFF_FOLDER_COLOR mc_skin_color__cache[45] -#define DFF_ERROR_COLOR mc_skin_color__cache[46] - -#define MC_SKIN_COLOR_CACHE_COUNT 47 +#define DFF_ADD_COLOR mc_skin_color__cache[49] +#define DFF_CHG_COLOR mc_skin_color__cache[50] +#define DFF_CHH_COLOR mc_skin_color__cache[51] +#define DFF_CHD_COLOR mc_skin_color__cache[52] +#define DFF_DEL_COLOR mc_skin_color__cache[53] +#define DFF_FOLDER_COLOR mc_skin_color__cache[54] +#define DFF_ERROR_COLOR mc_skin_color__cache[55] + +#define MC_SKIN_COLOR_CACHE_COUNT 56 /*** enums ***************************************************************************************/ diff --git a/lib/skin/colors.c b/lib/skin/colors.c index 039469920..752692c81 100644 --- a/lib/skin/colors.c +++ b/lib/skin/colors.c @@ -204,16 +204,20 @@ mc_skin_color_cache_init (void) MARKED_SELECTED_COLOR = mc_skin_color_get ("core", "markselect"); DISABLED_COLOR = mc_skin_color_get ("core", "disabled"); REVERSE_COLOR = mc_skin_color_get ("core", "reverse"); + HEADER_COLOR = mc_skin_color_get ("core", "header"); COMMAND_MARK_COLOR = mc_skin_color_get ("core", "commandlinemark"); COLOR_NORMAL = mc_skin_color_get ("dialog", "_default_"); COLOR_FOCUS = mc_skin_color_get ("dialog", "dfocus"); COLOR_HOT_NORMAL = mc_skin_color_get ("dialog", "dhotnormal"); COLOR_HOT_FOCUS = mc_skin_color_get ("dialog", "dhotfocus"); + COLOR_TITLE = mc_skin_color_get ("dialog", "dtitle"); ERROR_COLOR = mc_skin_color_get ("error", "_default_"); + ERROR_FOCUS = mc_skin_color_get ("error", "errdfocus"); ERROR_HOT_NORMAL = mc_skin_color_get ("error", "errdhotnormal"); ERROR_HOT_FOCUS = mc_skin_color_get ("error", "errdhotfocus"); + ERROR_TITLE = mc_skin_color_get ("error", "errdtitle"); MENU_ENTRY_COLOR = mc_skin_color_get ("menu", "_default_"); MENU_SELECTED_COLOR = mc_skin_color_get ("menu", "menusel"); @@ -223,6 +227,8 @@ mc_skin_color_cache_init (void) GAUGE_COLOR = mc_skin_color_get ("core", "gauge"); INPUT_COLOR = mc_skin_color_get ("core", "input"); + INPUT_HISTORY_COLOR = mc_skin_color_get ("core", "inputhistory"); + COMMAND_HISTORY_COLOR = mc_skin_color_get ("core", "commandhistory"); INPUT_MARK_COLOR = mc_skin_color_get ("core", "inputmark"); INPUT_UNCHANGED_COLOR = mc_skin_color_get ("core", "inputunchanged"); @@ -231,8 +237,11 @@ mc_skin_color_cache_init (void) HELP_BOLD_COLOR = mc_skin_color_get ("help", "helpbold"); HELP_LINK_COLOR = mc_skin_color_get ("help", "helplink"); HELP_SLINK_COLOR = mc_skin_color_get ("help", "helpslink"); + HELP_TITLE_COLOR = mc_skin_color_get ("help", "helptitle"); + VIEW_BOLD_COLOR = mc_skin_color_get ("viewer", "viewbold"); VIEW_UNDERLINED_COLOR = mc_skin_color_get ("viewer", "viewunderline"); + VIEW_SELECTED_COLOR = mc_skin_color_get ("viewer", "viewselected"); EDITOR_NORMAL_COLOR = mc_skin_color_get ("editor", "_default_"); EDITOR_BOLD_COLOR = mc_skin_color_get ("editor", "editbold"); diff --git a/lib/tty/color.c b/lib/tty/color.c index 0d70702a8..7ff1e86f0 100644 --- a/lib/tty/color.c +++ b/lib/tty/color.c @@ -103,7 +103,7 @@ static int tty_color_get_next__color_pair_number (void) { const size_t cp_count = g_hash_table_size (mc_tty_color__hashtable); - int cp; + size_t cp; for (cp = 0; cp < cp_count; cp++) if (g_hash_table_find (mc_tty_color__hashtable, tty_color_get_next_cpn_cb, diff --git a/misc/skins/darkfar.ini b/misc/skins/darkfar.ini index b4842dc11..20da2ece9 100644 --- a/misc/skins/darkfar.ini +++ b/misc/skins/darkfar.ini @@ -36,17 +36,23 @@ disabled=gray;blue reverse=black;lightgray commandlinemark=black;lightgray + header=yellow;black + inputhistory= + commandhistory= [dialog] _default_=brightcyan;blue dfocus=blue;cyan dhotnormal=white; dhotfocus=white;cyan + dtitle=white; [error] _default_=white;red + errdfocus=black;lightgray errdhotnormal=yellow;red errdhotfocus=yellow;lightgray + errdtitle=yellow;red [filehighlight] directory=white; @@ -77,6 +83,7 @@ helpbold=blue;lightgray helplink=black;cyan helpslink=yellow;blue + helptitle=blue;lightgray [editor] _default_=lightgray;black @@ -89,7 +96,9 @@ editrightmargin=white;blue [viewer] + viewbold=yellow;black viewunderline=brightred;black + viewselected=yellow;cyan [diffviewer] added=white;green diff --git a/misc/skins/default.ini b/misc/skins/default.ini index 503aca82f..6e03a2689 100644 --- a/misc/skins/default.ini +++ b/misc/skins/default.ini @@ -36,17 +36,24 @@ disabled=gray;lightgray reverse=black;lightgray commandlinemark=black;lightgray + header=yellow;blue + inputhistory= + commandhistory= [dialog] _default_=black;lightgray dfocus=black;cyan dhotnormal=blue;lightgray dhotfocus=blue;cyan + dtitle=blue;lightgray [error] _default_=white;red + errdfocus=black;lightgray errdhotnormal=yellow;red + errdtitle=yellow;red errdhotfocus=yellow;lightgray + errdtitle=yellow;red [filehighlight] directory=white; @@ -81,6 +88,7 @@ helpbold=blue;lightgray helplink=black;cyan helpslink=yellow;blue + helptitle=blue;lightgray [editor] _default_=lightgray;blue @@ -93,7 +101,9 @@ editrightmargin=brightblue;black [viewer] + viewbold=yellow;blue viewunderline=brightred;blue + viewselected=yellow;cyan [diffviewer] added=white;green diff --git a/misc/skins/double-lines.ini b/misc/skins/double-lines.ini index e64a1dc33..3ec4c03fa 100644 --- a/misc/skins/double-lines.ini +++ b/misc/skins/double-lines.ini @@ -36,17 +36,23 @@ commandlinemark=black;lightgray disabled=gray;lightgray reverse=black;lightgray + header=yellow;blue + inputhistory= + commandhistory= [dialog] _default_=black;lightgray dfocus=black;cyan dhotnormal=blue;lightgray dhotfocus=blue;cyan + dtitle=blue;lightgray [error] _default_=white;red + errdfocus=black;lightgray errdhotnormal=yellow;red errdhotfocus=yellow;lightgray + errdtitle=yellow;red [filehighlight] directory=white; @@ -77,6 +83,7 @@ helpbold=blue;lightgray helplink=black;cyan helpslink=yellow;blue + helptitle=blue;lightgray [editor] _default_=lightgray;blue @@ -89,7 +96,9 @@ editrightmargin=brightblue;black [viewer] + viewbold=yellow;blue viewunderline=brightred;blue + viewselected=yellow;cyan [diffviewer] added=white;green diff --git a/misc/skins/featured.ini b/misc/skins/featured.ini index 31b1cd16a..04bc49fa8 100644 --- a/misc/skins/featured.ini +++ b/misc/skins/featured.ini @@ -38,17 +38,23 @@ disabled=gray;lightgray reverse=black;lightgray commandlinemark=black;lightgray + header=yellow;blue + inputhistory= + commandhistory= [dialog] _default_=black;lightgray dfocus=black;cyan dhotnormal=blue;lightgray dhotfocus=blue;cyan + dtitle=blue;lightgray [error] _default_=white;red + errdfocus=black;lightgray errdhotnormal=yellow;red errdhotfocus=yellow;lightgray + errdtitle=yellow;red [filehighlight] directory=white; @@ -83,6 +89,7 @@ helpbold=blue;lightgray helplink=black;cyan helpslink=yellow;blue + helptitle=blue;lightgray [editor] _default_=lightgray;blue @@ -95,7 +102,9 @@ editrightmargin=brightblue;black [viewer] + viewbold=yellow;blue viewunderline=brightred;blue + viewselected=yellow;cyan [diffviewer] added=white;green diff --git a/misc/skins/gotar.ini b/misc/skins/gotar.ini index eab29b972..8fd07c42a 100644 --- a/misc/skins/gotar.ini +++ b/misc/skins/gotar.ini @@ -33,17 +33,23 @@ input=brightgreen; disabled=gray;blue reverse=brightgreen;blue + header=brightred; + inputhistory= + commandhistory= [dialog] _default_=brightcyan;blue dfocus=brightred;black dhotnormal=brightred; dhotfocus=yellow;black + dtitle=brightred; [error] _default_=white;red + errdfocus=brightgreen;blue errdhotnormal=yellow; errdhotfocus=yellow;blue + errdtitle=yellow; [filehighlight] directory=brightcyan; @@ -74,6 +80,7 @@ helpbold=brightgreen; helplink=white; helpslink=yellow;blue + helptitle=brightgreen; [editor] _default_=lightgray;black @@ -86,7 +93,9 @@ editrightmargin=brightblue;blue [viewer] + viewbold=brightred;black viewunderline=brightgreen;black + viewselected=yellow;black [diffviewer] _default_=lightgray;black diff --git a/src/boxes.c b/src/boxes.c index 884d4e57d..208c7401f 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -155,13 +155,6 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status) int dlg_width = 48, dlg_height = 15; Dlg_head *dd; - const int input_colors[3] = - { - INPUT_COLOR, - INPUT_UNCHANGED_COLOR, - INPUT_MARK_COLOR - }; - /* Controls whether the array strings have been translated */ const char *displays[LIST_TYPES] = { N_("&Full file list"), @@ -230,14 +223,14 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status) add_widget (dd, cancel_button); add_widget (dd, ok_button); - display_mini_status = input_new (10, 8, (int *) input_colors, dlg_width - 12, _status[radio_sel], + display_mini_status = input_new (10, 8, input_get_default_colors(), dlg_width - 12, _status[radio_sel], "mini-input", INPUT_COMPLETE_DEFAULT); add_widget (dd, display_mini_status); display_check_status = check_new (9, 4, _check_status, user_mini_status); add_widget (dd, display_check_status); - display_user_format = input_new (7, 8, (int *) input_colors, dlg_width - 12, init_text, + display_user_format = input_new (7, 8, input_get_default_colors(), dlg_width - 12, init_text, "user-fmt-input", INPUT_COMPLETE_DEFAULT); add_widget (dd, display_user_format); @@ -1134,16 +1127,18 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, c g_free (title); - in_user = input_new (5, istart, (int *) input_colors, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT); + in_user = input_new (5, istart, input_get_default_colors(), ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT); add_widget (auth_dlg, in_user); - in_domain = input_new (3, istart, (int *) input_colors, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT); + in_domain = + input_new (3, istart, input_get_default_colors(), ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT); add_widget (auth_dlg, in_domain); add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0)); add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0)); - in_password = input_new (7, istart, (int *) input_colors, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT); + in_password = + input_new (7, istart, input_get_default_colors(), ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT); in_password->completion_flags = 0; in_password->is_password = 1; diff --git a/src/command.c b/src/command.c index 019a54f18..ef2272389 100644 --- a/src/command.c +++ b/src/command.c @@ -308,11 +308,12 @@ WInput * command_new (int y, int x, int cols) { WInput *cmd; - const int command_colors[3] = + const input_colors_t command_colors = { DEFAULT_COLOR, DEFAULT_COLOR, - COMMAND_MARK_COLOR + DEFAULT_COLOR, + COMMAND_HISTORY_COLOR }; cmd = input_new (y, x, (int *) command_colors, cols, "", "cmdline", diff --git a/src/dialog.c b/src/dialog.c index a19d39a64..a824ac23c 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -49,8 +49,8 @@ #include "dialog-switch.h" /* Color styles for normal and error dialogs */ -int dialog_colors[4]; -int alarm_colors[4]; +dlg_colors_t dialog_colors; +dlg_colors_t alarm_colors; /* Primitive way to check if the the current dialog is our dialog */ /* This is needed by async routines like load_prompt */ @@ -115,13 +115,13 @@ common_dialog_repaint (Dlg_head *h) space = (h->flags & DLG_COMPACT) ? 0 : 1; - tty_setcolor (DLG_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_NORMAL]); dlg_erase (h); draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space, FALSE); if (h->title != NULL) { - tty_setcolor (DLG_HOT_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_TITLE]); dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2); tty_print_string (h->title); } @@ -273,8 +273,7 @@ create_dlg (gboolean modal, int y1, int x1, int lines, int cols, new_d->modal = modal; if (colors != NULL) { - new_d->color = g_new (int, DLG_COLOR_NUM); - memmove (new_d->color, colors, sizeof (int) * DLG_COLOR_NUM); + memmove (new_d->color, colors, sizeof (dlg_colors_t)); } new_d->help_ctx = help_ctx; new_d->callback = (callback != NULL) ? callback : default_dlg_callback; @@ -306,15 +305,17 @@ create_dlg (gboolean modal, int y1, int x1, int lines, int cols, void dlg_set_default_colors (void) { - dialog_colors[0] = COLOR_NORMAL; - dialog_colors[1] = COLOR_FOCUS; - dialog_colors[2] = COLOR_HOT_NORMAL; - dialog_colors[3] = COLOR_HOT_FOCUS; - - alarm_colors[0] = ERROR_COLOR; - alarm_colors[1] = REVERSE_COLOR; - alarm_colors[2] = ERROR_HOT_NORMAL; - alarm_colors[3] = ERROR_HOT_FOCUS; + dialog_colors[DLG_COLOR_NORMAL] = COLOR_NORMAL; + dialog_colors[DLG_COLOR_FOCUS] = COLOR_FOCUS; + dialog_colors[DLG_COLOR_HOT_NORMAL] = COLOR_HOT_NORMAL; + dialog_colors[DLG_COLOR_HOT_FOCUS] = COLOR_HOT_FOCUS; + dialog_colors[DLG_COLOR_TITLE] = COLOR_TITLE; + + alarm_colors[DLG_COLOR_NORMAL] = ERROR_COLOR; + alarm_colors[DLG_COLOR_FOCUS] = ERROR_FOCUS; + alarm_colors[DLG_COLOR_HOT_NORMAL] = ERROR_HOT_NORMAL; + alarm_colors[DLG_COLOR_HOT_FOCUS] = ERROR_HOT_FOCUS; + alarm_colors[DLG_COLOR_TITLE] = ERROR_TITLE; } void @@ -1090,7 +1091,6 @@ destroy_dlg (Dlg_head * h) dlg_broadcast_msg (h, WIDGET_DESTROY, FALSE); g_list_foreach (h->widgets, (GFunc) g_free, NULL); g_list_free (h->widgets); - g_free (h->color); g_free (h->title); g_free (h); diff --git a/src/dialog.h b/src/dialog.h index 84b51cb59..892c99877 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -127,11 +127,16 @@ typedef char *(*dlg_shortcut_str) (unsigned long command); typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len); /* Dialog color constants */ -#define DLG_COLOR_NUM 4 -#define DLG_NORMALC(h) ((h)->color[0]) -#define DLG_FOCUSC(h) ((h)->color[1]) -#define DLG_HOT_NORMALC(h) ((h)->color[2]) -#define DLG_HOT_FOCUSC(h) ((h)->color[3]) +typedef enum { + DLG_COLOR_NORMAL, + DLG_COLOR_FOCUS, + DLG_COLOR_HOT_NORMAL, + DLG_COLOR_HOT_FOCUS, + DLG_COLOR_TITLE, + DLG_COLOR_COUNT +} dlg_colors_enum_t; + +typedef int dlg_colors_t[DLG_COLOR_COUNT]; struct Dlg_head { @@ -139,7 +144,7 @@ struct Dlg_head gboolean modal; /* type of dialog: modal or not */ dlg_flags_t flags; /* User flags */ const char *help_ctx; /* Name of the help entry */ - int *color; /* Color set. Unused in viewer and editor */ + dlg_colors_t color; /* Color set. Unused in viewer and editor */ char *title; /* Title of the dialog */ /* Set and received by the user */ @@ -168,8 +173,8 @@ struct Dlg_head }; /* Color styles for normal and error dialogs */ -extern int dialog_colors[4]; -extern int alarm_colors[4]; +extern dlg_colors_t dialog_colors; +extern dlg_colors_t alarm_colors; /* Widget callback */ typedef cb_ret_t (*callback_fn) (Widget * widget, widget_msg_t msg, int parm); diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index a301c814c..fcc05efa0 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -312,17 +312,11 @@ int editcmd_dialog_raw_key_query (const char *heading, const char *query, int cancel) { int w = str_term_width1 (query) + 7; - const int input_colors[3] = - { - INPUT_COLOR, - INPUT_UNCHANGED_COLOR, - INPUT_MARK_COLOR - }; struct Dlg_head *raw_dlg = create_dlg (TRUE, 0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb, NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB); - add_widget (raw_dlg, input_new (3 - cancel, w - 5, (int *) input_colors, + add_widget (raw_dlg, input_new (3 - cancel, w - 5, input_get_default_colors(), 2, "", 0, INPUT_COMPLETE_DEFAULT)); add_widget (raw_dlg, label_new (3 - cancel, 2, query)); if (cancel) diff --git a/src/find.c b/src/find.c index dee415f9c..6488ff56a 100644 --- a/src/find.c +++ b/src/find.c @@ -384,13 +384,6 @@ find_parameters (char **start_dir, char **pattern, char **content) const char *buts[] = { N_("&OK"), N_("&Cancel"), N_("&Tree") }; - const int input_colors[3] = - { - INPUT_COLOR, - INPUT_UNCHANGED_COLOR, - INPUT_MARK_COLOR - }; - int b0, b1, b2; #ifdef ENABLE_NLS @@ -474,19 +467,19 @@ find_parameters (char **start_dir, char **pattern, char **content) file_case_sens_cbox = check_new (7, 3, options.file_case_sens, file_case_label); add_widget (find_dlg, file_case_sens_cbox); - in_with = input_new (6, FIND_X / 2 + 1, (int *) input_colors, FIND_X / 2 - 4, INPUT_LAST_TEXT, + in_with = input_new (6, FIND_X / 2 + 1, input_get_default_colors(), FIND_X / 2 - 4, INPUT_LAST_TEXT, MC_HISTORY_SHARED_SEARCH, INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_with); add_widget (find_dlg, label_new (5, FIND_X / 2 + 1, _("Content:"))); - in_name = input_new (6, 3, (int *) input_colors, + in_name = input_new (6, 3, input_get_default_colors(), FIND_X / 2 - 4, INPUT_LAST_TEXT, "name", INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_name); add_widget (find_dlg, label_new (5, 3, _("File name:"))); add_widget (find_dlg, button_new (3, FIND_X - b2 - 2, B_TREE, NORMAL_BUTTON, buts[2], 0)); - in_start = input_new (3, 3, (int *) input_colors, + in_start = input_new (3, 3, input_get_default_colors(), FIND_X - b2 - 6, in_start_dir, "start", INPUT_COMPLETE_DEFAULT); add_widget (find_dlg, in_start); add_widget (find_dlg, label_new (2, 3, _("Start at:"))); @@ -1035,7 +1028,7 @@ do_search (struct Dlg_head *h) if (verbose) { pos = (pos + 1) % 4; - tty_setcolor (DLG_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_NORMAL]); dlg_move (h, FIND2_Y - 7, FIND2_X - 4); tty_print_char (rotating_dash[pos]); mc_refresh (); diff --git a/src/help.c b/src/help.c index 928564cab..b5f4e1781 100644 --- a/src/help.c +++ b/src/help.c @@ -949,11 +949,12 @@ mousedispatch_new (int y, int x, int yl, int xl) void interactive_display (const char *filename, const char *node) { - const int help_colors[DLG_COLOR_NUM] = { + const dlg_colors_t help_colors = { HELP_NORMAL_COLOR, /* common text color */ 0, /* unused in help */ - HELP_BOLD_COLOR, /* title color */ - 0 /* unused in help */ + HELP_BOLD_COLOR, /* bold text color */ + 0, /* unused in help */ + HELP_TITLE_COLOR /* title color */ }; WButtonBar *help_bar; diff --git a/src/main.c b/src/main.c index 51ea2c85f..66e6b054b 100644 --- a/src/main.c +++ b/src/main.c @@ -1785,11 +1785,12 @@ mc_maybe_editor_or_viewer (void) static void do_nc (void) { - int midnight_colors[DLG_COLOR_NUM]; - midnight_colors[0] = mc_skin_color_get ("dialog", "_default_"); - midnight_colors[1] = mc_skin_color_get ("dialog", "focus"); - midnight_colors[2] = mc_skin_color_get ("dialog", "hotnormal"); - midnight_colors[3] = mc_skin_color_get ("dialog", "hotfocus"); + dlg_colors_t midnight_colors; + midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_"); + midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus"); + midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal"); + midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus"); + midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title"); panel_init (); diff --git a/src/panelize.c b/src/panelize.c index 02cda625b..3c944bea1 100644 --- a/src/panelize.c +++ b/src/panelize.c @@ -132,13 +132,6 @@ panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void static void init_panelize (void) { - const int input_colors[3] = - { - INPUT_COLOR, - INPUT_UNCHANGED_COLOR, - INPUT_MARK_COLOR - }; - int i, panelize_cols = COLS - 6; struct panelize *current = panelize; @@ -183,7 +176,7 @@ init_panelize (void) panelize_but[i].flags, panelize_but[i].text, 0)); pname = - input_new (UY + 14, UX, (int *) input_colors, + input_new (UY + 14, UX, input_get_default_colors(), panelize_dlg->cols - 10, "", "in", INPUT_COMPLETE_DEFAULT); add_widget (panelize_dlg, pname); diff --git a/src/screen.c b/src/screen.c index 8663cdff3..dda523e6c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1548,7 +1548,7 @@ paint_frame (WPanel * panel) g_string_append (format_txt, "]"); } - tty_setcolor (MARKED_COLOR); + tty_setcolor (HEADER_COLOR); tty_print_string (str_fit_to_term (format_txt->str, format->field_len, J_CENTER_LEFT)); width -= format->field_len; diff --git a/src/tree.c b/src/tree.c index 9aed068c7..5dcdfac17 100644 --- a/src/tree.c +++ b/src/tree.c @@ -71,8 +71,8 @@ #define tlines(t) (t->is_panel ? t->widget.lines - 2 - (show_mini_info ? 2 : 0) : t->widget.lines) /* Use the color of the parent widget for the unselected entries */ -#define TREE_NORMALC(h) (DLG_NORMALC (h)) -#define TREE_CURRENTC(h) (DLG_FOCUSC (h)) +#define TREE_NORMALC(h) (h->color[DLG_COLOR_NORMAL]) +#define TREE_CURRENTC(h) (h->color[DLG_COLOR_FOCUS]) /* Specifies the display mode: 1d or 2d */ static gboolean tree_navigation_flag = FALSE; diff --git a/src/viewer/display.c b/src/viewer/display.c index b8086daf4..d43173268 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -364,7 +364,7 @@ mcview_display_ruler (mcview_t * view) if (ruler == RULER_NONE || height < 1) return; - tty_setcolor (MARKED_COLOR); + tty_setcolor (VIEW_BOLD_COLOR); for (c = 0; c < width; c++) { cl = view->dpy_text_column + c; diff --git a/src/viewer/hex.c b/src/viewer/hex.c index 4440bacf0..16827bd6e 100644 --- a/src/viewer/hex.c +++ b/src/viewer/hex.c @@ -162,7 +162,7 @@ mcview_display_hex (mcview_t * view) /* Print the hex offset */ g_snprintf (hex_buff, sizeof (hex_buff), "%08jX ", (uintmax_t) from); widget_move (view, top + row, left); - tty_setcolor (MARKED_COLOR); + tty_setcolor (VIEW_BOLD_COLOR); for (i = 0; col < width && hex_buff[i] != '\0'; i++) { tty_print_char (hex_buff[i]); @@ -230,10 +230,10 @@ mcview_display_hex (mcview_t * view) /* Select the color for the hex number */ tty_setcolor (boldflag == MARK_NORMAL ? NORMAL_COLOR : - boldflag == MARK_SELECTED ? MARKED_COLOR : + boldflag == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag == MARK_CURSOR */ - view->hexview_in_text ? MARKED_SELECTED_COLOR : VIEW_UNDERLINED_COLOR); + view->hexview_in_text ? VIEW_SELECTED_COLOR : VIEW_UNDERLINED_COLOR); /* Print the hex number */ widget_move (view, top + row, left + col); @@ -277,10 +277,10 @@ mcview_display_hex (mcview_t * view) /* Select the color for the character; this differs from the * hex color when boldflag == MARK_CURSOR */ tty_setcolor (boldflag == MARK_NORMAL ? NORMAL_COLOR : - boldflag == MARK_SELECTED ? MARKED_COLOR : + boldflag == MARK_SELECTED ? VIEW_BOLD_COLOR : boldflag == MARK_CHANGED ? VIEW_UNDERLINED_COLOR : /* boldflag == MARK_CURSOR */ - view->hexview_in_text ? VIEW_UNDERLINED_COLOR : MARKED_SELECTED_COLOR); + view->hexview_in_text ? VIEW_SELECTED_COLOR : MARKED_SELECTED_COLOR); #ifdef HAVE_CHARSET diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c index 93ec40ca9..b55d47677 100644 --- a/src/viewer/nroff.c +++ b/src/viewer/nroff.c @@ -134,7 +134,7 @@ mcview_display_nroff (mcview_t * view) && (c_next != '_' || mcview_count_backspaces (view, from + 1) == 1)) tty_setcolor (VIEW_UNDERLINED_COLOR); else - tty_setcolor (MARKED_COLOR); + tty_setcolor (VIEW_BOLD_COLOR); continue; } } diff --git a/src/widget.c b/src/widget.c index 0a868d727..7b4443349 100644 --- a/src/widget.c +++ b/src/widget.c @@ -74,16 +74,16 @@ widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey) else if (hotkey) { if (focused) - color = DLG_HOT_FOCUSC (h); + color = h->color[DLG_COLOR_HOT_FOCUS]; else - color = DLG_HOT_NORMALC (h); + color = h->color[DLG_COLOR_HOT_NORMAL]; } else { if (focused) - color = DLG_FOCUSC (h); + color = h->color[DLG_COLOR_FOCUS]; else - color = DLG_NORMALC (h); + color = h->color[DLG_COLOR_NORMAL]; } tty_setcolor (color); @@ -767,7 +767,7 @@ label_callback (Widget * w, widget_msg_t msg, int parm) if (l->transparent) tty_setcolor (disabled ? DISABLED_COLOR : DEFAULT_COLOR); else - tty_setcolor (disabled ? DISABLED_COLOR : DLG_NORMALC (h)); + tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]); for (;;) { @@ -883,7 +883,7 @@ hline_callback (Widget * w, widget_msg_t msg, int parm) if (l->transparent) tty_setcolor (DEFAULT_COLOR); else - tty_setcolor (DLG_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2); @@ -937,7 +937,7 @@ gauge_callback (Widget * w, widget_msg_t msg, int parm) if (msg == WIDGET_DRAW) { widget_move (&g->widget, 0, 0); - tty_setcolor (DLG_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_NORMAL]); if (!g->shown) tty_printf ("%*s", gauge_len, ""); else @@ -964,16 +964,16 @@ gauge_callback (Widget * w, widget_msg_t msg, int parm) { tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", (int) columns, ""); - tty_setcolor (DLG_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("%*s] %3d%%", (int) (gauge_len - 7 - columns), "", (int) percentage); } else { - tty_setcolor (DLG_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("%*s", gauge_len - columns - 7, ""); tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", columns, ""); - tty_setcolor (DLG_NORMALC (h)); + tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("] %3d%%", 100 * columns / (gauge_len - 7), percentage); } } @@ -1029,9 +1029,9 @@ gauge_new (int y, int x, int shown, int max, int current) #define LARGE_HISTORY_BUTTON 1 #ifdef LARGE_HISTORY_BUTTON -# define HISTORY_BUTTON_WIDTH 3 +#define HISTORY_BUTTON_WIDTH 3 #else -# define HISTORY_BUTTON_WIDTH 1 +#define HISTORY_BUTTON_WIDTH 1 #endif #define should_show_history_button(in) \ @@ -1045,20 +1045,16 @@ draw_history_button (WInput * in) c = in->history->next ? (in->history->prev ? '|' : 'v') : '^'; widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH); + tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]); #ifdef LARGE_HISTORY_BUTTON { Dlg_head *h; h = in->widget.owner; - tty_setcolor (disabled ? DISABLED_COLOR : NORMAL_COLOR); tty_print_string ("[ ]"); - /* Too distracting: tty_setcolor (MARKED_COLOR); */ widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH + 1); - tty_print_char (c); } -#else - tty_setcolor (disabled ? DISABLED_COLOR : MARKED_COLOR); - tty_print_char (c); #endif + tty_print_char (c); } /* }}} history button */ @@ -1158,9 +1154,9 @@ update_input (WInput * in, int clear_first) if ((((Widget *) in)->options & W_DISABLED) != 0) tty_setcolor (DISABLED_COLOR); else if (in->first) - tty_setcolor (in->unchanged_color); + tty_setcolor (in->color[WINPUTC_UNCHANGED]); else - tty_setcolor (in->color); + tty_setcolor (in->color[WINPUTC_MAIN]); widget_move (&in->widget, 0, 0); @@ -1176,20 +1172,26 @@ update_input (WInput * in, int clear_first) long m1, m2; if (input_eval_marks (in, &m1, &m2)) { - tty_setcolor (in->color); - cp = str_term_substring (in->buffer, in->term_first_shown, in->field_width - has_history); + tty_setcolor (in->color[WINPUTC_MAIN]); + cp = str_term_substring (in->buffer, in->term_first_shown, + in->field_width - has_history); tty_print_string (cp); - tty_setcolor (in->mark_color); + tty_setcolor (in->color[WINPUTC_MARK]); if (m1 < in->term_first_shown) { widget_move (&in->widget, 0, 0); - tty_print_string (str_term_substring (in->buffer, in->term_first_shown, m2 - in->term_first_shown)); + tty_print_string (str_term_substring + (in->buffer, in->term_first_shown, + m2 - in->term_first_shown)); } else { int sel_width; widget_move (&in->widget, 0, m1 - in->term_first_shown); - sel_width = min (m2 - m1, (in->field_width - has_history) - (str_term_width2 (in->buffer, m1) - in->term_first_shown)); + sel_width = + min (m2 - m1, + (in->field_width - has_history) - (str_term_width2 (in->buffer, m1) - + in->term_first_shown)); tty_print_string (str_term_substring (in->buffer, m1, sel_width)); } } @@ -1202,7 +1204,7 @@ update_input (WInput * in, int clear_first) { if (i >= 0) { - tty_setcolor (in->color); + tty_setcolor (in->color[WINPUTC_MAIN]); tty_print_char ((cp[0] != '\0') ? '*' : ' '); } if (cp[0] != '\0') @@ -1809,6 +1811,7 @@ key_ctrl_right (WInput * in) { forward_word (in); } + static void backward_delete (WInput * in) { @@ -2041,13 +2044,12 @@ input_execute_cmd (WInput * in, unsigned long command) command == CK_InputRightHighlight || command == CK_InputWordLeftHighlight || command == CK_InputWordRightHighlight || - command == CK_InputBolHighlight || - command == CK_InputEolHighlight) + command == CK_InputBolHighlight || command == CK_InputEolHighlight) { if (!in->highlight) { - input_mark_cmd (in, FALSE); /* clear */ - input_mark_cmd (in, TRUE); /* marking on */ + input_mark_cmd (in, FALSE); /* clear */ + input_mark_cmd (in, TRUE); /* marking on */ } } @@ -2170,8 +2172,7 @@ input_execute_cmd (WInput * in, unsigned long command) command != CK_InputRightHighlight && command != CK_InputWordLeftHighlight && command != CK_InputWordRightHighlight && - command != CK_InputBolHighlight && - command != CK_InputEolHighlight) + command != CK_InputBolHighlight && command != CK_InputEolHighlight) { in->highlight = FALSE; } @@ -2356,6 +2357,32 @@ input_event (Gpm_Event * event, void *data) return MOU_NORMAL; } +/** Get default colors for WInput widget. + * @returns default colors + */ +int * +input_get_default_colors (void) +{ + static input_colors_t standart_colors; + + standart_colors[WINPUTC_MAIN] = INPUT_COLOR; + standart_colors[WINPUTC_MARK] = INPUT_MARK_COLOR; + standart_colors[WINPUTC_UNCHANGED] = INPUT_UNCHANGED_COLOR; + standart_colors[WINPUTC_HISTORY] = INPUT_HISTORY_COLOR; + + return standart_colors; +} + +/** Create new instance of WInput object. + * @param y Y coordinate + * @param x X coordinate + * @param input_colors Array of used colors + * @param width Widget width + * @param def_text Default text filled in widget + * @param histname Name of history + * @param completion_flags Flags for specify type of completions + * @returns WInput object + */ WInput * input_new (int y, int x, int *input_colors, int width, const char *def_text, const char *histname, INPUT_COMPLETE_FLAGS completion_flags) @@ -2390,9 +2417,9 @@ input_new (int y, int x, int *input_colors, int width, const char *def_text, in->completion_flags = completion_flags; in->current_max_size = initial_buffer_len; in->buffer = g_new (char, initial_buffer_len); - in->color = input_colors[0]; - in->unchanged_color = input_colors[1]; - in->mark_color = input_colors[2]; + + memmove (in->color, input_colors, sizeof (input_colors_t)); + in->field_width = width; in->first = TRUE; in->highlight = FALSE; @@ -2464,8 +2491,8 @@ listbox_draw (WListbox * l, gboolean focused) { const Dlg_head *h = l->widget.owner; const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0; - const int normalc = disabled ? DISABLED_COLOR : DLG_NORMALC (h); - int selc = disabled ? DISABLED_COLOR : focused ? DLG_HOT_FOCUSC (h) : DLG_FOCUSC (h); + const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]; + int selc = disabled ? DISABLED_COLOR : focused ? h->color[DLG_COLOR_HOT_FOCUS] : h->color[DLG_COLOR_FOCUS]; GList *le; int pos; @@ -3027,7 +3054,7 @@ buttonbar_call (WButtonBar * bb, int i) /* calculate positions of buttons; width is never less than 7 */ static void -buttonbar_init_button_positions (WButtonBar *bb) +buttonbar_init_button_positions (WButtonBar * bb) { int i; int pos = 0; @@ -3074,7 +3101,7 @@ buttonbar_init_button_positions (WButtonBar *bb) /* return width of one button */ static int -buttonbar_get_button_width (const WButtonBar *bb, int i) +buttonbar_get_button_width (const WButtonBar * bb, int i) { if (i == 0) return bb->labels[0].end_coord; @@ -3082,7 +3109,7 @@ buttonbar_get_button_width (const WButtonBar *bb, int i) } static int -buttonbar_get_button_by_x_coord (const WButtonBar *bb, int x) +buttonbar_get_button_by_x_coord (const WButtonBar * bb, int x) { int i; @@ -3242,18 +3269,21 @@ groupbox_callback (Widget * w, widget_msg_t msg, int parm) return MSG_NOT_HANDLED; case WIDGET_DRAW: - { - gboolean disabled = (w->options & W_DISABLED) != 0; - tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL); - draw_box (g->widget.owner, g->widget.y - g->widget.owner->y, - g->widget.x - g->widget.owner->x, g->widget.lines, g->widget.cols, TRUE); + { + gboolean disabled = (w->options & W_DISABLED) != 0; + tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL); + draw_box (g->widget.owner, g->widget.y - g->widget.owner->y, + g->widget.x - g->widget.owner->x, g->widget.lines, g->widget.cols, TRUE); - tty_setcolor (disabled ? DISABLED_COLOR : COLOR_HOT_NORMAL); - dlg_move (g->widget.owner, g->widget.y - g->widget.owner->y, - g->widget.x - g->widget.owner->x + 1); - tty_print_string (g->title); - return MSG_HANDLED; - } + if (g->title != NULL) + { + tty_setcolor (disabled ? DISABLED_COLOR : COLOR_TITLE); + dlg_move (g->widget.owner, g->widget.y - g->widget.owner->y, + g->widget.x - g->widget.owner->x + 1); + tty_print_string (g->title); + } + return MSG_HANDLED; + } case WIDGET_DESTROY: g_free (g->title); diff --git a/src/widget.h b/src/widget.h index 8403fc561..2bcd13987 100644 --- a/src/widget.h +++ b/src/widget.h @@ -99,17 +99,25 @@ void history_put (const char *input_name, GList *h); * function, as position of history dialog depends on widget's position */ char *show_hist (GList **history, Widget *widget); +typedef enum { + WINPUTC_MAIN, /* color used */ + WINPUTC_MARK, /* color for marked text */ + WINPUTC_UNCHANGED, /* color for inactive text (Is first keystroke) */ + WINPUTC_HISTORY, /* color for history list */ + WINPUTC_COUNT_COLORS /* count of used colors */ +} input_colors_enum_t; + +typedef int input_colors_t[WINPUTC_COUNT_COLORS]; + typedef struct { Widget widget; - int point; /* cursor position in the input line in characters */ + int point; /* cursor position in the input line in characters */ int mark; /* The mark position in characters */ gboolean highlight; /* There is a selected block */ int term_first_shown; /* column of the first shown character */ size_t current_max_size; /* Maximum length of input line (bytes) */ int field_width; /* width of the editing field */ - int color; /* color used */ - int mark_color; /* color for marked text */ - int unchanged_color; /* color for inactive text (Is first keystroke) */ + input_colors_t color; gboolean first; /* Is first keystroke? */ int disable_update; /* Do we want to skip updates? */ int is_password; /* Is this a password input line? */ @@ -208,6 +216,7 @@ WButtonBar *buttonbar_new (gboolean visible); WGroupbox *groupbox_new (int y, int x, int height, int width, const char *title); /* Input lines */ +int *input_get_default_colors (void); void winput_set_origin (WInput *i, int x, int field_width); cb_ret_t handle_char (WInput *in, int c_code); int is_in_input_map (WInput *in, int c_code); diff --git a/src/wtools.c b/src/wtools.c index 7f0cd7408..a0219c475 100644 --- a/src/wtools.c +++ b/src/wtools.c @@ -49,11 +49,12 @@ Listbox * create_listbox_window_centered (int center_y, int center_x, int lines, int cols, const char *title, const char *help) { - const int listbox_colors[DLG_COLOR_NUM] = { + const dlg_colors_t listbox_colors = { MENU_ENTRY_COLOR, MENU_SELECTED_COLOR, MENU_HOT_COLOR, MENU_HOTSEL_COLOR, + COLOR_TITLE }; const int space = 4; @@ -375,12 +376,6 @@ quick_dialog_skip (QuickDialog * qd, int nskip) WRadio *r; int return_val; - const int input_colors[3] = { - INPUT_COLOR, - INPUT_UNCHANGED_COLOR, - INPUT_MARK_COLOR - }; - I18N (qd->title); if ((qd->xpos == -1) || (qd->ypos == -1)) @@ -415,7 +410,7 @@ quick_dialog_skip (QuickDialog * qd, int nskip) break; case quick_input: - in = input_new (ypos, xpos, (int *) input_colors, + in = input_new (ypos, xpos, input_get_default_colors(), qw->u.input.len, qw->u.input.text, qw->u.input.histname, INPUT_COMPLETE_DEFAULT); in->is_password = (qw->u.input.flags == 1); -- 2.11.4.GIT