]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/windowids.h
Fix broken and missing DataView interface items for Phoenix
[wxWidgets.git] / docs / doxygen / overviews / windowids.h
CommitLineData
15b6757b 1/////////////////////////////////////////////////////////////////////////////
3863c5eb 2// Name: windowids.h
15b6757b
FM
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
15b6757b
FM
7/////////////////////////////////////////////////////////////////////////////
8
880efa2a 9/**
36c9828f 10
880efa2a 11@page overview_windowids Window IDs
36c9828f 12
831e1028 13@tableofcontents
3863c5eb 14
ccd4e1bc
VZ
15Various controls and other parts of wxWidgets need an ID. Sometimes the ID may
16be directly provided by the user or have a predefined value, such as
3863c5eb
BP
17@c wxID_OPEN. Often, however, the value of the ID is unimportant and is created
18automatically by calling wxWindow::NewControlId or by passing @c wxID_ANY as
19the ID of an object.
20
ccd4e1bc 21There are two ways to generate an ID. One way is to start at a negative
3863c5eb 22number, and for each new ID, return the next smallest number. This is fine for
ccd4e1bc 23systems that can use the full range of negative numbers for IDs, as this
3863c5eb 24provides more than enough IDs and it would take a very very long time to run
4c51a665 25out and wrap around. However, some systems cannot use the full range of the
3863c5eb
BP
26ID value. Windows, for example, can only use 16 bit IDs, and only has about
2732000 possible automatic IDs that can be generated by wxWindow::NewControlId.
28If the program runs long enough, depending on the program itself, using this
29first method would cause the IDs to wrap around into the positive ID range and
30cause possible clashes with any directly specified ID values.
31
32The other way is to keep track of the IDs returned by wxWindow::NewControlId
33and don't return them again until the ID is completely free and not being used
34by any other objects. This will make sure that the ID values do not clash with
35one another. This is accomplished by keeping a reference count for each of the
36IDs that can possibly be returned by wxWindow::NewControlId. Other IDs are not
37reference counted.
38
831e1028
BP
39@see wxIdManager, wxWindow::NewControlId(), wxWindow::UnreserveControlId()
40
3863c5eb
BP
41
42@section overview_windowids_type Data Types
43
44A wxWindowID is just the integer type for a window ID. It should be used
45almost everywhere. To help keep track of the count for the automatically
46generated IDs, a new type, wxWindowIDRef exists, that can take the place of
47wxWindowID where needed. When an ID is first created, it is marked as reserved.
48When assigning it to a wxWindowIDRef, the usage count of the ID is increased,
49or set to 1 if it is currently reserved. Assigning the same ID to several
50wxWindowIDRefs will keep track of the count. As the wxWindowIDRef gets
51destroyed or its value changes, it will decrease the count of the used ID. When
52there are no more wxWindowIDRef types with the created ID, the ID is considered
53free and can then be used again by wxWindow::NewControlId.
54
55If a created ID is not assigned to a wxWindowIDRef, then it remains reserved
56until it is unreserved manually with wxWindow::UnreserveControlId. However, if
57it is assigned to a wxWindowIDRef, then it will be unreserved automatically and
58will be considered free when the count is 0, and should NOT be manually
59unreserved.
60
ccd4e1bc
VZ
61wxWindowIDRef can store both automatic IDs from wxWindow::NewControlId and
62normal IDs. Reference counting is only done for the automatic IDs. Also,
3863c5eb
BP
63wxWindowIDRef has conversion operators that allow it to be treated just like a
64wxWindowID.
65
66
67@section overview_windowids_using Using wxWindowIDRef
68
69A wxWindowIDRef should be used in place of a wxWindowID where you want to make
70sure the ID is not created again by wxWindow::NewControlId at least until the
71wxWindowIDRef is destroyed, usually when the associated object is destroyed.
72This is done already for windows, menu items, and tool bar items. It should
73only be used in the main thread, as it is not thread safe.
74
75*/