File: overview_windowids.html

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (80 lines) | stat: -rw-r--r-- 7,686 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: Window IDs</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
 <tbody>
 <tr>
  <td id="projectlogo">
    <a href="http://www.wxwidgets.org/" target="_new">
      <img alt="wxWidgets" src="logo.png"/>
    </a>
  </td>
  <td style="padding-left: 0.5em; text-align: right;">
   <span id="projectnumber">Version: 3.0.2</span>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Categories</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Window IDs </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_windowids_type">Data Types</a></li>
<li class="level1"><a href="#overview_windowids_using">Using wxWindowIDRef</a></li>
</ul>
</div>
<div class="textblock"><p>Various controls and other parts of wxWidgets need an ID.</p>
<p>Sometimes the ID may be directly provided by the user or have a predefined value, such as <code>wxID_OPEN</code>. Often, however, the value of the ID is unimportant and is created automatically by calling <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId</a> or by passing <code>wxID_ANY</code> as the ID of an object.</p>
<p>There are two ways to generate an ID. One way is to start at a negative number, and for each new ID, return the next smallest number. This is fine for systems that can use the full range of negative numbers for IDs, as this provides more than enough IDs and it would take a very very long time to run 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 <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId</a>. 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.</p>
<p>The other way is to keep track of the IDs returned by <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId</a> 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 <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId</a>. Other IDs are not reference counted.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="classwx_id_manager.html" title="wxIdManager is responsible for allocating and releasing window IDs.">wxIdManager</a>, <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId()</a>, <a class="el" href="classwx_window.html#ad9bc342d1e38d221e37f0f6396950c8c" title="Unreserve an ID or range of IDs that was reserved by NewControlId().">wxWindow::UnreserveControlId()</a></dd></dl>
<h1><a class="anchor" id="overview_windowids_type"></a>
Data Types</h1>
<p>A wxWindowID is just the integer type for a window ID. It should be used almost everywhere. To help keep track of the count for the automatically generated IDs, a new type, wxWindowIDRef exists, that can take the place of wxWindowID where needed. When an ID is first created, it is marked as reserved. When assigning it to a wxWindowIDRef, the usage count of the ID is increased, or set to 1 if it is currently reserved. Assigning the same ID to several wxWindowIDRefs will keep track of the count. As the wxWindowIDRef gets destroyed or its value changes, it will decrease the count of the used ID. When there are no more wxWindowIDRef types with the created ID, the ID is considered free and can then be used again by <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId</a>.</p>
<p>If a created ID is not assigned to a wxWindowIDRef, then it remains reserved until it is unreserved manually with <a class="el" href="classwx_window.html#ad9bc342d1e38d221e37f0f6396950c8c" title="Unreserve an ID or range of IDs that was reserved by NewControlId().">wxWindow::UnreserveControlId</a>. However, if it is assigned to a wxWindowIDRef, then it will be unreserved automatically and will be considered free when the count is 0, and should NOT be manually unreserved.</p>
<p>wxWindowIDRef can store both automatic IDs from <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId</a> and normal IDs. Reference counting is only done for the automatic IDs. Also, wxWindowIDRef has conversion operators that allow it to be treated just like a wxWindowID.</p>
<h1><a class="anchor" id="overview_windowids_using"></a>
Using wxWindowIDRef</h1>
<p>A wxWindowIDRef should be used in place of a wxWindowID where you want to make sure the ID is not created again by <a class="el" href="classwx_window.html#a8175da594e6045635a1d1cfe775cdddb" title="Create a new ID or range of IDs that are not currently in use.">wxWindow::NewControlId</a> at least until the wxWindowIDRef is destroyed, usually when the associated object is destroyed. This is done already for windows, menu items, and tool bar items. It should only be used in the main thread, as it is not thread safe. </p>
</div></div><!-- contents -->

<address class="footer">
	<small>
		Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
	</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>