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 while ( gMacNotificationEvents
.top
!= gMacNotificationEvents
.bottom
)
120 // consume event at bottom
121 short index
= gMacNotificationEvents
.bottom
++ ;
122 if ( gMacNotificationEvents
.bottom
== kMaxEvents
)
123 gMacNotificationEvents
.bottom
= 0 ;
124 void* data
= gMacNotificationEvents
.data
[index
] ;
125 unsigned long event
= gMacNotificationEvents
.events
[index
] ;
126 wxMacNotificationProcPtr handler
= gMacNotificationEvents
.proc
[index
] ;
128 gMacNotificationEvents
.data
[index
] = NULL
;
129 gMacNotificationEvents
.events
[index
] = NULL
;
130 gMacNotificationEvents
.proc
[index
] = NULL
;
133 handler( event
, data
) ;
135 gInProcessing
= false ;
138 void wxMacProcessNotifierAndPendingEvents()
140 wxMacProcessNotifierEvents() ;
141 wxTheApp
->ProcessPendingEvents() ;