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