2007-04-02 Ariel Rios <ariel@gnu.org>
[platform/core/uifw/at-spi2-atk.git] / libspi / collection.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2007 IBM Corp.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* collection.c: implements the Collection interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <bonobo/bonobo-exception.h>
28 #include <libspi/collection.h>
29 #include <libspi/matchrule.h> 
30 #include <libspi/spi-private.h>
31
32 typedef struct _MatchRulePrivate MatchRulePrivate;
33
34 struct _MatchRulePrivate {
35
36      Accessibility_StateSet states;
37      Accessibility_Collection_MatchType statematchtype;
38      Accessibility_AttributeSet  *attributes;
39      Accessibility_Collection_MatchType attributematchtype;
40      Accessibility_RoleSet *roles;
41      Accessibility_Collection_MatchType rolematchtype;
42      CORBA_char *interfaces;
43      Accessibility_Collection_MatchType interfacematchtype;
44      gboolean invert;
45
46 };
47
48 #define MATCH_RULE_PRIVATE(o)\
49      G_TYPE_INSTANCE_GET_PRIVATE((o), SPI_MATCHRULE_TYPE, MatchRulePrivate)
50
51
52 SpiCollection *
53 spi_collection_interface_new ()
54 {
55
56      SpiCollection *new_collection = g_object_new (SPI_COLLECTION_TYPE, NULL);
57
58      spi_base_construct_default (SPI_BASE (new_collection));
59
60      return new_collection;
61
62 }
63
64 /*
65 static SpiCollection *
66 get_collection_from_servant (PortableServer_Servant servant)
67 {
68      SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
69
70      g_return_val_if_fail (object, NULL);
71      
72      return SPI_COLLECTION (object->gobj);
73                                 
74 }
75 */
76
77 static Accessibility_MatchRule 
78 impl_createMatchRule (PortableServer_Servant servant,
79                       const Accessibility_StateSet states,
80                       const Accessibility_Collection_MatchType statematchtype,
81                       const Accessibility_AttributeSet *attributes,
82                       const Accessibility_Collection_MatchType attributematchtype,
83                       const Accessibility_RoleSet *roles,
84                       const Accessibility_Collection_MatchType rolematchtype,
85                       const CORBA_char *interfaces,
86                       const Accessibility_Collection_MatchType interfacematchtype,
87                       const CORBA_boolean invert,
88                       CORBA_Environment *ev){
89
90      Accessibility_MatchRule  retval = NULL;
91
92      SpiMatchrule *matchrule = spi_matchrule_interface_new ();
93      MatchRulePrivate *mrp   = MATCH_RULE_PRIVATE (matchrule);
94      int i;
95
96      mrp->states  = states;
97      mrp->statematchtype = statematchtype;
98
99 /* attributes */
100
101      mrp->attributes = CORBA_sequence_CORBA_string__alloc ();
102      mrp->attributes->_maximum = attributes->_maximum;
103      mrp->attributes->_length = attributes->_length;
104      mrp->attributes->_buffer = CORBA_sequence_CORBA_string_allocbuf (attributes->_length);
105
106      for (i = 0; i < mrp->attributes->_length; i++)
107           mrp->attributes->_buffer [i]= CORBA_string_dup (attributes->_buffer [i]);
108     
109      CORBA_sequence_set_release (mrp->attributes, TRUE);
110      mrp->attributematchtype = attributematchtype;
111
112 /* roles */
113
114      mrp->roles = Accessibility_RoleSet__alloc ();
115      mrp->roles->_maximum = roles->_maximum;
116      mrp->roles->_length = roles->_length;
117      mrp->roles->_buffer = Accessibility_RoleSet_allocbuf (roles->_length);
118
119      for (i = 0; i < roles->_length; i++)
120           mrp->roles->_buffer [i] = roles->_buffer [i];
121      
122      CORBA_sequence_set_release (mrp->roles, TRUE);
123      mrp->rolematchtype = rolematchtype;
124
125 /* interfaces */
126      
127      mrp->interfaces = CORBA_string_dup (interfaces);
128      mrp->interfacematchtype = interfacematchtype;
129
130      mrp->invert = invert;
131      
132      retval = CORBA_Object_duplicate (BONOBO_OBJREF (matchrule), ev);
133
134      return retval;
135
136 }
137
138 static void impl_freeMatchRule (PortableServer_Servant servant,
139                                 Accessibility_MatchRule matchrule,     
140                                 CORBA_Environment *ev){
141
142      SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
143      SpiMatchrule *spimatchrule;
144
145      MatchRulePrivate *mrp;  
146
147      spimatchrule = SPI_MATCHRULE (object->gobj);
148      mrp =  MATCH_RULE_PRIVATE (spimatchrule);;
149      
150      CORBA_free (mrp->attributes);
151      CORBA_free (mrp->roles);
152      CORBA_free (mrp->interfaces);     
153      
154      g_free (spimatchrule);
155
156 }
157 static void
158 spi_collection_class_init (SpiCollectionClass *klass)
159 {
160
161     POA_Accessibility_Collection__epv *epv  = &klass->epv;
162
163     /*    epv->isAncestorOf = impl_isAncestorOf; */
164     
165    epv->createMatchRule =  impl_createMatchRule;
166    epv->freeMatchRule = impl_freeMatchRule;
167    
168    /*
169      epv->getChildren = impl_getChildren;
170      epv->getPreviousChildren = impl_getPreviousChildren;
171      epv->getNextChildren = impl_getNextChildren;
172      epv->getActiveDescendant = impl_getActiveDescendant;
173    */
174
175    g_type_class_add_private (klass, sizeof (MatchRulePrivate));
176 }
177
178 static void
179 spi_collection_init (SpiCollection *collection)
180 {
181 }
182
183 BONOBO_TYPE_FUNC_FULL (SpiCollection,
184                        Accessibility_Collection,
185                        SPI_TYPE_BASE,
186                        spi_collection)
187