]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/macnotfy.cpp
deactivate read-only implementation for unicodetextcontrol because it cannot be selec...
[wxWidgets.git] / src / mac / carbon / 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
3d1a4878
SC
10#include "wx/wxprec.h"
11
03e11df5 12#include "wx/wx.h"
76a5e5d2
SC
13
14#include "wx/mac/private.h"
15
ee6b1d97
SC
16#include "wx/mac/macnotfy.h"
17
18const short kMaxEvents = 1000 ;
19
20struct wxMacNotificationEvents
21{
e40298d5
JS
22 short top ;
23 short bottom ;
24
25 wxMacNotificationProcPtr proc[kMaxEvents] ;
26 unsigned long events[kMaxEvents] ;
27 void* data[kMaxEvents] ;
ee6b1d97
SC
28} ;
29
30typedef struct wxMacNotificationEvents wxMacNotificationEvents ;
af34705c 31static wxMacNotificationEvents gMacNotificationEvents ;
ee6b1d97 32
73280e05 33ProcessSerialNumber gAppProcess ;
ee6b1d97
SC
34
35void wxMacCreateNotifierTable()
36{
e40298d5
JS
37 GetCurrentProcess(&gAppProcess);
38 gMacNotificationEvents.top = 0 ;
39 gMacNotificationEvents.bottom = 0 ;
40 for ( int i = 0 ; i < kMaxEvents ; ++i )
41 {
42 gMacNotificationEvents.proc[i] = NULL ;
77eddfb7 43 gMacNotificationEvents.events[i] = 0 ;
e40298d5
JS
44 gMacNotificationEvents.data[i] = NULL ;
45 }
ee6b1d97
SC
46}
47
48void wxMacDestroyNotifierTable()
49{
ee6b1d97
SC
50}
51
52wxMacNotifierTableRef wxMacGetNotifierTable()
53{
e40298d5 54 return (wxMacNotifierTableRef) &gMacNotificationEvents ;
ee6b1d97
SC
55}
56
57void wxMacAddEvent(
e40298d5
JS
58 wxMacNotifierTableRef table ,
59 wxMacNotificationProcPtr handler ,
60 unsigned long event ,
61 void* data ,
62 short wakeUp )
ee6b1d97 63{
e40298d5 64 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
427ff662 65 wxASSERT_MSG( handler != NULL , wxT("illegal notification proc ptr") ) ;
e40298d5
JS
66 /* this should be protected eventually */
67 short index = e->top++ ;
68
69 if ( e->top == kMaxEvents )
70 e->top = 0 ;
71
72 e->proc[index] = handler ;
73 e->events[index] = event ;
74 e->data[index] = data ;
75 if ( wakeUp )
76 wxMacWakeUp() ;
ee6b1d97
SC
77}
78
79bool gInProcessing = false ;
80
81void wxMacRemoveAllNotifiersForData( wxMacNotifierTableRef table , void* data )
82{
e40298d5
JS
83 wxMacNotificationEvents *e = (wxMacNotificationEvents *) table ;
84 /* this should be protected eventually */
85 short index = e->bottom ;
86
87 while ( e->top != index )
88 {
e40298d5
JS
89 if ( e->data[index] == data )
90 e->data[index] = NULL ;
91 index++ ;
a722995e
SC
92 if ( index == kMaxEvents )
93 index = 0 ;
e40298d5 94 }
ee6b1d97
SC
95}
96
97void wxMacProcessNotifierEvents()
98{
e40298d5
JS
99 // if ( gInProcessing )
100 // return ;
101
102 gInProcessing = true ;
103 if ( gMacNotificationEvents.top != gMacNotificationEvents.bottom )
2c724d25 104 {
e40298d5
JS
105 // we only should process the notifiers that were here when we entered it
106 // otherwise we might never get out...
107 short count = gMacNotificationEvents.top - gMacNotificationEvents.bottom ;
108 if ( count < 0 )
109 count += kMaxEvents ;
2c724d25 110
e40298d5
JS
111 while ( count-- )
112 {
113 // consume event at bottom
114 short index = gMacNotificationEvents.bottom++ ;
115 if ( gMacNotificationEvents.bottom == kMaxEvents )
116 gMacNotificationEvents.bottom = 0 ;
117 void* data = gMacNotificationEvents.data[index] ;
118 unsigned long event = gMacNotificationEvents.events[index] ;
119 wxMacNotificationProcPtr handler = gMacNotificationEvents.proc[index] ;
120
121 gMacNotificationEvents.data[index] = NULL ;
77eddfb7 122 gMacNotificationEvents.events[index] = 0 ;
e40298d5
JS
123 gMacNotificationEvents.proc[index] = NULL ;
124
125 if ( handler )
126 handler( event , data ) ;
127 }
128 }
129 gInProcessing = false ;
ee6b1d97
SC
130}
131
132void wxMacProcessNotifierAndPendingEvents()
133{
e40298d5
JS
134 wxMacProcessNotifierEvents() ;
135 wxTheApp->ProcessPendingEvents() ;
ee6b1d97 136}