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