minor improvements to Bind() description
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59952 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -70,18 +70,28 @@ conditions. It also allows the direct binding of events to:
|
|||||||
@li An ordinary function like a static method or a global function.
|
@li An ordinary function like a static method or a global function.
|
||||||
@li An arbitrary functor like boost::function<>.
|
@li An arbitrary functor like boost::function<>.
|
||||||
|
|
||||||
The static event tables can only handle
|
The static event tables can only handle events in the object where they are
|
||||||
events in the object where they are defined so using Bind<>() is more flexible
|
defined so using Bind<>() is more flexible than using the event tables. On the
|
||||||
than using the event tables. On the other hand, event tables are more succinct
|
other hand, event tables are more succinct and centralize all event handler
|
||||||
and centralize all event handler bindings in one place. You can either
|
bindings in one place. You can either choose a single approach that you find
|
||||||
choose a single approach that you find preferable or freely combine both
|
preferable or freely combine both methods in your program in different classes
|
||||||
methods in your program in different classes or even in one and the same class,
|
or even in one and the same class, although this is probably sufficiently
|
||||||
although this is probably sufficiently confusing to be a bad idea.
|
confusing to be a bad idea.
|
||||||
|
|
||||||
But before you make this choice, let us discuss these two ways in more
|
Also notice that most of the existing wxWidgets tutorials and discussions use
|
||||||
detail. In the next section we provide a short introduction to handling the
|
the event tables because they historically preceded the apparition of dynamic
|
||||||
events using the event tables. Please see @ref overview_events_bind
|
event handling in wxWidgets. But this absolutely doesn't mean that using the
|
||||||
for the discussion of Bind<>().
|
event tables is the preferred way: handling events dynamically is better in
|
||||||
|
several aspects and you should strongly consider doing it if you are just
|
||||||
|
starting with wxWidgets. On the other hand, you still need to know about the
|
||||||
|
event tables if only because you are going to see them in many samples and
|
||||||
|
examples.
|
||||||
|
|
||||||
|
So before you make the choice between static event tables and dynamically
|
||||||
|
connecting the event handlers, let us discuss these two ways in more detail. In
|
||||||
|
the next section we provide a short introduction to handling the events using
|
||||||
|
the event tables. Please see @ref overview_events_bind for the discussion of
|
||||||
|
Bind<>().
|
||||||
|
|
||||||
@subsection overview_events_eventtables Event Handling with Event Tables
|
@subsection overview_events_eventtables Event Handling with Event Tables
|
||||||
|
|
||||||
@@ -302,9 +312,12 @@ Now let us describe the semantic differences:
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
Here are some more examples of how to use different event handlers.
|
Let us now look at more examples of how to use different event handlers using
|
||||||
|
the two overloads of Bind() function: first one for the object methods and the
|
||||||
|
other one for arbitrary functors (callable objects, including simple functions):
|
||||||
|
|
||||||
You can use a method from a completely different object as an event handler:
|
In addition to using a method of the object generating the event itself, you
|
||||||
|
can use a method from a completely different object as an event handler:
|
||||||
|
|
||||||
@code
|
@code
|
||||||
void MyFrameHandler::OnFrameExit( wxCommandEvent & )
|
void MyFrameHandler::OnFrameExit( wxCommandEvent & )
|
||||||
@@ -326,6 +339,7 @@ keep in mind that then the lifetime of @c myFrameHandler must be greater than
|
|||||||
that of @c MyFrame object -- or at least it needs to be unbound before being
|
that of @c MyFrame object -- or at least it needs to be unbound before being
|
||||||
destroyed.
|
destroyed.
|
||||||
|
|
||||||
|
|
||||||
To use an ordinary function or a static method as an event handler you would
|
To use an ordinary function or a static method as an event handler you would
|
||||||
write something like this:
|
write something like this:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user