* atk-bridge/bridge.c:
[platform/core/uifw/at-spi2-atk.git] / util / mag_control.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
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 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <libbonobo.h>
27 #include "Magnifier.h"
28 #include "mag_client.h"
29
30 static CORBA_Environment ev;
31
32 int main(int argc, char ** argv){
33
34   if (!bonobo_init (&argc, argv))
35   {
36     g_error ("Could not initialize Bonobo");
37   }
38
39   CORBA_exception_init (&ev);
40   
41   if(argc == 1){
42           get_magnifier ();
43   }
44
45   else
46     {
47       switch (*argv[1])
48         {
49         case 'z':       
50           printf ("setting mag factor to %f\n", (float) atof (argv[1]+1));
51           magnifier_set_magnification (0, (float) atof (argv[1]+1),
52                                        (float) atof (argv[1]+1));
53           break;
54         case 's':
55           printf ("resizing region 0 to 100x100 at (600, 0)\n");
56           magnifier_resize_region (0, 600, 0, 700, 100);
57           break;
58         case 'd':
59           printf ("destroying/clearing all regions.\n");
60           magnifier_clear_all_regions ();
61           break;
62         case 'q':
63           printf ("exiting magnifier.\n");
64           magnifier_exit ();
65           break;
66         case 'c':
67           printf ("creating 3x region at 100,100; 300x200\n");
68           magnifier_create_region (3.0, 3.0, 100, 100, 400, 300);
69         }
70     }
71   return 0;
72 }
73
74 Accessibility_Magnifier 
75 get_magnifier()
76 {
77   static Accessibility_Magnifier magnifier = NULL;
78   static gboolean is_error = FALSE;
79   CORBA_Object oclient;
80   char *obj_id;
81   
82   if (!magnifier && !is_error)
83   {
84     CORBA_exception_init (&ev);
85     obj_id = "OAFIID:Accessibility_Util_Magnifier:proto0.1";
86
87     oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev);
88     if (ev._major != CORBA_NO_EXCEPTION) {
89       fprintf (stderr,
90             ("Activation error: during magnifier activation: %s\n"),
91             CORBA_exception_id(&ev));
92       CORBA_exception_free(&ev);
93       is_error = TRUE;
94     }
95
96     if (CORBA_Object_is_nil (oclient, &ev))
97     {
98       g_error ("Could not locate magnifier");
99       is_error = TRUE;
100     }
101
102     magnifier = (Accessibility_Magnifier) oclient;
103
104     /* bonobo_activate (); ? */
105   }
106
107   return magnifier;
108 }
109
110 void
111 magnifier_set_roi(int zoom_region, int x, int y, int w, int h)
112 {
113   Accessibility_Magnifier magnifier = get_magnifier();
114
115   if (magnifier)
116        Accessibility_Magnifier_setROI (magnifier,
117                                       (const CORBA_short) zoom_region,
118                                       (const CORBA_long) x,
119                                       (const CORBA_long) y,
120                                       (const CORBA_long) x+w,
121                                       (const CORBA_long) y+h,
122                                       &ev);
123 }
124
125 void
126 magnifier_resize_region (int zoom_region, int x1, int y1, int x2, int y2)
127 {
128   Accessibility_Magnifier magnifier = get_magnifier();
129
130   if (magnifier)
131        Accessibility_Magnifier_resizeZoomRegion (magnifier,
132                                                  (const CORBA_short) zoom_region,
133                                                  (const CORBA_long) x1,
134                                                  (const CORBA_long) y1,
135                                                  (const CORBA_long) x2,
136                                                  (const CORBA_long) y2,
137                                                  &ev);
138 }
139
140 void
141 magnifier_clear_all_regions ()
142 {
143   Accessibility_Magnifier magnifier = get_magnifier();
144
145   if (magnifier)
146        Accessibility_Magnifier_clearAllZoomRegions (magnifier,
147                                                     &ev);
148 }
149
150 int
151 magnifier_create_region (float zx, float zy, int x1, int y1, int x2, int y2)
152 {
153   Accessibility_Magnifier magnifier = get_magnifier();
154   int retval = -1;
155   
156   if (magnifier)
157        retval = Accessibility_Magnifier_createZoomRegion (magnifier,
158                                                           (const CORBA_float) zx,
159                                                           (const CORBA_float) zy,
160                                                           (const CORBA_long) x1,
161                                                           (const CORBA_long) y1,
162                                                           (const CORBA_long) x2,
163                                                           (const CORBA_long) y2,
164                                                           &ev);
165   return retval;
166 }
167
168 void
169 magnifier_set_magnification (int zoom_region, float mag_factor_x, float mag_factor_y)
170 {
171   Accessibility_Magnifier magnifier = get_magnifier();
172
173   if (magnifier)
174        Accessibility_Magnifier_setMagFactor (magnifier,
175                                              (const CORBA_short) zoom_region,
176                                              (const CORBA_float) mag_factor_x,
177                                              (const CORBA_float) mag_factor_y,
178                                              &ev);
179 }
180
181 void
182 magnifier_exit (void)
183 {
184   Accessibility_Magnifier magnifier = get_magnifier();
185   if (magnifier)
186     Accessibility_Magnifier_exit (magnifier, &ev);
187 }