Correct and simplify window IDs overview in the manual
Explicitly mention that IDs effectively used when wxID_ANY is specified as well as IDs returned by NewControlId() are negative and that the user IDs should be positive to avoid clashing with such auto-generated ones.
This commit is contained in:
@@ -13,27 +13,16 @@
|
|||||||
|
|
||||||
Various controls and other parts of wxWidgets need an ID. Sometimes the ID may
|
Various controls and other parts of wxWidgets need an ID. Sometimes the ID may
|
||||||
be directly provided by the user or have a predefined value, such as
|
be directly provided by the user or have a predefined value, such as
|
||||||
@c wxID_OPEN. Often, however, the value of the ID is unimportant and is created
|
@c wxID_OPEN. Often, however, the value of the ID is unimportant and in this
|
||||||
automatically by calling wxWindow::NewControlId or by passing @c wxID_ANY as
|
case it is enough to use @c wxID_ANY as the ID of an object which tells
|
||||||
the ID of an object.
|
wxWidgets to assign an ID automatically. All such automatically-assigned IDs
|
||||||
|
are negative, so the IDs predefined in the user code should always be positive
|
||||||
|
to avoid clashes with them.
|
||||||
|
|
||||||
There are two ways to generate an ID. One way is to start at a negative
|
If you do care about the ID value but don't want to specify it as a literal in
|
||||||
number, and for each new ID, return the next smallest number. This is fine for
|
your code, you can use wxWindow::NewControlId() to create an ID that had never
|
||||||
systems that can use the full range of negative numbers for IDs, as this
|
been returned by this function before and, being also negative, never conflicts
|
||||||
provides more than enough IDs and it would take a very very long time to run
|
with any IDs explicitly defined in the program if the advice above is followed.
|
||||||
out and wrap around. However, some systems cannot use the full range of the
|
|
||||||
ID value. Windows, for example, can only use 16 bit IDs, and only has about
|
|
||||||
32000 possible automatic IDs that can be generated by wxWindow::NewControlId.
|
|
||||||
If the program runs long enough, depending on the program itself, using this
|
|
||||||
first method would cause the IDs to wrap around into the positive ID range and
|
|
||||||
cause possible clashes with any directly specified ID values.
|
|
||||||
|
|
||||||
The other way is to keep track of the IDs returned by wxWindow::NewControlId
|
|
||||||
and don't return them again until the ID is completely free and not being used
|
|
||||||
by any other objects. This will make sure that the ID values do not clash with
|
|
||||||
one another. This is accomplished by keeping a reference count for each of the
|
|
||||||
IDs that can possibly be returned by wxWindow::NewControlId. Other IDs are not
|
|
||||||
reference counted.
|
|
||||||
|
|
||||||
@see wxIdManager, wxWindow::NewControlId(), wxWindow::UnreserveControlId()
|
@see wxIdManager, wxWindow::NewControlId(), wxWindow::UnreserveControlId()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user