1 /* -------------------------------------------------------------------------
2 * Project: Mac Notifier Support
4 * Author: Stefan CSomor
5 * Purpose: Mac Notifier main file
7 * -------------------------------------------------------------------------
10 #include "wx/wxprec.h"
14 #include "wx/mac/private.h"
16 #include "wx/mac/macnotfy.h"
18 const short kMaxEvents
= 1000 ;
20 struct wxMacNotificationEvents
25 wxMacNotificationProcPtr proc
[kMaxEvents
] ;
26 unsigned long events
[kMaxEvents
] ;
27 void* data
[kMaxEvents
] ;
30 typedef struct wxMacNotificationEvents wxMacNotificationEvents
;
31 static wxMacNotificationEvents gMacNotificationEvents
;
33 ProcessSerialNumber gAppProcess
;
35 void wxMacCreateNotifierTable()
37 GetCurrentProcess(&gAppProcess
);
38 gMacNotificationEvents
.top
= 0 ;
39 gMacNotificationEvents
.bottom
= 0 ;
40 for ( int i
= 0 ; i
< kMaxEvents
; ++i
)
42 gMacNotificationEvents
.proc
[i
] = NULL
;
43 gMacNotificationEvents
.events
[i
] = 0 ;
44 gMacNotificationEvents
.data
[i
] = NULL
;
48 void wxMacDestroyNotifierTable()
52 wxMacNotifierTableRef
wxMacGetNotifierTable()
54 return (wxMacNotifierTableRef
) &gMacNotificationEvents
;
58 wxMacNotifierTableRef table
,
59 wxMacNotificationProcPtr handler
,
64 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
65 wxASSERT_MSG( handler
!= NULL
, wxT("illegal notification proc ptr") ) ;
66 /* this should be protected eventually */
67 short index
= e
->top
++ ;
69 if ( e
->top
== kMaxEvents
)
72 e
->proc
[index
] = handler
;
73 e
->events
[index
] = event
;
74 e
->data
[index
] = data
;
79 bool gInProcessing
= false ;
81 void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table
, void* data
)
83 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
84 /* this should be protected eventually */
85 short index
= e
->bottom
;
87 while ( e
->top
!= index
)
89 if ( e
->data
[index
] == data
)
90 e
->data
[index
] = NULL
;
92 if ( index
== kMaxEvents
)
97 void wxMacProcessNotifierEvents()
99 // if ( gInProcessing )
102 gInProcessing
= true ;
103 if ( gMacNotificationEvents
.top
!= gMacNotificationEvents
.bottom
)
105 // we only should process the notifiers that were here when we entered it
106 // otherwise we might never get out...
107 short count
= gMacNotificationEvents
.top
- gMacNotificationEvents
.bottom
;
109 count
+= kMaxEvents
;
113 // consume event at bottom
114 short index
= gMacNotificationEvents
.bottom
++ ;
115 if ( gMacNotificationEvents
.bottom
== kMaxEvents
)
116 gMacNotificationEvents
.bottom
= 0 ;
117 void* data
= gMacNotificationEvents
.data
[index
] ;
118 unsigned long event
= gMacNotificationEvents
.events
[index
] ;
119 wxMacNotificationProcPtr handler
= gMacNotificationEvents
.proc
[index
] ;
121 gMacNotificationEvents
.data
[index
] = NULL
;
122 gMacNotificationEvents
.events
[index
] = 0 ;
123 gMacNotificationEvents
.proc
[index
] = NULL
;
126 handler( event
, data
) ;
129 gInProcessing
= false ;
132 void wxMacProcessNotifierAndPendingEvents()
134 wxMacProcessNotifierEvents() ;
135 wxTheApp
->ProcessPendingEvents() ;