]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/macnotfy.cpp
Include missing.h to find O_* flags.
[wxWidgets.git] / src / mac / carbon / macnotfy.cpp
CommitLineData
ee6b1d97
SC
1/* -------------------------------------------------------------------------
2 * Project: Mac Notifier Support
3 * Name: macnotfy.c
4 * Author: Stefan CSomor
5 * Purpose: Mac Notifier main file
6 * CVSID: $Id$
7 * -------------------------------------------------------------------------
8 */
9
03e11df5 10#include "wx/wx.h"
76a5e5d2
SC
11
12#include "wx/mac/private.h"
13
ee6b1d97
SC
14#include "wx/mac/macnotfy.h"
15
16const short kMaxEvents = 1000 ;
17
18struct wxMacNotificationEvents
19{
e40298d5
JS
20 short top ;
21 short bottom ;
22
23 wxMacNotificationProcPtr proc[kMaxEvents] ;
24 unsigned long events[kMaxEvents] ;
25 void* data[kMaxEvents] ;
ee6b1d97
SC
26} ;
27
28typedef struct wxMacNotificationEvents wxMacNotificationEvents ;
af34705c 29static wxMacNotificationEvents gMacNotificationEvents ;
ee6b1d97 30
73280e05 31ProcessSerialNumber gAppProcess ;
ee6b1d97
SC
32
33void wxMacCreateNotifierTable()
34{
e40298d5
JS
35 GetCurrentProcess(&gAppProcess);
36 gMacNotificationEvents.top = 0 ;
37 gMacNotificationEvents.bottom = 0 ;
38 for ( int i = 0 ; i < kMaxEvents ; ++i )
39 {
40 gMacNotificationEvents.proc[i] = NULL ;
41 gMacNotificationEvents.events[i] = NULL ;
42 gMacNotificationEvents.data[i] = NULL ;
43 }
ee6b1d97
SC
44}
45
46void wxMacDestroyNotifierTable()
47{
ee6b1d97
SC
48}
49
50wxMacNotifierTableRef wxMacGetNotifierTable()
51{
e40298d5 52 return (wxMacNotifierTableRef) &gMacNotificationEvents ;
ee6b1d97
SC
53}
54
55void wxMacAddEvent(
e40298d5
JS
56 wxMacNotifierTableRef table ,
57 wxMacNotificationProcPtr handler ,
58 unsigned long event ,
59 void* data ,
60 short wakeUp )
ee6b1d97 61{
e40298d5 62 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
427ff662 63 wxASSERT_MSG( handler != NULL , wxT("illegal notification proc ptr") ) ;
e40298d5
JS
64 /* this should be protected eventually */
65 short index = e->top++ ;
66
67 if ( e->top == kMaxEvents )
68 e->top = 0 ;
69
70 e->proc[index] = handler ;
71 e->events[index] = event ;
72 e->data[index] = data ;
73 if ( wakeUp )
74 wxMacWakeUp() ;
ee6b1d97
SC
75}
76
77bool gInProcessing = false ;
78
79void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table , void* data )
80{
e40298d5
JS
81 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
82 /* this should be protected eventually */
83 short index = e->bottom ;
84
85 while ( e->top != index )
86 {
e40298d5
JS
87 if ( e->data[index] == data )
88 e->data[index] = NULL ;
89 index++ ;
a722995e
SC
90 if ( index == kMaxEvents )
91 index = 0 ;
e40298d5 92 }
ee6b1d97
SC
93}
94
95void wxMacProcessNotifierEvents()
96{
e40298d5
JS
97 // if ( gInProcessing )
98 // return ;
99
100 gInProcessing = true ;
101 if ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
2c724d25 102 {
e40298d5
JS
103 // we only should process the notifiers that were here when we entered it
104 // otherwise we might never get out...
105 short count = gMacNotificationEvents.top - gMacNotificationEvents.bottom ;
106 if ( count < 0 )
107 count += kMaxEvents ;
2c724d25 108
e40298d5
JS
109 while ( count-- )
110 {
111 // consume event at bottom
112 short index = gMacNotificationEvents.bottom++ ;
113 if ( gMacNotificationEvents.bottom == kMaxEvents )
114 gMacNotificationEvents.bottom = 0 ;
115 void* data = gMacNotificationEvents.data[index] ;
116 unsigned long event = gMacNotificationEvents.events[index] ;
117 wxMacNotificationProcPtr handler = gMacNotificationEvents.proc[index] ;
118
119 gMacNotificationEvents.data[index] = NULL ;
120 gMacNotificationEvents.events[index] = NULL ;
121 gMacNotificationEvents.proc[index] = NULL ;
122
123 if ( handler )
124 handler( event , data ) ;
125 }
126 }
127 gInProcessing = false ;
ee6b1d97
SC
128}
129
130void wxMacProcessNotifierAndPendingEvents()
131{
e40298d5
JS
132 wxMacProcessNotifierEvents() ;
133 wxTheApp->ProcessPendingEvents() ;
ee6b1d97 134}