1 /* -------------------------------------------------------------------------
2 * Project: Mac Notifier Support
4 * Author: Stefan CSomor
5 * Purpose: Mac Notifier main file
7 * -------------------------------------------------------------------------
12 #include "wx/mac/private.h"
14 #include "wx/mac/macnotfy.h"
16 const short kMaxEvents
= 1000 ;
18 struct wxMacNotificationEvents
23 wxMacNotificationProcPtr proc
[kMaxEvents
] ;
24 unsigned long events
[kMaxEvents
] ;
25 void* data
[kMaxEvents
] ;
28 typedef struct wxMacNotificationEvents wxMacNotificationEvents
;
29 static wxMacNotificationEvents gMacNotificationEvents
;
31 ProcessSerialNumber gAppProcess
;
33 void wxMacCreateNotifierTable()
35 GetCurrentProcess(&gAppProcess
);
36 gMacNotificationEvents
.top
= 0 ;
37 gMacNotificationEvents
.bottom
= 0 ;
38 for ( int i
= 0 ; i
< kMaxEvents
; ++i
)
40 gMacNotificationEvents
.proc
[i
] = NULL
;
41 gMacNotificationEvents
.events
[i
] = NULL
;
42 gMacNotificationEvents
.data
[i
] = NULL
;
46 void wxMacDestroyNotifierTable()
50 wxMacNotifierTableRef
wxMacGetNotifierTable()
52 return (wxMacNotifierTableRef
) &gMacNotificationEvents
;
56 wxMacNotifierTableRef table
,
57 wxMacNotificationProcPtr handler
,
62 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
63 wxASSERT_MSG( handler
!= NULL
, wxT("illegal notification proc ptr") ) ;
64 /* this should be protected eventually */
65 short index
= e
->top
++ ;
67 if ( e
->top
== kMaxEvents
)
70 e
->proc
[index
] = handler
;
71 e
->events
[index
] = event
;
72 e
->data
[index
] = data
;
77 bool gInProcessing
= false ;
79 void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table
, void* data
)
81 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
82 /* this should be protected eventually */
83 short index
= e
->bottom
;
85 while ( e
->top
!= index
)
87 if ( e
->data
[index
] == data
)
88 e
->data
[index
] = NULL
;
90 if ( index
== kMaxEvents
)
95 void wxMacProcessNotifierEvents()
97 // if ( gInProcessing )
100 gInProcessing
= true ;
101 if ( gMacNotificationEvents
.top
!= gMacNotificationEvents
.bottom
)
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
;
107 count
+= kMaxEvents
;
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
] ;
119 gMacNotificationEvents
.data
[index
] = NULL
;
120 gMacNotificationEvents
.events
[index
] = NULL
;
121 gMacNotificationEvents
.proc
[index
] = NULL
;
124 handler( event
, data
) ;
127 gInProcessing
= false ;
130 void wxMacProcessNotifierAndPendingEvents()
132 wxMacProcessNotifierEvents() ;
133 wxTheApp
->ProcessPendingEvents() ;