]> git.saurik.com Git - wxWidgets.git/blame - src/mac/macnotfy.cpp
compilation fix
[wxWidgets.git] / src / mac / 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{
20 short top ;
21 short bottom ;
22
23 wxMacNotificationProcPtr proc[kMaxEvents] ;
24 unsigned long events[kMaxEvents] ;
25 void* data[kMaxEvents] ;
26} ;
27
28typedef struct wxMacNotificationEvents wxMacNotificationEvents ;
29wxMacNotificationEvents gMacNotificationEvents ;
30
a959b088 31ProcessSerialNumber gAppProcess ;
ee6b1d97
SC
32
33void wxMacWakeUp()
34{
35 ProcessSerialNumber psn ;
36 Boolean isSame ;
37 psn.highLongOfPSN = 0 ;
38 psn.lowLongOfPSN = kCurrentProcess ;
a959b088 39 SameProcess( &gAppProcess , &psn , &isSame ) ;
ee6b1d97
SC
40 if ( isSame )
41 {
42 PostEvent( nullEvent , 0 ) ;
43 }
44 else
45 {
a959b088 46 WakeUpProcess( &gAppProcess ) ;
ee6b1d97
SC
47 }
48}
49
50void wxMacCreateNotifierTable()
51{
a959b088 52 GetCurrentProcess(&gAppProcess);
ee6b1d97
SC
53 gMacNotificationEvents.top = 0 ;
54 gMacNotificationEvents.bottom = 0 ;
55 for ( int i = 0 ; i < kMaxEvents ; ++i )
56 {
57 gMacNotificationEvents.proc[i] = NULL ;
58 gMacNotificationEvents.events[i] = NULL ;
59 gMacNotificationEvents.data[i] = NULL ;
60 }
61}
62
63void wxMacDestroyNotifierTable()
64{
ee6b1d97
SC
65}
66
67wxMacNotifierTableRef wxMacGetNotifierTable()
68{
69 return (wxMacNotifierTableRef) &gMacNotificationEvents ;
70}
71
72void wxMacAddEvent(
73 wxMacNotifierTableRef table ,
74 wxMacNotificationProcPtr handler ,
75 unsigned long event ,
76 void* data ,
77 short wakeUp )
78{
79 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
76a5e5d2 80 wxASSERT_MSG( handler != NULL , "illegal notification proc ptr" ) ;
ee6b1d97
SC
81 /* this should be protected eventually */
82 short index = e->top++ ;
83
84 if ( e->top == kMaxEvents )
85 e->top = 0 ;
86
87 e->proc[index] = handler ;
88 e->events[index] = event ;
89 e->data[index] = data ;
90 if ( wakeUp )
91 wxMacWakeUp() ;
92}
93
94bool gInProcessing = false ;
95
96void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table , void* data )
97{
98 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
99 /* this should be protected eventually */
100 short index = e->bottom ;
101
102 while ( e->top != index )
103 {
104 if ( index == kMaxEvents )
105 index = 0 ;
106 if ( e->data[index] == data )
107 e->data[index] = NULL ;
108 index++ ;
109 }
110}
111
112void wxMacProcessNotifierEvents()
113{
114// if ( gInProcessing )
115// return ;
116
117 gInProcessing = true ;
2c724d25 118 if ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
ee6b1d97 119 {
2c724d25
SC
120 // we only should process the notifiers that were here when we entered it
121 // otherwise we might never get out...
122 short count = gMacNotificationEvents.top - gMacNotificationEvents.bottom ;
123 if ( count < 0 )
124 count += kMaxEvents ;
125
126 while ( count-- )
127 {
128 // consume event at bottom
129 short index = gMacNotificationEvents.bottom++ ;
130 if ( gMacNotificationEvents.bottom == kMaxEvents )
131 gMacNotificationEvents.bottom = 0 ;
132 void* data = gMacNotificationEvents.data[index] ;
133 unsigned long event = gMacNotificationEvents.events[index] ;
134 wxMacNotificationProcPtr handler = gMacNotificationEvents.proc[index] ;
135
136 gMacNotificationEvents.data[index] = NULL ;
137 gMacNotificationEvents.events[index] = NULL ;
138 gMacNotificationEvents.proc[index] = NULL ;
139
140 if ( handler )
141 handler( event , data ) ;
142 }
ee6b1d97
SC
143 }
144 gInProcessing = false ;
145}
146
147void wxMacProcessNotifierAndPendingEvents()
148{
149 wxMacProcessNotifierEvents() ;
150 wxTheApp->ProcessPendingEvents() ;
151}