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 wxMacNotificationEvents gMacNotificationEvents
;
31 ProcessSerialNumber gAppProcess
;
35 ProcessSerialNumber psn
;
37 psn
.highLongOfPSN
= 0 ;
38 psn
.lowLongOfPSN
= kCurrentProcess
;
39 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
42 PostEvent( nullEvent
, 0 ) ;
46 WakeUpProcess( &gAppProcess
) ;
50 void wxMacCreateNotifierTable()
52 GetCurrentProcess(&gAppProcess
);
53 gMacNotificationEvents
.top
= 0 ;
54 gMacNotificationEvents
.bottom
= 0 ;
55 for ( int i
= 0 ; i
< kMaxEvents
; ++i
)
57 gMacNotificationEvents
.proc
[i
] = NULL
;
58 gMacNotificationEvents
.events
[i
] = NULL
;
59 gMacNotificationEvents
.data
[i
] = NULL
;
63 void wxMacDestroyNotifierTable()
67 wxMacNotifierTableRef
wxMacGetNotifierTable()
69 return (wxMacNotifierTableRef
) &gMacNotificationEvents
;
73 wxMacNotifierTableRef table
,
74 wxMacNotificationProcPtr handler
,
79 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
80 wxASSERT_MSG( handler
!= NULL
, "illegal notification proc ptr" ) ;
81 /* this should be protected eventually */
82 short index
= e
->top
++ ;
84 if ( e
->top
== kMaxEvents
)
87 e
->proc
[index
] = handler
;
88 e
->events
[index
] = event
;
89 e
->data
[index
] = data
;
94 bool gInProcessing
= false ;
96 void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table
, void* data
)
98 wxMacNotificationEvents
*e
= (wxMacNotificationEvents
*) table
;
99 /* this should be protected eventually */
100 short index
= e
->bottom
;
102 while ( e
->top
!= index
)
104 if ( index
== kMaxEvents
)
106 if ( e
->data
[index
] == data
)
107 e
->data
[index
] = NULL
;
112 void wxMacProcessNotifierEvents()
114 // if ( gInProcessing )
117 gInProcessing
= true ;
118 if ( gMacNotificationEvents
.top
!= gMacNotificationEvents
.bottom
)
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
;
124 count
+= kMaxEvents
;
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
] ;
136 gMacNotificationEvents
.data
[index
] = NULL
;
137 gMacNotificationEvents
.events
[index
] = NULL
;
138 gMacNotificationEvents
.proc
[index
] = NULL
;
141 handler( event
, data
) ;
144 gInProcessing
= false ;
147 void wxMacProcessNotifierAndPendingEvents()
149 wxMacProcessNotifierEvents() ;
150 wxTheApp
->ProcessPendingEvents() ;