luaforwindows/files/docs/wxlua/doxygen/html/wxlcallb_8h_source.html

179 lines
19 KiB
HTML

<!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"/>
<title>wxLua: /mnt/share/devel/lua/wxLua/modules/wxlua/include/wxlcallb.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="dirs.html"><span>Directories</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File&nbsp;List</span></a></li>
<li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
</ul>
</div>
<div class="navpath"><a class="el" href="dir_15d5a205ad383328522db6a6be296af1.html">modules</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_b59b58daa92d206701e75411b2cef894.html">wxlua</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_a9b43b959fc4efc3ae9ddc99e98c5750.html">include</a>
</div>
</div>
<div class="contents">
<h1>wxlcallb.h</h1><a href="wxlcallb_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/////////////////////////////////////////////////////////////////////////////</span>
<a name="l00002"></a>00002 <span class="comment"></span><span class="comment">// Name: wxlcallb.h</span>
<a name="l00003"></a>00003 <span class="comment">// Purpose: wxLuaEventCallback and wxLuaWinDestroyCallback</span>
<a name="l00004"></a>00004 <span class="comment">// Author: Francis Irving, John Labenski</span>
<a name="l00005"></a>00005 <span class="comment">// Created: 21/01/2002</span>
<a name="l00006"></a>00006 <span class="comment">// Copyright: (c) 2002 Creature Labs. All rights reserved.</span>
<a name="l00007"></a>00007 <span class="comment">// Licence: wxWidgets licence</span><span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment">/////////////////////////////////////////////////////////////////////////////</span>
<a name="l00009"></a>00009 <span class="comment"></span>
<a name="l00010"></a>00010 <span class="preprocessor">#ifndef _WXLCALLB_H_</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#define _WXLCALLB_H_</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &quot;<a class="code" href="wxldefs_8h.html">wxlua/include/wxldefs.h</a>&quot;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;<a class="code" href="wxlstate_8h.html">wxlua/include/wxlstate.h</a>&quot;</span>
<a name="l00015"></a>00015
<a name="l00016"></a>00016 <span class="comment">// ----------------------------------------------------------------------------</span>
<a name="l00017"></a>00017 <span class="comment">// wxLuaEventCallback - Forward events from wxEvtHandlers to Lua functions.</span>
<a name="l00018"></a>00018 <span class="comment">//</span>
<a name="l00019"></a>00019 <span class="comment">// The wxLuaEventCallback is created with the wxLuaState, the stack index of a</span>
<a name="l00020"></a>00020 <span class="comment">// Lua function to call when a wxEvent is received, the window id ranges, and</span>
<a name="l00021"></a>00021 <span class="comment">// the wxEventType used with wxEvtHandler::Connect() with &quot;this&quot; as the</span>
<a name="l00022"></a>00022 <span class="comment">// callback user data for event.</span>
<a name="l00023"></a>00023 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment">// Do NOT delete wxLuaEventCallbacks since the wxEvtHandler deletes the</span>
<a name="l00025"></a>00025 <span class="comment">// callback user data itself.</span>
<a name="l00026"></a>00026 <span class="comment">//</span>
<a name="l00027"></a>00027 <span class="comment">// The function wxLuaEventCallback::OnAllEvents() generically handles all wxEvents</span>
<a name="l00028"></a>00028 <span class="comment">// by retrieving the wxLuaEventCallback instance from the wxEvent userdata</span>
<a name="l00029"></a>00029 <span class="comment">// to call wxLuaEventCallback::OnEvent() on the correct instance.</span>
<a name="l00030"></a>00030 <span class="comment">// ----------------------------------------------------------------------------</span>
<a name="l00031"></a>00031
<a name="l00032"></a><a class="code" href="wxlcallb_8h.html#a2c65ce5032e6ce9b5e202ac44376ac2e">00032</a> <span class="preprocessor">#define WXLUAEVENTCALLBACK_NOROUTINE 1000000 // use this for the lua_func_stack_idx</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span> <span class="comment">// param of the constructor for no Lua routine</span>
<a name="l00034"></a>00034
<a name="l00035"></a><a class="code" href="classwxLuaEventCallback.html">00035</a> <span class="keyword">class </span><a class="code" href="wxldefs_8h.html#ad8b07fc8dd8f30300e284b64f734b026">WXDLLIMPEXP_WXLUA</a> <a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a> : <span class="keyword">public</span> wxObject
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037 <span class="keyword">public</span>:
<a name="l00038"></a>00038 <span class="comment">// default constructor, call Connect() to actually connect the event</span>
<a name="l00039"></a>00039 <a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>();
<a name="l00040"></a>00040
<a name="l00041"></a>00041 <span class="keyword">virtual</span> ~<a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>();
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="comment">// Verifies the inputs and calls evtHandler-&gt;Connect() with &quot;this&quot; as</span>
<a name="l00044"></a>00044 <span class="comment">// the callback userdata.</span>
<a name="l00045"></a>00045 <span class="comment">// lua_func_stack_idx is the Lua stack index of a function to call with</span>
<a name="l00046"></a>00046 <span class="comment">// the wxEvent as the single parameter.</span>
<a name="l00047"></a>00047 <span class="comment">// win_id and last_id follow the same notation as wxEvtHandler::Connect().</span>
<a name="l00048"></a>00048 <span class="comment">// If only one event Id is needed set last_id = wxID_ANY</span>
<a name="l00049"></a>00049 <span class="comment">// Returns an empty string on success and the wxEvtHandler takes ownership of this,</span>
<a name="l00050"></a>00050 <span class="comment">// otherwise an error message is returned and you must delete this since nobody else will.</span>
<a name="l00051"></a>00051 <span class="keyword">virtual</span> wxString Connect( <span class="keyword">const</span> <a class="code" href="classwxLuaState.html">wxLuaState</a>&amp; wxlState, <span class="keywordtype">int</span> lua_func_stack_idx,
<a name="l00052"></a>00052 wxWindowID win_id, wxWindowID last_id,
<a name="l00053"></a>00053 wxEventType eventType, wxEvtHandler *evtHandler );
<a name="l00054"></a>00054
<a name="l00055"></a>00055 <span class="keywordtype">void</span> ClearwxLuaState(); <span class="comment">// m_wxlState.UnRef()</span>
<a name="l00056"></a>00056
<a name="l00057"></a><a class="code" href="classwxLuaEventCallback.html#a5fb1611ad72c116f78ab6f7ba9b95283">00057</a> <a class="code" href="classwxLuaState.html">wxLuaState</a> <a class="code" href="classwxLuaEventCallback.html#a5fb1611ad72c116f78ab6f7ba9b95283">GetwxLuaState</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_wxlState; }
<a name="l00058"></a><a class="code" href="classwxLuaEventCallback.html#ab696a1037542b6e1baa6a5e20a65cd43">00058</a> wxWindowID <a class="code" href="classwxLuaEventCallback.html#ab696a1037542b6e1baa6a5e20a65cd43">GetId</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_id; }
<a name="l00059"></a><a class="code" href="classwxLuaEventCallback.html#ab50ca68f46e3fce67b8ba46345a27b79">00059</a> wxWindowID <a class="code" href="classwxLuaEventCallback.html#ab50ca68f46e3fce67b8ba46345a27b79">GetLastId</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_last_id; }
<a name="l00060"></a><a class="code" href="classwxLuaEventCallback.html#a9d261c62f81fbdebbb270eeaf1ac3ac6">00060</a> wxEventType <a class="code" href="classwxLuaEventCallback.html#a9d261c62f81fbdebbb270eeaf1ac3ac6">GetEventType</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_wxlBindEvent ? *m_wxlBindEvent-&gt;eventType : wxEVT_NULL; }
<a name="l00061"></a><a class="code" href="classwxLuaEventCallback.html#a43a1795558a72d6ba6f4f5a563d7a8e6">00061</a> wxEvtHandler* <a class="code" href="classwxLuaEventCallback.html#a43a1795558a72d6ba6f4f5a563d7a8e6">GetEvtHandler</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_evtHandler; }
<a name="l00062"></a><a class="code" href="classwxLuaEventCallback.html#a650ca5aaf3907f84b3e9ae5ee5bf4a76">00062</a> <span class="keywordtype">int</span> <a class="code" href="classwxLuaEventCallback.html#a650ca5aaf3907f84b3e9ae5ee5bf4a76">GetLuaFuncRef</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_luafunc_ref; }
<a name="l00063"></a>00063
<a name="l00064"></a><a class="code" href="classwxLuaEventCallback.html#ae6aad7d1196b6aacf7843c2756b6ef36">00064</a> <span class="keyword">const</span> <a class="code" href="structwxLuaBindEvent.html">wxLuaBindEvent</a>* <a class="code" href="classwxLuaEventCallback.html#ae6aad7d1196b6aacf7843c2756b6ef36">GetwxLuaBindEvent</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_wxlBindEvent; }
<a name="l00065"></a>00065
<a name="l00066"></a>00066 <span class="comment">// Get a human readable string about this callback.</span>
<a name="l00067"></a>00067 <span class="comment">// &quot;wxEVT_XXX(evt#) -&gt; wxLuaEventCallback(&amp;callback, ids %d %d)|wxEvtHandler(&amp;evthandler) -&gt; wxEvtHandlerClassName&quot;</span>
<a name="l00068"></a>00068 wxString GetInfo() <span class="keyword">const</span>; <span class="comment">// Get a human readable string</span>
<a name="l00069"></a>00069
<a name="l00070"></a>00070 <span class="comment">// Central event handler that calls OnEvent() for the actual</span>
<a name="l00071"></a>00071 <span class="comment">// wxLuaEventCallback callback userdata.</span>
<a name="l00072"></a>00072 <span class="comment">// This function is treated like a static function that all handlers of</span>
<a name="l00073"></a>00073 <span class="comment">// this class will call.</span>
<a name="l00074"></a>00074 <span class="keywordtype">void</span> OnAllEvents(wxEvent&amp; event);
<a name="l00075"></a>00075
<a name="l00076"></a>00076 <span class="comment">// Handle the wxEvent by calling the Lua function to handle the event.</span>
<a name="l00077"></a>00077 <span class="comment">// The Lua function will receive a single parameter, the wxEvent.</span>
<a name="l00078"></a>00078 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnEvent(wxEvent *event);
<a name="l00079"></a>00079
<a name="l00080"></a>00080 <span class="keyword">protected</span>:
<a name="l00081"></a><a class="code" href="classwxLuaEventCallback.html#a345f97641a497fb6b3184de9ea77a65b">00081</a> <span class="keywordtype">int</span> m_luafunc_ref; <span class="comment">// ref of the Lua routine to call in the wxlua_lreg_refs_key registry table</span>
<a name="l00082"></a><a class="code" href="classwxLuaEventCallback.html#a9132ece5a0d3ce33b549d45b74d542d5">00082</a> <a class="code" href="classwxLuaState.html">wxLuaState</a> m_wxlState; <span class="comment">// stored to verify that that lua_State is still active</span>
<a name="l00083"></a><a class="code" href="classwxLuaEventCallback.html#a24b10cd51688dc114ba08d770ab533aa">00083</a> wxEvtHandler* m_evtHandler;
<a name="l00084"></a><a class="code" href="classwxLuaEventCallback.html#a8c9bfe5e31a55df1f1ad3add4bc20bb8">00084</a> wxWindowID m_id;
<a name="l00085"></a><a class="code" href="classwxLuaEventCallback.html#a3ac255b4c1bcfe3c7803b765efcfa2bb">00085</a> wxWindowID m_last_id;
<a name="l00086"></a><a class="code" href="classwxLuaEventCallback.html#a8bda510e3c67898275e4413c3df72303">00086</a> <span class="keyword">const</span> <a class="code" href="structwxLuaBindEvent.html">wxLuaBindEvent</a>* m_wxlBindEvent; <span class="comment">// data for this wxEventType</span>
<a name="l00087"></a>00087
<a name="l00088"></a>00088 <span class="keyword">private</span>:
<a name="l00089"></a>00089 DECLARE_ABSTRACT_CLASS(<a class="code" href="classwxLuaEventCallback.html">wxLuaEventCallback</a>)
<a name="l00090"></a>00090 };
<a name="l00091"></a>00091
<a name="l00092"></a>00092 <span class="comment">// ----------------------------------------------------------------------------</span>
<a name="l00093"></a>00093 <span class="comment">// wxLuaWinDestroyCallback - Handle the wxEVT_DESTROY event from wxWindows.</span>
<a name="l00094"></a>00094 <span class="comment">//</span>
<a name="l00095"></a>00095 <span class="comment">// Clears the metatable for the wxWindow userdata so that after a call to</span>
<a name="l00096"></a>00096 <span class="comment">// win:Destroy() calling a function on win won&#39;t crash wxLua, but will generate</span>
<a name="l00097"></a>00097 <span class="comment">// an error message in Lua.</span>
<a name="l00098"></a>00098 <span class="comment">//</span>
<a name="l00099"></a>00099 <span class="comment">// Do NOT delete this, the wxEvtHandler deletes the callback user data itself</span>
<a name="l00100"></a>00100 <span class="comment">// unless it is !Ok() since that means it wasn&#39;t attached to the window.</span>
<a name="l00101"></a>00101 <span class="comment">//</span>
<a name="l00102"></a>00102 <span class="comment">// The function OnAllDestroyEvents() generically handles the events and forwards them</span>
<a name="l00103"></a>00103 <span class="comment">// to the wxEvent&#39;s wxLuaWinDestroyCallback callback user data function OnDestroy().</span>
<a name="l00104"></a>00104 <span class="comment">// ----------------------------------------------------------------------------</span>
<a name="l00105"></a>00105
<a name="l00106"></a><a class="code" href="classwxLuaWinDestroyCallback.html">00106</a> <span class="keyword">class </span><a class="code" href="wxldefs_8h.html#ad8b07fc8dd8f30300e284b64f734b026">WXDLLIMPEXP_WXLUA</a> <a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a> : <span class="keyword">public</span> wxObject
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108 <span class="keyword">public</span>:
<a name="l00109"></a>00109 <a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a>(<span class="keyword">const</span> <a class="code" href="classwxLuaState.html">wxLuaState</a>&amp; state, wxWindow *win);
<a name="l00110"></a>00110
<a name="l00111"></a>00111 <span class="keyword">virtual</span> ~<a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a>();
<a name="l00112"></a>00112
<a name="l00113"></a>00113 <span class="keywordtype">void</span> ClearwxLuaState(); <span class="comment">// m_wxlState.UnRef()</span>
<a name="l00114"></a>00114
<a name="l00115"></a><a class="code" href="classwxLuaWinDestroyCallback.html#ae811b1143135364f87599a5afe0c8fa2">00115</a> <a class="code" href="classwxLuaState.html">wxLuaState</a> <a class="code" href="classwxLuaWinDestroyCallback.html#ae811b1143135364f87599a5afe0c8fa2">GetwxLuaState</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_wxlState; }
<a name="l00116"></a><a class="code" href="classwxLuaWinDestroyCallback.html#ae2572b116622d6d8af56593ef68d923e">00116</a> wxWindow* <a class="code" href="classwxLuaWinDestroyCallback.html#ae2572b116622d6d8af56593ef68d923e">GetWindow</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_window; }
<a name="l00117"></a>00117
<a name="l00118"></a>00118 <span class="comment">// If Ok then this should be attached to a wxEVT_DESTROY callback</span>
<a name="l00119"></a>00119 <span class="comment">// else you should delete this since nobody else will.</span>
<a name="l00120"></a><a class="code" href="classwxLuaWinDestroyCallback.html#a2553e54eb4485223a8701e7c15f901ea">00120</a> <span class="keywordtype">bool</span> <a class="code" href="classwxLuaWinDestroyCallback.html#a2553e54eb4485223a8701e7c15f901ea">Ok</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_wxlState.Ok() &amp;&amp; (m_window != NULL); }
<a name="l00121"></a>00121
<a name="l00122"></a>00122 <span class="comment">// Get a human readable string</span>
<a name="l00123"></a>00123 <span class="comment">// &quot;wxWindowClassName(&amp;win, id=%d)|wxLuaDestroyCallback(&amp;callback)&quot;</span>
<a name="l00124"></a>00124 wxString GetInfo() <span class="keyword">const</span>;
<a name="l00125"></a>00125
<a name="l00126"></a>00126 <span class="comment">// Central event handler that calls OnDestroy() for the actual</span>
<a name="l00127"></a>00127 <span class="comment">// wxLuaWinDestroyCallback callback user data.</span>
<a name="l00128"></a>00128 <span class="comment">// This function is treated like a static function that all handlers of</span>
<a name="l00129"></a>00129 <span class="comment">// this class will call.</span>
<a name="l00130"></a>00130 <span class="keywordtype">void</span> OnAllDestroyEvents(wxWindowDestroyEvent&amp; event);
<a name="l00131"></a>00131
<a name="l00132"></a>00132 <span class="comment">// Handle the event by clearing the metatable for the window.</span>
<a name="l00133"></a>00133 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnDestroy(wxWindowDestroyEvent&amp; event);
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="keyword">protected</span>:
<a name="l00136"></a><a class="code" href="classwxLuaWinDestroyCallback.html#a66d8100028b9d46a505d85b1560920c3">00136</a> <a class="code" href="classwxLuaState.html">wxLuaState</a> m_wxlState; <span class="comment">// store it since we&#39;re added to a list of its callbacks.</span>
<a name="l00137"></a><a class="code" href="classwxLuaWinDestroyCallback.html#a0a0d596452e321360fed0a0a2e8b68ed">00137</a> wxWindow* m_window;
<a name="l00138"></a>00138
<a name="l00139"></a>00139 <span class="keyword">private</span>:
<a name="l00140"></a>00140 DECLARE_ABSTRACT_CLASS(<a class="code" href="classwxLuaWinDestroyCallback.html">wxLuaWinDestroyCallback</a>)
<a name="l00141"></a>00141 };
<a name="l00142"></a>00142
<a name="l00143"></a>00143 <span class="preprocessor">#endif //_WXLCALLB_H_</span>
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Tue Jul 13 10:30:39 2010 for wxLua by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>