1 /* -------------------------------------------------------------------------
2 * Project: Mac Notifier Support
4 * Author: Stefan CSomor
5 * Purpose: Mac Notifier main file
7 * -------------------------------------------------------------------------
10 #include "wx/mac/macnotfy.h"
12 const short kMaxEvents
= 1000 ;
14 struct wxMacNotificationEvents
19 wxMacNotificationProcPtr proc
[kMaxEvents
] ;
20 unsigned long events
[kMaxEvents
] ;
21 void* data
[kMaxEvents
] ;
24 typedef struct wxMacNotificationEvents wxMacNotificationEvents
;
25 wxMacNotificationEvents gMacNotificationEvents
;
27 ProcessSerialNumber gAppProcess
;
31 ProcessSerialNumber psn
;
33 psn
.highLongOfPSN
= 0 ;
34 psn
.lowLongOfPSN
= kCurrentProcess
;
35 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
38 PostEvent( nullEvent
, 0 ) ;
42 WakeUpProcess( &gAppProcess
) ;
46 void wxMacCreateNotifierTable()
48 GetCurrentProcess(&gAppProcess
);
49 gMacNotificationEvents
.top
= 0 ;
50 gMacNotificationEvents
.bottom
= 0 ;
51 for ( int i
= 0 ; i
< kMaxEvents
; ++i
)
53 gMacNotificationEvents
.proc
[i
] = NULL
;
54 gMacNotificationEvents
.events
[i
] = NULL
;
55 gMacNotificationEvents
.data
[i
] = NULL
;
59 void wxMacDestroyNotifierTable()
61 wxASSERT( gMacNotificationEvents
.top
== gMacNotificationEvents
.bottom
) ;
64 wxMacNotifierTableRef
wxMacGetNotifierTable()
66 return (wxMacNotifierTableRef
) &gMacNotificationEvents
;
70 wxMacNotifierTableRef table
,
71 wxMacNotificationProcPtr handler
,
76 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
77 /* this should be protected eventually */
78 short index
= e
->top
++ ;
80 if ( e
->top
== kMaxEvents
)
83 e
->proc
[index
] = handler
;
84 e
->events
[index
] = event
;
85 e
->data
[index
] = data
;
90 bool gInProcessing
= false ;
92 void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table
, void* data
)
94 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
95 /* this should be protected eventually */
96 short index
= e
->bottom
;
98 while ( e
->top
!= index
)
100 if ( index
== kMaxEvents
)
102 if ( e
->data
[index
] == data
)
103 e
->data
[index
] = NULL
;
108 void wxMacProcessNotifierEvents()
110 // if ( gInProcessing )
113 gInProcessing
= true ;
114 while ( gMacNotificationEvents
.top
!= gMacNotificationEvents
.bottom
)
116 // consume event at bottom
117 short index
= gMacNotificationEvents
.bottom
++ ;
118 if ( gMacNotificationEvents
.bottom
== kMaxEvents
)
119 gMacNotificationEvents
.bottom
= 0 ;
120 void* data
= gMacNotificationEvents
.data
[index
] ;
121 unsigned long event
= gMacNotificationEvents
.events
[index
] ;
122 wxMacNotificationProcPtr handler
= gMacNotificationEvents
.proc
[index
] ;
124 gMacNotificationEvents
.data
[index
] = NULL
;
125 gMacNotificationEvents
.events
[index
] = NULL
;
126 gMacNotificationEvents
.proc
[index
] = NULL
;
128 handler( event
, data
) ;
130 gInProcessing
= false ;
133 void wxMacProcessNotifierAndPendingEvents()
135 wxMacProcessNotifierEvents() ;
136 wxTheApp
->ProcessPendingEvents() ;