* atk-bridge/bridge.c:
[platform/core/uifw/at-spi2-atk.git] / util / mag_client.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
24 #include <stdlib.h>
25 #include <libbonobo.h>
26 #include "Magnifier.h"
27 #include "mag_client.h"
28
29 static CORBA_Environment ev;
30
31 Accessibility_Magnifier 
32 get_magnifier()
33 {
34   static Accessibility_Magnifier magnifier = NULL;
35   static gboolean is_error = FALSE;
36   CORBA_Object oclient;
37   char *obj_id;
38   
39   if (!magnifier && !is_error)
40   {
41     CORBA_exception_init (&ev);
42     obj_id = "OAFIID:Accessibility_Util_Magnifier:proto0.1";
43
44     oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev);
45     if (ev._major != CORBA_NO_EXCEPTION) {
46       fprintf (stderr,
47             ("Activation error: during magnifier activation: %s\n"),
48             CORBA_exception_id(&ev));
49       CORBA_exception_free(&ev);
50       is_error = TRUE;
51     }
52
53     if (CORBA_Object_is_nil (oclient, &ev))
54     {
55       g_error ("Could not locate magnifier");
56       is_error = TRUE;
57     }
58
59     magnifier = (Accessibility_Magnifier) oclient;
60
61   }
62
63   return magnifier;
64 }
65
66 void
67 magnifier_set_roi(int zoom_region, int x, int y, int w, int h)
68 {
69   Accessibility_Magnifier magnifier = get_magnifier();
70
71   if (magnifier)
72        Accessibility_Magnifier_setROI (magnifier,
73                                        (const CORBA_short) zoom_region,
74                                        (const CORBA_long) x,
75                                        (const CORBA_long) y,
76                                        (const CORBA_long) x+w,
77                                        (const CORBA_long) y+h,
78                                        &ev);
79 }
80
81 void
82 magnifier_set_magnification (int zoom_region, float mag_factor_x, float mag_factor_y)
83 {
84   Accessibility_Magnifier magnifier = get_magnifier();
85
86   if (magnifier)
87        Accessibility_Magnifier_setMagFactor (magnifier,
88                                              (const CORBA_short) zoom_region,
89                                              ((CORBA_float) mag_factor_x),
90                                              ((CORBA_float) mag_factor_y),
91                                              &ev);
92 }
93