From bc446f0cee7d12cd7790b4ab70781483dba846d4 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Thu, 7 Jul 2005 19:34:55 +0000 Subject: [PATCH] * dialog.h: Replaced object-like macros with implicit references to an identifier ``h'' with function-like macros. Adjusted all users. * dialog.c: Likewise. * find.c: Likewise. * tree.c: Likewise. * widget.c: Likewise. * widget.c (widget_selectcolor): New function that selects a color among DLG_{HOT_,}{FOCUS,NORMAL}C. --- src/ChangeLog | 12 ++++++++++++ src/dialog.c | 4 ++-- src/dialog.h | 8 ++++---- src/find.c | 2 +- src/tree.c | 12 ++++++------ src/widget.c | 48 ++++++++++++++++++++++++++++++------------------ 6 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index fa0678384..afde3720c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2005-07-07 Roland Illig + + * dialog.h: Replaced object-like macros with implicit references + to an identifier ``h'' with function-like macros. Adjusted all + users. + * dialog.c: Likewise. + * find.c: Likewise. + * tree.c: Likewise. + * widget.c: Likewise. + * widget.c (widget_selectcolor): New function that selects a + color among DLG_{HOT_,}{FOCUS,NORMAL}C. + 2005-07-07 Roland Illig * view.c (view_compute_areas): Fixed a bug noted by Pavel diff --git a/src/dialog.c b/src/dialog.c index 3c56e6716..cc8711e5d 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -160,12 +160,12 @@ common_dialog_repaint (struct Dlg_head *h) space = (h->flags & DLG_COMPACT) ? 0 : 1; - attrset (NORMALC); + attrset (DLG_NORMALC (h)); dlg_erase (h); draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space); if (h->title) { - attrset (HOT_NORMALC); + attrset (DLG_HOT_NORMALC (h)); dlg_move (h, space, (h->cols - strlen (h->title)) / 2); addstr (h->title); } diff --git a/src/dialog.h b/src/dialog.h index 6f4d638e0..43e14c825 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -22,10 +22,10 @@ #include "mouse.h" /* Color constants */ -#define FOCUSC h->color[1] -#define NORMALC h->color[0] -#define HOT_NORMALC h->color[2] -#define HOT_FOCUSC h->color[3] +#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]) /* Common return values */ #define B_EXIT 0 diff --git a/src/find.c b/src/find.c index 42f402ae4..fcb452bdd 100644 --- a/src/find.c +++ b/src/find.c @@ -719,7 +719,7 @@ do_search (struct Dlg_head *h) if (verbose){ pos = (pos + 1) % 4; - attrset (NORMALC); + attrset (DLG_NORMALC (h)); dlg_move (h, FIND2_Y-6, FIND2_X - 4); addch (rotating_dash [pos]); mc_refresh (); diff --git a/src/tree.c b/src/tree.c index a38553de5..d4c826d27 100644 --- a/src/tree.c +++ b/src/tree.c @@ -54,7 +54,7 @@ extern int command_prompt; /* Use the color of the parent widget for the unselected entries */ -#define TREE_NORMALC NORMALC +#define TREE_NORMALC(h) (DLG_NORMALC (h)) /* Specifies the display mode: 1d or 2d */ static int tree_navigation_flag; @@ -171,13 +171,13 @@ static void tree_show_mini_info (WTree *tree, int tree_lines, int tree_cols) if (tree->searching){ /* Show search string */ - attrset (TREE_NORMALC); - attrset (FOCUSC); + attrset (TREE_NORMALC (h)); + attrset (DLG_FOCUSC (h)); addch (PATH_SEP); addstr ((char *) name_trunc (tree->search_buffer, tree_cols-2)); addch (' '); - attrset (FOCUSC); + attrset (DLG_FOCUSC (h)); } else { /* Show full name of selected directory */ addstr ((char *) name_trunc (tree->selected_ptr->name, tree_cols)); @@ -197,7 +197,7 @@ static void show_tree (WTree *tree) tree_lines = tlines (tree); tree_cols = tree->widget.cols; - attrset (TREE_NORMALC); + attrset (TREE_NORMALC (h)); widget_move ((Widget*)tree, y, x); if (tree->is_panel){ tree_cols -= 2; @@ -306,7 +306,7 @@ static void show_tree (WTree *tree) addch (' '); /* Return to normal color */ - attrset (TREE_NORMALC); + attrset (TREE_NORMALC (h)); /* Calculate the next value for current */ current = current->next; diff --git a/src/widget.c b/src/widget.c index 34915e2bf..299971a98 100644 --- a/src/widget.c +++ b/src/widget.c @@ -66,6 +66,20 @@ static int button_event (Gpm_Event *event, void *); int quote = 0; +static void +widget_selectcolor (Widget *w, gboolean focused, gboolean hotkey) +{ + Dlg_head *h = w->parent; + + attrset (hotkey + ? (focused + ? DLG_HOT_FOCUSC (h) + : DLG_HOT_NORMALC (h)) + : (focused + ? DLG_FOCUSC (h) + : DLG_NORMALC (h))); +} + static cb_ret_t button_callback (Widget *w, widget_msg_t msg, int parm) { @@ -159,14 +173,14 @@ button_callback (Widget *w, widget_msg_t msg, int parm) break; } - attrset ((b->selected) ? FOCUSC : NORMALC); - widget_move (&b->widget, 0, 0); + widget_selectcolor (w, b->selected, FALSE); + widget_move (w, 0, 0); addstr (buf); if (b->hotpos >= 0) { - attrset ((b->selected) ? HOT_FOCUSC : HOT_NORMALC); - widget_move (&b->widget, 0, b->hotpos + off); + widget_selectcolor (w, b->selected, TRUE); + widget_move (w, 0, b->hotpos + off); addch ((unsigned char) b->text[b->hotpos]); } return MSG_HANDLED; @@ -342,18 +356,16 @@ radio_callback (Widget *w, widget_msg_t msg, int parm) case WIDGET_DRAW: for (i = 0; i < r->count; i++) { register const char *cp; - attrset ((i == r->pos - && msg == WIDGET_FOCUS) ? FOCUSC : NORMALC); + const gboolean focused = (i == r->pos && msg == WIDGET_FOCUS); + widget_selectcolor (w, focused, FALSE); widget_move (&r->widget, i, 0); printw ("(%c) ", (r->sel == i) ? '*' : ' '); for (cp = r->texts[i]; *cp; cp++) { if (*cp == '&') { - attrset ((i == r->pos && msg == WIDGET_FOCUS) - ? HOT_FOCUSC : HOT_NORMALC); + widget_selectcolor (w, focused, TRUE); addch (*++cp); - attrset ((i == r->pos - && msg == WIDGET_FOCUS) ? FOCUSC : NORMALC); + widget_selectcolor (w, focused, FALSE); } else addch (*cp); } @@ -449,12 +461,12 @@ check_callback (Widget *w, widget_msg_t msg, int parm) case WIDGET_FOCUS: case WIDGET_UNFOCUS: case WIDGET_DRAW: - attrset ((msg == WIDGET_FOCUS) ? FOCUSC : NORMALC); + widget_selectcolor (w, msg == WIDGET_FOCUS, FALSE); widget_move (&c->widget, 0, 0); printw ("[%c] %s", (c->state & C_BOOL) ? 'x' : ' ', c->text); if (c->hotpos >= 0) { - attrset ((msg == WIDGET_FOCUS) ? HOT_FOCUSC : HOT_NORMALC); + widget_selectcolor (w, msg == WIDGET_FOCUS, TRUE); widget_move (&c->widget, 0, +c->hotpos + 4); addch ((unsigned char) c->text[c->hotpos]); } @@ -549,7 +561,7 @@ label_callback (Widget *w, widget_msg_t msg, int parm) if (l->transparent) attrset (DEFAULT_COLOR); else - attrset (NORMALC); + attrset (DLG_NORMALC (h)); for (;;) { int xlen; @@ -649,7 +661,7 @@ gauge_callback (Widget *w, widget_msg_t msg, int parm) if (msg == WIDGET_DRAW){ widget_move (&g->widget, 0, 0); - attrset (NORMALC); + attrset (DLG_NORMALC (h)); if (!g->shown) printw ("%*s", gauge_len, ""); else { @@ -671,7 +683,7 @@ gauge_callback (Widget *w, widget_msg_t msg, int parm) addch ('['); attrset (GAUGE_COLOR); printw ("%*s", (int) columns, ""); - attrset (NORMALC); + attrset (DLG_NORMALC (h)); printw ("%*s] %3d%%", (int)(gauge_len - 7 - columns), "", (int) percentage); } return MSG_HANDLED; @@ -1738,14 +1750,14 @@ listbox_draw (WListbox *l, int focused) int i; int sel_line; Dlg_head *h = l->widget.parent; - int normalc = NORMALC; + int normalc = DLG_NORMALC (h); int selc; const char *text; if (focused){ - selc = FOCUSC; + selc = DLG_FOCUSC (h); } else { - selc = HOT_FOCUSC; + selc = DLG_HOT_FOCUSC (h); } sel_line = -1;