Nana C++ Library  

An open-source C++ framework project
The Programmer's Guide 
Events

Description

    Nana.GUI provides some raw events, such as click, mouse_move and so on. The most of these events can work with all widgets implemented by Nana.GUI, but some of them are individual, like unload for root widget, elapse for timer.
    Every widget has an interface for registering an event, it named make_event.

    template<typename Event, typename Function>
    event_handle make_event(Function) const;

    template<typename Event, typename Class, typename Concept>
    event_handle make_event(Class& object, void (Concept::*mf)(const nana::gui::eventinfo&));

    template<typename Event, typename Class, typename Concept>
    event_handle make_event(Class& object, void(Concept::*mf)());

    These template function calls with explicitly specified the first template parameter, the Event is a type defined by Nana.GUI in nana::gui::events. The events are

click A mouse click event.
dbl_click A mouse double click event.
mouse_enter A mouse enters a widget.
mouse_move A mouse moves over a widget.
mouse_leave A mouse leaves a widget.
mouse_down A mouse button is pressed on a widget.
mouse_up A mouse button is released on a widget.
mouse_wheel A mouse scrolls the wheel on a widget.
mouse_drop A mouse release over a window that is registered as recipient of drag and drop.
sizing A widget's size is sizing. In this event, A widget's size can be overrided with a new size.
size A widget's size has changed.
unload A form is closed by clicking the X button, only works for root widget.
destroy A widget is about to be destroyed.
focus A widget's focus is changed.
key_down A keyboard is pressed on a focus widget.
key_char The focus widget received a character.
key_up A keyboard is released on a focus widget.
shortkey The widgets received a shortkey message.
elapse A widget received a tick that is sended by timer.

    The user-defined event function may have a parameter that type is const nana::gui::eventinfo& for quering the event information, such as mouse position.

    void foo();

    void foo_with_parameter(const nana::gui::eventinfo&);

    class user_def_functor
    {
    public:
        void operator()(const nana::gui::eventinfo&);  //user-defined function must have the parameter.
    };

    nana::gui::button().make_event<nana::gui::events::click>(foo);
    nana::gui::button().make_event<nana::gui::events::click>(foo_with_parameter);
    nana::gui::button().make_event<nana::gui::events::click>(user_def_functor());

    make_event returns a handle for uninstalling the associated user-defined event function and Nana.GUI destroyes the user-defined event function automatically when the widget is beginning to destroy.

    This just describes these general-purpose events, but some widgets like nana::gui::treebox provides some high-level events, such as expanding a node, these details are only described in the reference of corresponding widget. 


File

None.

Notes

None.

See also

None.


Move to The Nana Programmer's Guide Main Page