1 /* -------------------------------------------------------------------------
2 * Project: Mac Notifier Support
4 * Author: Stefan CSomor
5 * Purpose: Mac Notifier main file
7 * -------------------------------------------------------------------------
11 #include "wx/mac/macnotfy.h"
13 const short kMaxEvents
= 1000 ;
15 struct wxMacNotificationEvents
20 wxMacNotificationProcPtr proc
[kMaxEvents
] ;
21 unsigned long events
[kMaxEvents
] ;
22 void* data
[kMaxEvents
] ;
25 typedef struct wxMacNotificationEvents wxMacNotificationEvents
;
26 wxMacNotificationEvents gMacNotificationEvents
;
28 ProcessSerialNumber gAppProcess
;
32 ProcessSerialNumber psn
;
34 psn
.highLongOfPSN
= 0 ;
35 psn
.lowLongOfPSN
= kCurrentProcess
;
36 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
39 PostEvent( nullEvent
, 0 ) ;
43 WakeUpProcess( &gAppProcess
) ;
47 void wxMacCreateNotifierTable()
49 GetCurrentProcess(&gAppProcess
);
50 gMacNotificationEvents
.top
= 0 ;
51 gMacNotificationEvents
.bottom
= 0 ;
52 for ( int i
= 0 ; i
< kMaxEvents
; ++i
)
54 gMacNotificationEvents
.proc
[i
] = NULL
;
55 gMacNotificationEvents
.events
[i
] = NULL
;
56 gMacNotificationEvents
.data
[i
] = NULL
;
60 void wxMacDestroyNotifierTable()
62 wxASSERT( gMacNotificationEvents
.top
== gMacNotificationEvents
.bottom
) ;
65 wxMacNotifierTableRef
wxMacGetNotifierTable()
67 return (wxMacNotifierTableRef
) &gMacNotificationEvents
;
71 wxMacNotifierTableRef table
,
72 wxMacNotificationProcPtr handler
,
77 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
78 /* this should be protected eventually */
79 short index
= e
->top
++ ;
81 if ( e
->top
== kMaxEvents
)
84 e
->proc
[index
] = handler
;
85 e
->events
[index
] = event
;
86 e
->data
[index
] = data
;
91 bool gInProcessing
= false ;
93 void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table
, void* data
)
95 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
96 /* this should be protected eventually */
97 short index
= e
->bottom
;
99 while ( e
->top
!= index
)
101 if ( index
== kMaxEvents
)
103 if ( e
->data
[index
] == data
)
104 e
->data
[index
] = NULL
;
109 void wxMacProcessNotifierEvents()
111 // if ( gInProcessing )
114 gInProcessing
= true ;
115 while ( gMacNotificationEvents
.top
!= gMacNotificationEvents
.bottom
)
117 // consume event at bottom
118 short index
= gMacNotificationEvents
.bottom
++ ;
119 if ( gMacNotificationEvents
.bottom
== kMaxEvents
)
120 gMacNotificationEvents
.bottom
= 0 ;
121 void* data
= gMacNotificationEvents
.data
[index
] ;
122 unsigned long event
= gMacNotificationEvents
.events
[index
] ;
123 wxMacNotificationProcPtr handler
= gMacNotificationEvents
.proc
[index
] ;
125 gMacNotificationEvents
.data
[index
] = NULL
;
126 gMacNotificationEvents
.events
[index
] = NULL
;
127 gMacNotificationEvents
.proc
[index
] = NULL
;
129 handler( event
, data
) ;
131 gInProcessing
= false ;
134 void wxMacProcessNotifierAndPendingEvents()
136 wxMacProcessNotifierEvents() ;
137 wxTheApp
->ProcessPendingEvents() ;