Ticket #3161: mc-3161-listbox.c-remember-focus-state.patch

File mc-3161-listbox.c-remember-focus-state.patch, 2.1 KB (added by and, 8 years ago)
  • lib/widget/listbox.c

    From db09ca01a05644d45eaeb7158c0eeb810d81fb5f Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Thu, 7 Jan 2016 15:25:27 +0000
    Subject: [PATCH] #3161 listbox.c remember focus state
    
    when listbox is updated, e.g. new file match add MSG_DRAW event is triggered
    but currently listbox re-draw has no knowledge about right focus state
    fix it by remember current focus state and resolve #3161
    
    (patch can be simplify but I unsure about lib api function change)
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     lib/widget/listbox.c | 11 ++++++++++-
     lib/widget/listbox.h |  1 +
     2 files changed, 11 insertions(+), 1 deletion(-)
    
    diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c
    index 7668ee3..d391668 100644
    a b listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void 
    449449        return MSG_HANDLED; 
    450450 
    451451    case MSG_FOCUS: 
     452        l->hasfocus = TRUE; 
     453        listbox_draw (l, l->hasfocus); 
     454        return MSG_HANDLED; 
     455 
    452456    case MSG_UNFOCUS: 
     457        l->hasfocus = FALSE; 
     458        listbox_draw (l, l->hasfocus); 
     459        return MSG_HANDLED; 
     460 
    453461    case MSG_DRAW: 
    454         listbox_draw (l, msg != MSG_UNFOCUS); 
     462        listbox_draw (l, l->hasfocus); 
    455463        return MSG_HANDLED; 
    456464 
    457465    case MSG_DESTROY: 
    listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn 
    559567    l->callback = callback; 
    560568    l->allow_duplicates = TRUE; 
    561569    l->scrollbar = !mc_global.tty.slow_terminal; 
     570    l->hasfocus = FALSE; 
    562571    widget_want_hotkey (w, TRUE); 
    563572    widget_want_cursor (w, FALSE); 
    564573 
  • lib/widget/listbox.h

    diff --git a/lib/widget/listbox.h b/lib/widget/listbox.h
    index 6bb5269..ae73313 100644
    a b typedef struct WListbox 
    5252    gboolean allow_duplicates;  /* Do we allow duplicates on the list? */ 
    5353    gboolean scrollbar;         /* Draw a scrollbar? */ 
    5454    gboolean deletable;         /* Can list entries be deleted? */ 
     55    gboolean hasfocus;          /* Has listbox a focus */ 
    5556    lcback_fn callback;         /* The callback function */ 
    5657    int cursor_x, cursor_y;     /* Cache the values */ 
    5758} WListbox;