]> git.saurik.com Git - wxWidgets.git/blame - src/mac/macnotfy.cpp
corrections for modifications made to common mimetype code
[wxWidgets.git] / src / mac / macnotfy.cpp
CommitLineData
ee6b1d97
SC
1/* -------------------------------------------------------------------------
2 * Project: Mac Notifier Support
3 * Name: macnotfy.c
4 * Author: Stefan CSomor
5 * Purpose: Mac Notifier main file
6 * CVSID: $Id$
7 * -------------------------------------------------------------------------
8 */
9
03e11df5 10#include "wx/wx.h"
ee6b1d97
SC
11#include "wx/mac/macnotfy.h"
12
13const short kMaxEvents = 1000 ;
14
15struct wxMacNotificationEvents
16{
17 short top ;
18 short bottom ;
19
20 wxMacNotificationProcPtr proc[kMaxEvents] ;
21 unsigned long events[kMaxEvents] ;
22 void* data[kMaxEvents] ;
23} ;
24
25typedef struct wxMacNotificationEvents wxMacNotificationEvents ;
26wxMacNotificationEvents gMacNotificationEvents ;
27
a959b088 28ProcessSerialNumber gAppProcess ;
ee6b1d97
SC
29
30void wxMacWakeUp()
31{
32 ProcessSerialNumber psn ;
33 Boolean isSame ;
34 psn.highLongOfPSN = 0 ;
35 psn.lowLongOfPSN = kCurrentProcess ;
a959b088 36 SameProcess( &gAppProcess , &psn , &isSame ) ;
ee6b1d97
SC
37 if ( isSame )
38 {
39 PostEvent( nullEvent , 0 ) ;
40 }
41 else
42 {
a959b088 43 WakeUpProcess( &gAppProcess ) ;
ee6b1d97
SC
44 }
45}
46
47void wxMacCreateNotifierTable()
48{
a959b088 49 GetCurrentProcess(&gAppProcess);
ee6b1d97
SC
50 gMacNotificationEvents.top = 0 ;
51 gMacNotificationEvents.bottom = 0 ;
52 for ( int i = 0 ; i < kMaxEvents ; ++i )
53 {
54 gMacNotificationEvents.proc[i] = NULL ;
55 gMacNotificationEvents.events[i] = NULL ;
56 gMacNotificationEvents.data[i] = NULL ;
57 }
58}
59
60void wxMacDestroyNotifierTable()
61{
62 wxASSERT( gMacNotificationEvents.top == gMacNotificationEvents.bottom ) ;
63}
64
65wxMacNotifierTableRef wxMacGetNotifierTable()
66{
67 return (wxMacNotifierTableRef) &gMacNotificationEvents ;
68}
69
70void wxMacAddEvent(
71 wxMacNotifierTableRef table ,
72 wxMacNotificationProcPtr handler ,
73 unsigned long event ,
74 void* data ,
75 short wakeUp )
76{
77 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
78 /* this should be protected eventually */
79 short index = e->top++ ;
80
81 if ( e->top == kMaxEvents )
82 e->top = 0 ;
83
84 e->proc[index] = handler ;
85 e->events[index] = event ;
86 e->data[index] = data ;
87 if ( wakeUp )
88 wxMacWakeUp() ;
89}
90
91bool gInProcessing = false ;
92
93void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table , void* data )
94{
95 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
96 /* this should be protected eventually */
97 short index = e->bottom ;
98
99 while ( e->top != index )
100 {
101 if ( index == kMaxEvents )
102 index = 0 ;
103 if ( e->data[index] == data )
104 e->data[index] = NULL ;
105 index++ ;
106 }
107}
108
109void wxMacProcessNotifierEvents()
110{
111// if ( gInProcessing )
112// return ;
113
114 gInProcessing = true ;
115 while ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
116 {
117 // consume event at bottom
118 short index = gMacNotificationEvents.bottom++ ;
119 if ( gMacNotificationEvents.bottom == kMaxEvents )
120 gMacNotificationEvents.bottom = 0 ;
121 void* data = gMacNotificationEvents.data[index] ;
122 unsigned long event = gMacNotificationEvents.events[index] ;
123 wxMacNotificationProcPtr handler = gMacNotificationEvents.proc[index] ;
124
125 gMacNotificationEvents.data[index] = NULL ;
126 gMacNotificationEvents.events[index] = NULL ;
127 gMacNotificationEvents.proc[index] = NULL ;
128
129 handler( event , data ) ;
130 }
131 gInProcessing = false ;
132}
133
134void wxMacProcessNotifierAndPendingEvents()
135{
136 wxMacProcessNotifierEvents() ;
137 wxTheApp->ProcessPendingEvents() ;
138}