root/trunk/txlib/txwehook.c

Revision 1, 6.6 kB (checked in by jvw, 3 years ago)

Initial check-in for TxWin? version 1.02 sources

Line 
1//
2//                     TxWin, Textmode Windowing Library
3//
4//   Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk
5//
6// ==========================================================================
7//
8// This file contains Original Code and/or Modifications of Original Code as
9// defined in and that are subject to the GNU Lesser General Public License.
10// You may not use this file except in compliance with the License.
11// BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE.
12// A copy of the License is provided with the Original Code and Modifications,
13// and is also available at http://www.dfsee.com/txwin/lgpl.htm
14//
15// This library is free software; you can redistribute it and/or modify
16// it under the terms of the GNU Lesser General Public License as published
17// by the Free Software Foundation; either version 2.1 of the License,
18// or (at your option) any later version.
19//
20// This library is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23// See the GNU Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public License
26// along with this library; (lgpl.htm) if not, write to the Free Software
27// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28//
29// Questions on TxWin licensing can be directed to: txwin@fsys.nl
30//
31// ==========================================================================
32//
33// Author: J. van Wijk
34//
35// TX simple event hook implementation, for multi-thread communication
36// like passing status or progress information to UI dialogs
37//
38// JvW  02-12-2005   Initial version
39
40#include <txlib.h>                              // public interface
41#include <txwpriv.h>                            // private window interface
42
43
44#if defined (USEWINDOWING)
45
46// Note: can be refined later to have a list of hooks per event-type
47
48// Simple event hook data structure (single hook per event-type)
49static TXWHANDLE      txwEventHookHandle[TXHK_EVENTS] = {TXHWND_NULL};
50
51
52/*****************************************************************************/
53// Attach specified hook-event to a window-handle
54/*****************************************************************************/
55ULONG txwAttachEventHook                        // RET   result
56(
57   ULONG               hookid,                  // IN    TXHK identifier
58   TXWHANDLE           hwnd                     // IN    window handle
59)
60{
61   ULONG               rc = NO_ERROR;           // function return
62
63   ENTER();
64
65   if (hookid < TXHK_EVENTS)
66   {
67      if (txwEventHookHandle[ hookid] == TXHWND_NULL)
68      {
69         TRACES(( "Attaching hwnd: %8.8lx for event: %lu\n", hwnd, hookid));
70         txwEventHookHandle[ hookid] = hwnd;
71      }
72      else                                      // slot is in use
73      {
74         rc = TX_FAILED;
75      }
76   }
77   else
78   {
79      rc = TX_INVALID_DATA;
80   }
81   RETURN (rc);
82}                                               // end 'txwAttachEventHook'
83/*---------------------------------------------------------------------------*/
84
85
86/*****************************************************************************/
87// Detach specified hook-event from a window-handle
88/*****************************************************************************/
89ULONG txwDetachEventHook                        // RET   result
90(
91   ULONG               hookid,                  // IN    TXHK identifier
92   TXWHANDLE           hwnd                     // IN    window handle
93)
94{
95   ULONG               rc = NO_ERROR;           // function return
96
97   ENTER();
98
99   if (hookid < TXHK_EVENTS)
100   {
101      if (txwEventHookHandle[ hookid] == hwnd)
102      {
103         TRACES(( "Detaching hwnd: %8.8lx for event: %lu\n", hwnd, hookid));
104         txwEventHookHandle[ hookid] = TXHWND_NULL;
105      }
106      else                                      // hwnd not attached
107      {
108         rc = TX_FAILED;
109      }
110   }
111   else
112   {
113      rc = TX_INVALID_DATA;
114   }
115   RETURN (rc);
116}                                               // end 'txwDetachEventHook'
117/*---------------------------------------------------------------------------*/
118
119
120/*****************************************************************************/
121// Query specified hook-event for a window-handle
122/*****************************************************************************/
123TXWHANDLE txwQueryEventHook                     // RET   window handle
124(
125   ULONG               hookid                   // IN    TXHK identifier
126)
127{
128   ULONG               rc = TXHWND_NULL;           // function return
129
130   ENTER();
131
132   if (hookid < TXHK_EVENTS)
133   {
134      rc = txwEventHookHandle[ hookid];
135   }
136   RETURN (rc);
137}                                               // end 'txwQueryEventHook'
138/*---------------------------------------------------------------------------*/
139
140#if defined (HAVETHREADS)
141
142/*****************************************************************************/
143// Signal specified hook-event, pass optional data (data must stay valid!)
144/*****************************************************************************/
145TXWHANDLE txwSignalEventHook                    // RET   window signalled
146(
147   ULONG               hookid,                  // IN    TXHK identifier (MP1)
148   void               *data                     // IN    optional data   (MP2)
149)
150{
151   ULONG               rc = TXHWND_NULL;        // function return
152
153   ENTER();
154
155   if (hookid < TXHK_EVENTS)
156   {
157      if ((rc = txwEventHookHandle[ hookid]) != TXHWND_NULL)
158      {
159         //- to be refined, may add boolean parameter for multiple messages
160         //- otherwise, don't add multiple to avoid msg pile-up in queue
161
162         if (txwQueueMsgPresent( rc, TXWM_HOOKEVENT) == FALSE)
163         {
164            if (txwPostMsg( rc, TXWM_HOOKEVENT, hookid, (ULONG) data))
165            {
166               txwNotifyAsyncInput();           // signal to synchronious
167            }                                   // input procedures ...
168            else
169            {
170               rc = TXHWND_NULL;                // Post failed, MSGQ full ?
171            }
172         }
173      }
174   }
175   RETURN (rc);
176}                                               // end 'txwSignalEventHook'
177/*---------------------------------------------------------------------------*/
178
179#endif                                          // HAVETHREADS
180#endif                                          // USEWINDOWING
Note: See TracBrowser for help on using the browser.