]> git.saurik.com Git - wxWidgets.git/blob - src/mac/macnotfy.cpp
fixes for operator new declaration/definition (patch 549349)
[wxWidgets.git] / src / mac / macnotfy.cpp
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
10 #include "wx/wx.h"
11
12 #include "wx/mac/private.h"
13
14 #include "wx/mac/macnotfy.h"
15
16 const short kMaxEvents = 1000 ;
17
18 struct wxMacNotificationEvents
19 {
20 short top ;
21 short bottom ;
22
23 wxMacNotificationProcPtr proc[kMaxEvents] ;
24 unsigned long events[kMaxEvents] ;
25 void* data[kMaxEvents] ;
26 } ;
27
28 typedef struct wxMacNotificationEvents wxMacNotificationEvents ;
29 wxMacNotificationEvents gMacNotificationEvents ;
30
31 ProcessSerialNumber gAppProcess ;
32
33 void wxMacWakeUp()
34 {
35 ProcessSerialNumber psn ;
36 Boolean isSame ;
37 psn.highLongOfPSN = 0 ;
38 psn.lowLongOfPSN = kCurrentProcess ;
39 SameProcess( &gAppProcess , &psn , &isSame ) ;
40 if ( isSame )
41 {
42 PostEvent( nullEvent , 0 ) ;
43 }
44 else
45 {
46 WakeUpProcess( &gAppProcess ) ;
47 }
48 }
49
50 void wxMacCreateNotifierTable()
51 {
52 GetCurrentProcess(&gAppProcess);
53 gMacNotificationEvents.top = 0 ;
54 gMacNotificationEvents.bottom = 0 ;
55 for ( int i = 0 ; i < kMaxEvents ; ++i )
56 {
57 gMacNotificationEvents.proc[i] = NULL ;
58 gMacNotificationEvents.events[i] = NULL ;
59 gMacNotificationEvents.data[i] = NULL ;
60 }
61 }
62
63 void wxMacDestroyNotifierTable()
64 {
65 }
66
67 wxMacNotifierTableRef wxMacGetNotifierTable()
68 {
69 return (wxMacNotifierTableRef) &gMacNotificationEvents ;
70 }
71
72 void wxMacAddEvent(
73 wxMacNotifierTableRef table ,
74 wxMacNotificationProcPtr handler ,
75 unsigned long event ,
76 void* data ,
77 short wakeUp )
78 {
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++ ;
83
84 if ( e->top == kMaxEvents )
85 e->top = 0 ;
86
87 e->proc[index] = handler ;
88 e->events[index] = event ;
89 e->data[index] = data ;
90 if ( wakeUp )
91 wxMacWakeUp() ;
92 }
93
94 bool gInProcessing = false ;
95
96 void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table , void* data )
97 {
98 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
99 /* this should be protected eventually */
100 short index = e->bottom ;
101
102 while ( e->top != index )
103 {
104 if ( index == kMaxEvents )
105 index = 0 ;
106 if ( e->data[index] == data )
107 e->data[index] = NULL ;
108 index++ ;
109 }
110 }
111
112 void wxMacProcessNotifierEvents()
113 {
114 // if ( gInProcessing )
115 // return ;
116
117 gInProcessing = true ;
118 if ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
119 {
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 ;
123 if ( count < 0 )
124 count += kMaxEvents ;
125
126 while ( count-- )
127 {
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] ;
135
136 gMacNotificationEvents.data[index] = NULL ;
137 gMacNotificationEvents.events[index] = NULL ;
138 gMacNotificationEvents.proc[index] = NULL ;
139
140 if ( handler )
141 handler( event , data ) ;
142 }
143 }
144 gInProcessing = false ;
145 }
146
147 void wxMacProcessNotifierAndPendingEvents()
148 {
149 wxMacProcessNotifierEvents() ;
150 wxTheApp->ProcessPendingEvents() ;
151 }