Changeset 31

Show
Ignore:
Timestamp:
04/06/07 07:20:40 (2 years ago)
Author:
takkaria
Message:

Reformat code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ui.c

    r30 r31  
    77 * incorporate modifications in all Angband variants as defined in the 
    88 * Angband variants FAQ. See rec.games.roguelike.angband for FAQ. 
    9  */  
     9 */ 
    1010 
    1111/* 
     
    4848/* forward declarations */ 
    4949static void display_menu_row(menu_type *menu, int pos, int top, 
    50                                                         bool cursor, int row, int col, int width); 
     50                                                        bool cursor, int row, int col, int width); 
    5151 
    5252/* =================== GEOMETRY ================= */ 
     
    5757        int w = loc->width; 
    5858        int h = loc->page_rows; 
    59         if(loc->width <= 0 || loc->page_rows <= 0) { 
     59 
     60        if (loc->width <= 0 || loc->page_rows <= 0) 
     61        { 
    6062                Term_get_size(&w, &h); 
    61                 if(loc->width <= 0) w -= loc->width; 
    62                 if(loc->page_rows <= 0) h -= loc->page_rows; 
    63         } 
    64         for(i = 0; i < h; i++) { 
    65                Term_erase(loc->col, loc->row+i, w); 
    66         } 
     63                if (loc->width <= 0) w -= loc->width; 
     64                if (loc->page_rows <= 0) h -= loc->page_rows; 
     65        } 
     66 
     67        for (i = 0; i < h; i++) 
     68               Term_erase(loc->col, loc->row + i, w); 
    6769} 
    6870 
    6971bool region_inside(const region *loc, const key_event *key) 
    7072{ 
    71         if((loc->col > key->mousex) || (loc->col + loc->width <= key->mousex)) 
     73        if ((loc->col > key->mousex) || (loc->col + loc->width <= key->mousex)) 
    7274                return FALSE; 
    73         if((loc->row > key->mousey) || (loc->row + loc->page_rows <= key->mousey)) 
     75 
     76        if ((loc->row > key->mousey) || (loc->row + loc->page_rows <= key->mousey)) 
    7477                return FALSE; 
     78 
    7579        return TRUE; 
    7680} 
     
    8993{ 
    9094        key_event stop = { EVT_STOP }; 
     95 
    9196        /* Stop right away! */ 
    9297        Term_event_push(&stop); 
     
    105110 *    The first unhandled event - forever is false. 
    106111 */ 
    107 key_event run_event_loop(event_target *target, bool forever, const key_event *start) 
     112key_event run_event_loop(event_target * target, bool forever, const key_event *start) 
    108113{ 
    109114        key_event ke; 
    110115        bool handled = TRUE; 
    111         while (forever || handled) { 
     116 
     117        while (forever || handled) 
     118        { 
    112119                listener_list *list = target->observers; 
    113120                handled = FALSE; 
    114                 if(start) ke = *start; 
     121 
     122                if (start) ke = *start; 
    115123                else ke = inkey_ex(); 
    116                 if(ke.type == EVT_STOP) 
     124 
     125                if (ke.type == EVT_STOP) 
    117126                        break; 
    118127 
    119                 if(ke.type & target->self.events.evt_flags)  
     128                if (ke.type & target->self.events.evt_flags) 
    120129                        handled = target->self.handler(target->self.object, &ke); 
    121130 
    122                 if(!target->is_modal) { 
    123                         while(list && !handled) { 
    124                                 if(ke.type & list->listener->events.evt_flags) { 
     131                if (!target->is_modal) 
     132                { 
     133                        while (list && !handled) 
     134                        { 
     135                                if (ke.type & list->listener->events.evt_flags) 
    125136                                        handled = list->listener->handler(list->listener->object, &ke); 
    126                                 } 
     137 
    127138                                list = list->next; 
    128139                        } 
    129140                } 
    130                 if(handled) start = NULL; 
    131         } 
    132         if(start) { 
     141 
     142                if (handled) start = NULL; 
     143        } 
     144 
     145        if (start) 
     146        { 
    133147                ke.type = EVT_AGAIN; 
    134148                ke.key = '\xff'; 
    135149        } 
     150 
    136151        return ke; 
    137152} 
    138153 
    139 void add_listener(event_target *target, event_listener *observer) 
     154void add_listener(event_target * target, event_listener * observer) 
    140155{ 
    141156        listener_list *link; 
     157 
    142158        MAKE(link, listener_list); 
    143159        link->listener = observer; 
     
    146162} 
    147163 
    148 void remove_listener(event_target *target, event_listener *observer) 
     164void remove_listener(event_target * target, event_listener * observer) 
    149165{ 
    150166        listener_list *cur = target->observers; 
    151167        listener_list **prev = &target->observers; 
    152         while(cur) { 
    153                 if(cur->listener == observer) { 
     168 
     169        while (cur) 
     170        { 
     171                if (cur->listener == observer) 
     172                { 
    154173                        *prev = cur->next; 
    155174                        FREE(cur); 
     
    157176                } 
    158177        } 
     178 
    159179        bell("remove_listener: no such observer"); 
    160180} 
     
    165185 
    166186/* Display an event, with possible preference overrides */ 
    167 static void display_event_aux(event_action *event, int menuID, byte color, 
    168                                                         int row, int col, int wid) 
     187static void display_event_aux(event_action *event, int menuID, byte color, int row, int col, int wid) 
    169188{ 
    170189        /* TODO: add preference support */ 
    171190        /* TODO: wizard mode should show more data */ 
    172191        Term_erase(col, row, wid); 
    173         if(event->name) { 
     192 
     193        if (event->name) 
    174194                Term_putstr(col, row, wid, color, event->name); 
    175         } 
    176 
    177  
    178 static void display_event(menu_type *menu, int oid, bool cursor,  
    179                                                         int row, int col, int width) 
    180 
    181         event_action *evts = (event_action*)menu->menu_data; 
     195
     196 
     197static void display_event(menu_type *menu, int oid, bool cursor, int row, int col, int width) 
     198
     199        event_action *evts = (event_action *)menu->menu_data; 
    182200        byte color = curs_attrs[CURS_KNOWN][0 != cursor]; 
    183         display_event_aux(&evts[oid], menu->target.self.object_id, color, row, col, width); 
     201 
     202        display_event_aux(&evts[oid], menu->target.self.object_id, color, row, col, 
     203                                          width); 
    184204} 
    185205 
     
    188208static bool handle_menu_item_event(char cmd, void *db, int oid) 
    189209{ 
    190         event_action *evt = &((event_action*)db)[oid]; 
    191         if(cmd == '\xff' && evt->action) { 
     210        event_action *evt = &((event_action *)db)[oid]; 
     211 
     212        if (cmd == '\xff' && evt->action) 
     213        { 
    192214                evt->action(evt->data, evt->name); 
    193215                return TRUE; 
    194216        } 
    195         else if(cmd == '\xff') 
     217        else if (cmd == '\xff') 
     218        { 
    196219                return TRUE; 
     220        } 
     221 
    197222        return FALSE; 
    198223} 
     
    200225static int valid_menu_event(menu_type *menu, int oid) 
    201226{ 
    202         event_action *evts = (event_action *) menu->menu_data; 
     227        event_action *evts = (event_action *)menu->menu_data; 
    203228        return (NULL != evts[oid].name); 
    204229} 
    205230 
    206231/* Virtual function table for action_events */ 
    207 static const menu_iter menu_iter_event = { 
     232static const menu_iter menu_iter_event = 
     233
    208234        MN_EVT, 
    209235        0, 
     
    218244static char tag_menu_item(menu_type *menu, int oid) 
    219245{ 
    220         menu_item *items = (menu_item *) menu->menu_data; 
     246        menu_item *items = (menu_item *)menu->menu_data; 
    221247        return items[oid].sel; 
    222248} 
    223249 
    224 static void display_menu_item(menu_type *menu, int oid, bool cursor, 
    225                                                                 int row, int col, int width) 
    226 
    227         menu_item *items = (menu_item *) menu->menu_data; 
    228  
    229         byte color = 
    230                 curs_attrs[!(items[oid].flags & (MN_GRAYED))][0 != cursor]; 
    231         display_event_aux(&items[oid].evt, menu->target.self.object_id, color, row, col, width); 
     250static void display_menu_item(menu_type *menu, int oid, bool cursor, int row, int col, int width) 
     251
     252        menu_item *items = (menu_item *)menu->menu_data; 
     253        byte color = curs_attrs[!(items[oid].flags & (MN_GRAYED))][0 != cursor]; 
     254 
     255        display_event_aux(&items[oid].evt, menu->target.self.object_id, color, row, 
     256                                          col, width); 
    232257} 
    233258 
     
    235260static bool handle_menu_item(char cmd, void *db, int oid) 
    236261{ 
    237         if(cmd == '\xff') 
    238         { 
    239                 menu_item *item  = &((menu_item*)db)[oid]; 
    240                 if(item->flags & MN_DISABLED) return TRUE;  
    241                 if(item->evt.action) 
     262        if (cmd == '\xff') 
     263        { 
     264                menu_item *item = &((menu_item *)db)[oid]; 
     265 
     266                if (item->flags & MN_DISABLED) 
     267                        return TRUE; 
     268                if (item->evt.action) 
    242269                        item->evt.action(item->evt.data, item->evt.name); 
    243                 if(item->flags & MN_SELECTABLE) { 
     270                if (item->flags & MN_SELECTABLE) 
    244271                        item->flags ^= MN_SELECTED; 
    245                 } 
     272 
    246273                return TRUE; 
    247274        } 
     275 
    248276        return FALSE; 
    249277} 
     
    251279static int valid_menu_item(menu_type *menu, int oid) 
    252280{ 
    253         menu_item *items = (menu_item *) menu->menu_data; 
    254         if(items[oid].flags & MN_HIDDEN) return 2; 
     281        menu_item *items = (menu_item *)menu->menu_data; 
     282 
     283        if (items[oid].flags & MN_HIDDEN) 
     284                return 2; 
     285 
    255286        return (NULL != items[oid].evt.name); 
    256287} 
    257288 
    258289/* Virtual function table for menu items */ 
    259 static const menu_iter menu_iter_item = { 
     290static const menu_iter menu_iter_item = 
     291
    260292        MN_ACT, 
    261293        tag_menu_item, 
     
    268300 
    269301static void display_string(menu_type *menu, int oid, bool cursor, 
    270                                                                int row, int col, int width) 
    271 { 
    272         const char **items = (const char **) menu->menu_data; 
     302               int row, int col, int width) 
     303{ 
     304        const char **items = (const char **)menu->menu_data; 
    273305        byte color = curs_attrs[CURS_KNOWN][0 != cursor]; 
    274306        Term_putstr(col, row, width, color, items[oid]); 
     
    276308 
    277309/* Virtual function table for displaying arrays of strings */ 
    278 static const menu_iter menu_iter_string = { MN_STRING, 0, 0, display_string, 0 }; 
     310static const menu_iter menu_iter_string = 
     311{ MN_STRING, 0, 0, display_string, 0 }; 
    279312 
    280313 
     
    289322{ 
    290323        int cursor = row - loc->row + top; 
    291         if(cursor >= n) cursor = n-1; 
     324        if (cursor >= n) cursor = n - 1; 
    292325 
    293326        return cursor; 
     
    296329 
    297330/* Display current view of a skin */ 
    298 static void display_scrolling (menu_type *menu, int cursor, int *top, region *loc) 
     331static void 
     332display_scrolling(menu_type *menu, int cursor, int *top, region *loc) 
    299333{ 
    300334        int col = loc->col; 
     
    304338        int i; 
    305339 
    306         if(cursor <= *top && *top > 0
     340        if ((cursor <= *top) && (*top > 0)
    307341                *top = cursor - jumpscroll - 1; 
    308         if(cursor >= *top + (rows_per_page-1)) 
    309                  *top = cursor - (rows_per_page-1) + 1 + jumpscroll; 
    310         if(*top > n - rows_per_page) *top = n - rows_per_page; 
    311         if(*top < 0) *top = 0; 
    312  
    313         for(i = 0; i < rows_per_page && i < n; i++) 
     342        if (cursor >= *top + (rows_per_page - 1)) 
     343                *top = cursor - (rows_per_page - 1) + 1 + jumpscroll; 
     344        if (*top > n - rows_per_page) 
     345                *top = n - rows_per_page; 
     346        if (*top < 0) 
     347                *top = 0; 
     348 
     349        for (i = 0; i < rows_per_page && i < n; i++) 
    314350        { 
    315351                bool is_curs = (i == cursor - *top); 
    316                 display_menu_row(menu, i+*top, *top, is_curs, row+i, col, loc->width); 
    317         } 
    318         if(cursor >= 0) { 
    319                 Term_gotoxy(col, row + cursor-*top); 
    320         } 
     352                display_menu_row(menu, i + *top, *top, is_curs, row + i, col, 
     353                                                 loc->width); 
     354        } 
     355 
     356        if (cursor >= 0) 
     357                Term_gotoxy(col, row + cursor - *top); 
    321358} 
    322359 
     
    327364 
    328365/* Virtual function table for scrollable menu skin */ 
    329 static const menu_skin scroll_skin = { 
     366static const menu_skin scroll_skin = 
     367
    330368        MN_SCROLL, 
    331369        scrolling_get_cursor, 
     
    340378{ 
    341379        int rows_per_page = loc->page_rows; 
    342         int colw = loc->width / (n + rows_per_page-1)/rows_per_page; 
    343         int cursor = row + rows_per_page * (col - loc->col)/colw; 
    344  
    345         if(cursor < 0) cursor = 0; /* assert: This should never happen */ 
    346         if(cursor >= n) cursor = n-1; 
     380        int colw = loc->width / (n + rows_per_page - 1) / rows_per_page; 
     381        int cursor = row + rows_per_page * (col - loc->col) / colw; 
     382 
     383        if (cursor < 0) cursor = 0;    /* assert: This should never happen */ 
     384        if (cursor >= n) cursor = n - 1; 
    347385 
    348386        return cursor; 
    349387} 
    350388 
    351 void display_columns (menu_type *menu, int cursor, int *top, region *loc) 
     389void display_columns(menu_type *menu, int cursor, int *top, region *loc) 
    352390{ 
    353391        int c, r; 
     
    357395        int row = loc->row; 
    358396        int rows_per_page = loc->page_rows; 
    359         int cols = (n + rows_per_page - 1) / rows_per_page; 
     397        int cols = (n + rows_per_page - 1) / rows_per_page; 
    360398        int colw = menu_width; 
     399 
    361400        Term_get_size(&w, &h); 
    362         if(colw * cols > w - col)  
    363                 colw = (w-col) /cols; 
    364  
    365         for(c = 0; c < cols; c++) { 
    366                 for(r = 0; r < rows_per_page; r++) { 
    367                         int pos = c*rows_per_page + r; 
     401 
     402        if ((colw * cols) > (w - col)) 
     403                colw = (w - col) / cols; 
     404 
     405        for (c = 0; c < cols; c++) 
     406        { 
     407                for (r = 0; r < rows_per_page; r++) 
     408                { 
     409                        int pos = c * rows_per_page + r; 
    368410                        bool is_cursor = (pos == cursor); 
    369                         display_menu_row(menu, pos, 0, is_cursor, row+r, col+c*colw, colw); 
     411                        display_menu_row(menu, pos, 0, is_cursor, row + r, col + c * colw, 
     412                                                         colw); 
    370413                } 
    371414        } 
     
    378421 
    379422/* Virtual function table for multi-column menu skin */ 
    380 static const menu_skin column_skin = { 
     423static const menu_skin column_skin = 
     424
    381425        MN_COLUMNS, 
    382426        columns_get_cursor, 
     
    387431/* ================== IMPLICIT MENU FOR KEY SELECTION ================== */ 
    388432 
    389 static void display_nothing (menu_type *menu, int cursor, int *top, region *loc) 
     433static void display_nothing(menu_type *menu, int cursor, int *top, region *loc) 
    390434{ 
    391435} 
     
    396440} 
    397441 
    398 static const menu_skin key_select_skin = { 
     442static const menu_skin key_select_skin = 
     443
    399444        MN_KEY_ONLY, 
    400445        no_cursor, 
     
    408453{ 
    409454        int oid = cursor; 
    410         if(cursor < 0 || cursor >= menu->filter_count) return FALSE; 
    411         if(menu->object_list) { 
    412                 oid = menu->object_list[cursor];  
    413         } 
    414         if(!menu->row_funcs->valid_row) return TRUE; 
     455 
     456        if (cursor < 0 || cursor >= menu->filter_count) 
     457                return FALSE; 
     458 
     459        if (menu->object_list) 
     460                oid = menu->object_list[cursor]; 
     461 
     462        if (!menu->row_funcs->valid_row) 
     463                return TRUE; 
     464 
    415465        return menu->row_funcs->valid_row(menu, oid); 
    416466} 
     
    420470        int i; 
    421471        int n = menu->filter_count; 
    422         if(menu->flags & MN_NO_TAGS) return -1; 
    423         else if(menu->flags & MN_REL_TAGS) { 
    424                 for(i = 0; i < n; i++) { 
     472 
     473        if (menu->flags & MN_NO_TAGS) 
     474        { 
     475                return -1; 
     476        } 
     477        else if (menu->flags & MN_REL_TAGS) 
     478        { 
     479                for (i = 0; i < n; i++) 
     480                { 
    425481                        char c = menu->skin->get_tag(menu, i); 
    426                         if(c && c == key) 
     482                        if (c && c == key) 
    427483                                return i + menu->top; 
    428484                } 
    429485        } 
    430         else if(!(menu->flags & MN_PVT_TAGS) && menu->selections) { 
    431                 for(i = 0; menu->selections[i] ; i++) 
    432                         if(menu->selections[i] == key) return i; 
    433         } 
    434         else if(menu->row_funcs->get_tag) { 
    435                 for(i = 0; i < n; i++) { 
     486        else if (!(menu->flags & MN_PVT_TAGS) && menu->selections) 
     487        { 
     488                for (i = 0; menu->selections[i]; i++) 
     489                { 
     490                        if (menu->selections[i] == key) 
     491                                return i; 
     492                } 
     493        } 
     494        else if (menu->row_funcs->get_tag) 
     495        { 
     496                for (i = 0; i < n; i++) 
     497                { 
    436498                        int oid = menu->object_list ? menu->object_list[i] : i; 
    437499                        char c = menu->row_funcs->get_tag(menu, oid); 
    438                         if(c && c == key) 
     500                        if (c && c == key) 
    439501                                return i; 
    440502                } 
    441503        } 
     504 
    442505        return -1; 
    443506} 
     
    450513{ 
    451514        int oid = cursor; 
    452         if(menu->object_list) oid = menu->object_list[cursor]; 
    453515        int flags = menu->flags; 
    454         if(flags & MN_NO_ACT) return FALSE; 
    455  
    456         if(isspace(cmd) && (flags & MN_PAGE)) return FALSE; 
    457  
    458         if(cmd == ESCAPE) return FALSE; 
    459         if(!cmd == '\xff' && (!menu->cmd_keys || !strchr(menu->cmd_keys, cmd))) 
    460                         return FALSE; 
    461  
    462         if(menu->row_funcs->row_handler && 
    463                                                 menu->row_funcs->row_handler(cmd, (void*) menu->menu_data, oid)) { 
     516 
     517        if (menu->object_list) oid = menu->object_list[cursor]; 
     518        if (flags & MN_NO_ACT) return FALSE; 
     519 
     520        if (isspace(cmd) && (flags & MN_PAGE)) return FALSE; 
     521 
     522        if (cmd == ESCAPE) return FALSE; 
     523        if (!cmd == '\xff' && (!menu->cmd_keys || !strchr(menu->cmd_keys, cmd))) 
     524                return FALSE; 
     525 
     526        if (menu->row_funcs->row_handler && 
     527                menu->row_funcs->row_handler(cmd, (void *)menu->menu_data, oid)) 
     528        { 
    464529                key_event ke; 
    465530                ke.type = EVT_SELECT; 
     
    469534                return TRUE; 
    470535        } 
     536 
    471537        return FALSE; 
    472538} 
    473539 
    474540/* Modal display of menu */ 
    475 static void display_menu_row(menu_type *menu, int pos, int top, 
    476                                                                 bool cursor, int row, int col, int width) 
     541static void 
     542display_menu_row(menu_type *menu, int pos, int top, 
     543                 bool cursor, int row, int col, int width) 
    477544{ 
    478545        int flags = menu->flags; 
    479546        char sel = 0; 
    480547        int oid = pos; 
    481         if(menu->object_list) oid = menu->object_list[oid]; 
    482         if(menu->row_funcs->valid_row && menu->row_funcs->valid_row(menu, oid) == 2) 
     548 
     549        if (menu->object_list) 
     550                oid = menu->object_list[oid]; 
     551 
     552        if (menu->row_funcs->valid_row && menu->row_funcs->valid_row(menu, oid) == 2) 
    483553                return; 
    484         if(!(flags & MN_NO_TAGS)) { 
    485                 if(flags & MN_REL_TAGS) { 
     554 
     555        if (!(flags & MN_NO_TAGS)) 
     556        { 
     557                if (flags & MN_REL_TAGS) 
    486558                        sel = menu->skin->get_tag(menu, pos); 
    487                 } 
    488                 else if(menu->selections && !(flags & MN_PVT_TAGS)) { 
     559                else if (menu->selections && !(flags & MN_PVT_TAGS)) 
    489560                        sel = menu->selections[pos]; 
    490                 } 
    491                 else if(menu->row_funcs->get_tag) { 
     561                else if (menu->row_funcs->get_tag) 
    492562                        sel = menu->row_funcs->get_tag(menu, oid); 
    493                 } 
    494         } 
    495         if(sel) { 
     563        } 
     564 
     565        if (sel) 
     566        { 
    496567                /* TODO: CHECK FOR VALID */ 
    497568                byte color = curs_attrs[CURS_KNOWN][0 != (cursor)]; 
     
    500571                width -= 3; 
    501572        } 
     573 
    502574        menu->row_funcs->display_row(menu, oid, cursor, row, col, width); 
    503575} 
     
    507579        region *loc = &menu->boundary; 
    508580        int oid = menu->cursor; 
    509         if(menu->object_list && menu->cursor >= 0) 
     581        if (menu->object_list && menu->cursor >= 0) 
    510582                oid = menu->object_list[oid]; 
    511583 
    512  
    513584        region_erase(&menu->boundary); 
    514585 
    515         if(menu->title) 
     586        if (menu->title) 
    516587                Term_putstr(loc->col, loc->row, loc->width, TERM_WHITE, menu->title); 
    517         if(menu->prompt)  
    518                 Term_putstr(loc->col, loc->row+loc->page_rows-1, loc->width, TERM_WHITE, menu->prompt); 
     588        if (menu->prompt) 
     589                Term_putstr(loc->col, loc->row + loc->page_rows - 1, loc->width, 
     590                                        TERM_WHITE, menu->prompt); 
    519591 
    520592        menu->skin->display_list(menu, menu->cursor, &menu->top, &menu->active); 
    521         if(menu->browse_hook && oid >= 0) { 
     593 
     594        if (menu->browse_hook && oid >= 0) 
    522595                menu->browse_hook(oid, menu->menu_data, loc); 
    523         } 
    524596} 
    525597 
     
    530602        int *cursor = &menu->cursor; 
    531603        key_event out; 
     604 
    532605        out.key = '\xff'; 
    533         if(menu->target.observers) { 
     606 
     607        if (menu->target.observers) 
     608        { 
    534609                /* TODO: need a panel dispatcher here, not a generic target */ 
    535                 event_target t = {{0, 0, 0, 0}, FALSE, menu->target.observers}; 
     610                event_target t = { { 0, 0, 0, 0 }, FALSE, menu->target.observers }; 
    536611                out = run_event_loop(&t, FALSE, in); 
    537                 if(out.type != EVT_AGAIN) { 
    538                         if(out.type == EVT_SELECT) { 
     612 
     613                if (out.type != EVT_AGAIN) 
     614                { 
     615                        if (out.type == EVT_SELECT) 
     616                        { 
    539617                                /* HACK: can't return selection event from submenu (no ID) */ 
    540618                                out.type = EVT_REFRESH; 
    541619                                Term_event_push(&out); 
    542620                        } 
     621 
    543622                        return TRUE; 
    544623                } 
    545624        } 
    546625 
    547         switch(in->type) 
     626        switch (in->type) 
    548627        { 
    549628                case EVT_MOUSE: 
    550629                { 
    551630                        int m_curs; 
    552                         if(!region_inside(&menu->active, in)) { 
    553                                 if(!region_inside(&menu->boundary, in)) { 
     631 
     632                        if (!region_inside(&menu->active, in)) 
     633                        { 
     634                                if (!region_inside(&menu->boundary, in)) 
     635                                { 
    554636                                        return FALSE; 
    555637                                } 
    556638 
    557639                                /* used for heirarchical menus */ 
    558                                 if(in->mousex < menu->active.col) { 
     640                                if (in->mousex < menu->active.col) 
     641                                { 
    559642                                        out.type = EVT_BACK; 
    560643                                        break; 
    561644                                } 
     645 
    562646                                return FALSE; 
    563647                        } 
    564          
    565  
    566                         m_curs = menu->skin->get_cursor(in->mousey,in->mousex, 
    567                                                                 menu->filter_count, menu->top, &menu->active); 
     648 
     649                        m_curs = menu->skin->get_cursor(in->mousey, in->mousex, 
     650                                                                                        menu->filter_count, menu->top, 
     651                                                                                        &menu->active); 
     652 
    568653                        /* Ignore this event - retry */ 
    569                         if(!is_valid_row(menu, m_curs)) 
     654                        if (!is_valid_row(menu, m_curs)) 
    570655                                return TRUE; 
    571656 
    572657                        out.index = m_curs; 
    573                         if(*cursor == m_curs || !(menu->flags & MN_DBL_TAP)) { 
     658 
     659                        if (*cursor == m_curs || !(menu->flags & MN_DBL_TAP)) 
    574660                                out.type = EVT_SELECT; 
    575                         } 
    576                         else { 
     661                        else 
    577662                                out.type = EVT_MOVE; 
    578                         } 
     663 
    579664                        *cursor = m_curs; 
     665 
    580666                        break; 
    581667                } 
     
    586672 
    587673                        /* could install handle_menu_key as a handler */ 
    588                         if((menu->cmd_keys && strchr(menu->cmd_keys, in->key)) 
    589                                                                                                                 || in->key == ESCAPE) 
    590                         { 
    591                                 if(menu->flags & MN_NO_ACT) return FALSE; 
    592                                 else return handle_menu_key(in->key, menu, *cursor); 
    593                         } 
    594  
    595                         if(!(menu->flags & MN_NO_TAGS)) 
     674                        if ((menu->cmd_keys && strchr(menu->cmd_keys, in->key)) 
     675                                || in->key == ESCAPE) 
     676                        { 
     677                                if (menu->flags & MN_NO_ACT) 
     678                                        return FALSE; 
     679                                else 
     680                                        return handle_menu_key(in->key, menu, *cursor); 
     681                        } 
     682 
     683                        if (!(menu->flags & MN_NO_TAGS)) 
    596684                        { 
    597685                                int c = get_cursor_key(menu, menu->top, in->key); 
     686 
    598687                                /* retry! */ 
    599                                 if(c > 0 && !is_valid_row(menu, c)) 
     688                                if (c > 0 && !is_valid_row(menu, c)) 
     689                                { 
    600690                                        return FALSE; 
    601                                 else if(c >= 0) { 
     691                                } 
     692                                else if (c >= 0) 
     693                                { 
    602694                                        menu->cursor = c; 
    603695                                        out.type = EVT_SELECT; 
     
    606698                                } 
    607699                        } 
     700 
    608701                        /* Not handled */ 
    609                         if(menu->flags & MN_NO_CURSOR) 
     702                        if (menu->flags & MN_NO_CURSOR) 
    610703                                return FALSE; 
    611          
     704 
    612705                        /* cursor movement */ 
    613706                        dir = target_dir(in->key); 
    614                         if(ddx[dir] && ddy[dir]) return FALSE;          /* Reject diagonals */ 
    615                         else if(ddx[dir]) { 
     707 
     708                        /* Reject diagonals */ 
     709                        if (ddx[dir] && ddy[dir]) 
     710                        { 
     711                                return FALSE; 
     712                        } 
     713                        else if (ddx[dir]) 
     714                        { 
    616715                                out.type = ddx[dir] < 0 ? EVT_BACK : EVT_SELECT; 
    617716                                out.key = '\xff'; 
    618717                                out.index = *cursor; 
    619718                        } 
    620                         else if(ddy[dir]) {     /* Move up or down to the next valid & visible row */ 
     719                        /* Move up or down to the next valid & visible row */ 
     720                        else if (ddy[dir]) 
     721                        { 
    621722                                int ind; 
    622723                                int dy = ddy[dir]; 
     724 
    623725                                out.type = EVT_MOVE; 
    624                                 for(ind = *cursor + dy; ind < n && ind >= 0 
    625                                                        && (TRUE != is_valid_row(menu, ind)); ind += dy) ; 
     726                                for (ind = *cursor + dy; ind < n && ind >= 0 
     727                                        && (TRUE != is_valid_row(menu, ind)); ind += dy) ; 
    626728                                out.index = ind; 
    627                                 if(ind < n && ind >= 0) *cursor = ind; 
    628                         } 
    629                         else return FALSE; 
     729                                if (ind < n && ind >= 0) *cursor = ind; 
     730                        } 
     731                        else 
     732                        { 
     733                                return FALSE; 
     734                        } 
     735 
    630736                        break; 
    631737                } 
    632738 
    633                 case EVT_REFRESH: { 
     739                case EVT_REFRESH: 
     740                { 
    634741                        menu_refresh(menu); 
    635742                        return FALSE; 
    636743                } 
     744 
    637745                default: 
     746                { 
    638747                        return FALSE; 
    639        
    640  
    641         if(out.type == EVT_SELECT && handle_menu_key('\xff', menu, *cursor)) 
    642         { 
     748               
     749        } 
     750 
     751        if (out.type == EVT_SELECT && handle_menu_key('\xff', menu, *cursor)) 
    643752                return TRUE; 
    644         } 
    645  
    646         if(out.type == EVT_MOVE) menu_refresh(menu); 
     753 
     754        if (out.type == EVT_MOVE) 
     755               menu_refresh(menu); 
    647756 
    648757        Term_event_push(&out); 
     758 
    649759        return TRUE; 
    650760} 
     
    652762 
    653763/* VTAB for menus */ 
    654 static const panel_type menu_target = { 
    655         { { 0,                                                          /* listener.object_id */ 
    656                 (handler_f)menu_handle_event,   /* listener.handler */ 
    657                 (release_f)menu_destroy,                /* listener.release */ 
    658                 0,                                                              /* listener.object */ 
    659                 {EVT_KBRD | EVT_MOUSE | EVT_REFRESH} /* listener.events */ 
     764static const panel_type menu_target = 
     765
     766        { 
     767         {0,                                            /* listener.object_id */ 
     768          (handler_f) menu_handle_event,        /* listener.handler */ 
     769          (release_f) menu_destroy,     /* listener.release */ 
     770          0,                                            /* listener.object */ 
     771          {EVT_KBRD | EVT_MOUSE | EVT_REFRESH}  /* listener.events */ 
    660772          }, 
    661           TRUE,                                                               /* target.is_modal */ 
    662         }, 
    663         menu_refresh,                                          /* refresh() */ 
    664         {0, 0, 0, 0}                                           /* boundary */ 
     773         TRUE,                                                /* target.is_modal */ 
     774        }, 
     775        menu_refresh,                           /* refresh() */ 
     776        {0, 0, 0, 0}                            /* boundary */ 
    665777}; 
    666778 
     
    685797 *  EVT_KBRD - An unhandled keyboard event 
    686798 */ 
    687  
    688799key_event menu_select(menu_type *menu, int *cursor, int no_handle) 
    689800{ 
     801        key_event ke; 
    690802 
    691803        menu->cursor = *cursor; 
     804 
    692805        /* Menu shall not handle these */ 
    693         no_handle |= (EVT_SELECT|EVT_BACK|EVT_ESCAPE|EVT_STOP); 
     806        no_handle |= (EVT_SELECT | EVT_BACK | EVT_ESCAPE | EVT_STOP); 
    694807        no_handle &= ~(EVT_REFRESH); 
    695808 
    696         if(!menu->object_list) 
     809        if (!menu->object_list) 
    697810                menu->filter_count = menu->count; 
    698811 
    699         key_event ke; 
    700812        ke.type = EVT_REFRESH; 
    701         (void) run_event_loop(&menu->target, FALSE, &ke); 
     813        (void)run_event_loop(&menu->target, FALSE, &ke); 
    702814 
    703815        /* Stop on first unhandled event. */ 
    704         while(!(ke.type & no_handle)) 
     816        while (!(ke.type & no_handle)) 
    705817        { 
    706818                ke = run_event_loop(&menu->target, FALSE, 0); 
    707                 switch(ke.type) 
     819 
     820                switch (ke.type) 
    708821                { 
    709822                        /* menu always returns these */ 
    710823                        case EVT_SELECT: 
    711                                 if(*cursor != ke.index) { 
     824                        { 
     825