FLTK logo

Re: [fltk.general] scrollbar

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: scrollbar Greg Ercolano Aug 05, 2021  
 

On 8/4/21 5:02 AM, Dave Jordan wrote:

Hi everybody.
I'm using a hold browser and i think its scrollbar is stealing a shortcut to a menu item i have assigned to ctrl-end. How can I prevent this? subclass the scrollbar? Or is it legit to have a handle and a callback for the same widget i.e. the browser?

    Yes - looking at the code for src/Fl_Scrollbar.cxx, it appears to react to FL_End
    as a shortcut regardless of the keyboard modifiers, so apparently Alt, Shift, Ctrl, etc.
    can all be used with the End key to handle moving the scrollbar.

    I think order of widgets in the parent group matter for shortcut event delivery;
    the group's children are likely processed in order of creation, so the first widget
    to respond to the shortcut 'wins'.

    So if possible, try creating your 'widget that needs ctrl-end' /before/ creating the
    hold browser. Or, you can rearrange the pointers in the parent group using I think
    remove() and add().

    Or I think the better approach might be to make your own subclass of the hold browser
    that /doesn't/ react to Ctrl+End, which should be easy to do, and will guarantee it doesn't
    steal the events you want.

    In your subclass handle() method, you can check for Ctrl+End and ignore the event
    by just doing a return(0); when it's received. This will eclipse the event from the base class
    so it can't react to it. Pretty sure this would work:



int MyHoldBrowser::handle(int e) {
    // Specifically ignore the Fl_End + FL_Ctrl key combo so that other widgets may use it
    switch (e) {
        case FL_KEYDOWN:     // keyboard press events (aka. FL_KEYBOARD)
        case FL_KEYUP:       // keyboard releae events
        case FL_SHORTCUT:    // keyboard shortcuts
            switch ( Fl::event_key() ) {
                case FL_End:                              // Fl_End pressed?
                    if ( Fl::event_state() & FL_CTRL )    // Ctrl key also pressed?
                        { return 0; }                     //
short circuit this event from base class so other widgets can use it
                    break;
            }
            break;
    }
    return Fl_Hold_Browser::handle(e);                    // all other events pass to base class
}



    You can easily tweak that to ignore other modifier key combos as well that you might need,
    like Alt-End, Shift-End, and ignore those combos with other keys as well, like Home, PgUp/Dn, etc.

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/d240503e-859b-235b-34de-b4db98bb6d96%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.