]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/macnotfy.cpp
call AddChild() when the control is already reallly created
[wxWidgets.git] / src / mac / carbon / 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 static wxMacNotificationEvents gMacNotificationEvents ;
30
31 ProcessSerialNumber gAppProcess ;
32
33 void wxMacCreateNotifierTable()
34 {
35 GetCurrentProcess(&gAppProcess);
36 gMacNotificationEvents.top = 0 ;
37 gMacNotificationEvents.bottom = 0 ;
38 for ( int i = 0 ; i < kMaxEvents ; ++i )
39 {
40 gMacNotificationEvents.proc[i] = NULL ;
41 gMacNotificationEvents.events[i] = NULL ;
42 gMacNotificationEvents.data[i] = NULL ;
43 }
44 }
45
46 void wxMacDestroyNotifierTable()
47 {
48 }
49
50 wxMacNotifierTableRef wxMacGetNotifierTable()
51 {
52 return (wxMacNotifierTableRef) &gMacNotificationEvents ;
53 }
54
55 void wxMacAddEvent(
56 wxMacNotifierTableRef table ,
57 wxMacNotificationProcPtr handler ,
58 unsigned long event ,
59 void* data ,
60 short wakeUp )
61 {
62 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
63 wxASSERT_MSG( handler != NULL , wxT("illegal notification proc ptr") ) ;
64 /* this should be protected eventually */
65 short index = e->top++ ;
66
67 if ( e->top == kMaxEvents )
68 e->top = 0 ;
69
70 e->proc[index] = handler ;
71 e->events[index] = event ;
72 e->data[index] = data ;
73 if ( wakeUp )
74 wxMacWakeUp() ;
75 }
76
77 bool gInProcessing = false ;
78
79 void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table , void* data )
80 {
81 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
82 /* this should be protected eventually */
83 short index = e->bottom ;
84
85 while ( e->top != index )
86 {
87 if ( e->data[index] == data )
88 e->data[index] = NULL ;
89 index++ ;
90 if ( index == kMaxEvents )
91 index = 0 ;
92 }
93 }
94
95 void wxMacProcessNotifierEvents()
96 {
97 // if ( gInProcessing )
98 // return ;
99
100 gInProcessing = true ;
101 if ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
102 {
103 // we only should process the notifiers that were here when we entered it
104 // otherwise we might never get out...
105 short count = gMacNotificationEvents.top - gMacNotificationEvents.bottom ;
106 if ( count < 0 )
107 count += kMaxEvents ;
108
109 while ( count-- )
110 {
111 // consume event at bottom
112 short index = gMacNotificationEvents.bottom++ ;
113 if ( gMacNotificationEvents.bottom == kMaxEvents )
114 gMacNotificationEvents.bottom = 0 ;
115 void* data = gMacNotificationEvents.data[index] ;
116 unsigned long event = gMacNotificationEvents.events[index] ;
117 wxMacNotificationProcPtr handler = gMacNotificationEvents.proc[index] ;
118
119 gMacNotificationEvents.data[index] = NULL ;
120 gMacNotificationEvents.events[index] = NULL ;
121 gMacNotificationEvents.proc[index] = NULL ;
122
123 if ( handler )
124 handler( event , data ) ;
125 }
126 }
127 gInProcessing = false ;
128 }
129
130 void wxMacProcessNotifierAndPendingEvents()
131 {
132 wxMacProcessNotifierEvents() ;
133 wxTheApp->ProcessPendingEvents() ;
134 }