X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=libspi%2Ftext.c;h=b32223912abf7c44879f2be2aa3b15edf23987b8;hb=42bec7927aea61be20b65fbfa155a74e3e8b4e3e;hp=7b369a720d38749e72e5b4d46c32e479368e2ebf;hpb=262e6e147178e8744ddb24296a3d41f889400590;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/libspi/text.c b/libspi/text.c index 7b369a7..b322239 100644 --- a/libspi/text.c +++ b/libspi/text.c @@ -20,235 +20,40 @@ * Boston, MA 02111-1307, USA. */ -/* - * component.c : bonobo wrapper for accessible component implementation - * - */ -#include -#include +/* text.c : implements the Text interface */ +#include #include #include +#include +#include -/* - * This pulls the CORBA definitions for the "Accessibility::Accessible" server - */ -#include - -/* - * This pulls the definition of the Text bonobo object - */ -#include "text.h" - -/* - * Static function declarations - */ - -static void -text_class_init (TextClass *klass); -static void -text_init (Text *text); -static void -text_finalize (GObject *obj); -static CORBA_string -impl_getText (PortableServer_Servant _servant, - const CORBA_long startOffset, - const CORBA_long endOffset, - CORBA_Environment * ev); -CORBA_string -impl_getTextAfterOffset (PortableServer_Servant _servant, - const CORBA_long offset, - const - Accessibility_TEXT_BOUNDARY_TYPE - type, CORBA_long * startOffset, - CORBA_long * endOffset, - CORBA_Environment * ev); -static CORBA_string -impl_getTextAtOffset (PortableServer_Servant _servant, - const CORBA_long offset, - const Accessibility_TEXT_BOUNDARY_TYPE type, - CORBA_long * startOffset, - CORBA_long * endOffset, - CORBA_Environment * ev); - -static CORBA_unsigned_long -impl_getCharacterAtOffset (PortableServer_Servant _servant, - const CORBA_long offset, - CORBA_Environment * ev); -static CORBA_string -impl_getTextBeforeOffset (PortableServer_Servant _servant, - const CORBA_long offset, - const - Accessibility_TEXT_BOUNDARY_TYPE - type, CORBA_long * startOffset, - CORBA_long * endOffset, - CORBA_Environment * ev); -static CORBA_long -impl__get_caretOffset (PortableServer_Servant _servant, - CORBA_Environment * ev); -static CORBA_string -impl_getAttributes (PortableServer_Servant _servant, - const CORBA_long offset, - CORBA_long * startOffset, - CORBA_long * endOffset, - CORBA_Environment * ev); -static void -impl_getCharacterExtents (PortableServer_Servant _servant, - const CORBA_long offset, CORBA_long * x, - CORBA_long * y, CORBA_long * width, - CORBA_long * height, - const CORBA_short coordType, - CORBA_Environment * ev); -static CORBA_long -impl__get_characterCount (PortableServer_Servant _servant, - CORBA_Environment * ev); -static CORBA_long -impl_getOffsetAtPoint (PortableServer_Servant _servant, - const CORBA_long x, const CORBA_long y, - const CORBA_short coordType, - CORBA_Environment * ev); -static CORBA_long -impl_getNSelections (PortableServer_Servant _servant, - CORBA_Environment * ev); -static void -impl_getSelection (PortableServer_Servant _servant, - const CORBA_long selectionNum, - CORBA_long * startOffset, CORBA_long * endOffset, - CORBA_Environment * ev); -static CORBA_boolean -impl_addSelection (PortableServer_Servant _servant, - const CORBA_long startOffset, - const CORBA_long endOffset, - CORBA_Environment * ev); -static CORBA_boolean -impl_removeSelection (PortableServer_Servant _servant, - const CORBA_long selectionNum, - CORBA_Environment * ev); -static CORBA_boolean -impl_setSelection (PortableServer_Servant _servant, - const CORBA_long selectionNum, - const CORBA_long startOffset, - const CORBA_long endOffset, - CORBA_Environment * ev); -static CORBA_boolean -impl_setCaretOffset (PortableServer_Servant _servant, - const CORBA_long value, - CORBA_Environment * ev); - - - -static GObjectClass *parent_class; - -GType -text_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo tinfo = { - sizeof (TextClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) text_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class data */ - sizeof (Text), - 0, /* n preallocs */ - (GInstanceInitFunc) text_init, - NULL /* value table */ - }; - - /* - * Bonobo_type_unique auto-generates a load of - * CORBA structures for us. All derived types must - * use bonobo_type_unique. - */ - type = bonobo_type_unique ( - BONOBO_OBJECT_TYPE, - POA_Accessibility_Text__init, - NULL, - G_STRUCT_OFFSET (TextClass, epv), - &tinfo, - "AccessibleText"); - } - - return type; -} - -static void -text_class_init (TextClass *klass) -{ - GObjectClass * object_class = (GObjectClass *) klass; - POA_Accessibility_Text__epv *epv = &klass->epv; - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = text_finalize; - - - /* Initialize epv table */ - - epv->getText = impl_getText; - epv->getTextAfterOffset = impl_getTextAfterOffset; - epv->getCharacterAtOffset = impl_getCharacterAtOffset; - epv->getTextAtOffset = impl_getTextAtOffset; - epv->getTextBeforeOffset = impl_getTextBeforeOffset; - epv->_get_caretOffset = impl__get_caretOffset; - epv->getAttributes = impl_getAttributes; - epv->getCharacterExtents = impl_getCharacterExtents; - epv->_get_characterCount = impl__get_characterCount; - epv->getOffsetAtPoint = impl_getOffsetAtPoint; - epv->getNSelections = impl_getNSelections; - epv->getSelection = impl_getSelection; - epv->addSelection = impl_addSelection; - epv->removeSelection = impl_removeSelection; - epv->setSelection = impl_setSelection; - epv->setCaretOffset = impl_setCaretOffset; -} - -static void -text_init (Text *text) -{ -} +/* Our parent Gtk object type */ +#define PARENT_TYPE SPI_TYPE_BASE -static void -text_finalize (GObject *obj) +static AtkText * +get_text_from_servant (PortableServer_Servant servant) { - Text *text = TEXT (obj); - g_object_unref (text->atko); - text->atko = NULL; - parent_class->finalize (obj); -} + SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant)); -Text * -text_interface_new (AtkObject *obj) -{ - Text *new_text = - TEXT(g_object_new (TEXT_TYPE, NULL)); - new_text->atko = obj; - g_object_ref (obj); - return new_text; + g_return_val_if_fail (object, NULL); + g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL); + return ATK_TEXT (object->gobj); } - - static CORBA_string -impl_getText (PortableServer_Servant _servant, - const CORBA_long startOffset, - const CORBA_long endOffset, - CORBA_Environment * ev) +impl_getText (PortableServer_Servant servant, + const CORBA_long startOffset, + const CORBA_long endOffset, + CORBA_Environment *ev) { - Text *text; gchar *txt; - CORBA_char *rv; - BonoboObject *obj; - - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)""); - text = TEXT (obj); - g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)""); + CORBA_string rv; + AtkText *text = get_text_from_servant (servant); + + g_return_val_if_fail (text != NULL, CORBA_string_dup ("")); - txt = atk_text_get_text (ATK_TEXT(text->atko), - (gint) startOffset, (gint) endOffset); + txt = atk_text_get_text (text, (gint) startOffset, (gint) endOffset); if (txt) { rv = CORBA_string_dup (txt); @@ -256,34 +61,30 @@ impl_getText (PortableServer_Servant _servant, } else rv = CORBA_string_dup (""); + return rv; } - CORBA_string -impl_getTextAfterOffset (PortableServer_Servant _servant, +impl_getTextAfterOffset (PortableServer_Servant servant, const CORBA_long offset, const Accessibility_TEXT_BOUNDARY_TYPE type, CORBA_long * startOffset, CORBA_long * endOffset, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; gchar *txt; CORBA_char *rv; gint intStartOffset, intEndOffset; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)""); - text = TEXT (obj); - g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)""); - - txt = atk_text_get_text_after_offset (ATK_TEXT(text->atko), - (gint) offset, (AtkTextBoundary) type, - &intStartOffset, &intEndOffset); + g_return_val_if_fail (text != NULL, CORBA_string_dup ("")); + + txt = atk_text_get_text_after_offset (text, + (gint) offset, (AtkTextBoundary) type, + &intStartOffset, &intEndOffset); *startOffset = (CORBA_long) intStartOffset; *endOffset = (CORBA_long) intEndOffset; @@ -291,36 +92,34 @@ impl_getTextAfterOffset (PortableServer_Servant _servant, { rv = CORBA_string_dup (txt); g_free (txt); - } + } else rv = CORBA_string_dup (""); + return rv; } - static CORBA_string -impl_getTextAtOffset (PortableServer_Servant _servant, +impl_getTextAtOffset (PortableServer_Servant servant, const CORBA_long offset, const Accessibility_TEXT_BOUNDARY_TYPE type, CORBA_long * startOffset, CORBA_long * endOffset, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; CORBA_char *txt; CORBA_char *rv; gint intStartOffset, intEndOffset; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); + + g_return_val_if_fail (text != NULL, CORBA_string_dup ("")); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)""); - text = TEXT (obj); - g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)""); + txt = (CORBA_char *) atk_text_get_text_at_offset ( + text, + (gint) offset, (AtkTextBoundary) type, + &intStartOffset, &intEndOffset); - txt = (CORBA_char *) atk_text_get_text_at_offset (ATK_TEXT (text->atko), - (gint) offset, (AtkTextBoundary) type, - &intStartOffset, &intEndOffset); *startOffset = (CORBA_long) intStartOffset; *endOffset = (CORBA_long) intEndOffset; @@ -337,46 +136,39 @@ impl_getTextAtOffset (PortableServer_Servant _servant, static CORBA_unsigned_long -impl_getCharacterAtOffset (PortableServer_Servant _servant, +impl_getCharacterAtOffset (PortableServer_Servant servant, const CORBA_long offset, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; - obj = (bonobo_object_from_servant (_servant)); - - g_return_val_if_fail (IS_TEXT (obj), (CORBA_unsigned_long)0); - text = TEXT (obj); - g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_unsigned_long)0); + AtkText *text = get_text_from_servant (servant); + + g_return_val_if_fail (text != NULL, 0); return (CORBA_unsigned_long) - atk_text_get_character_at_offset (ATK_TEXT(text->atko), (gint) offset); + atk_text_get_character_at_offset (text, (gint) offset); } static CORBA_string -impl_getTextBeforeOffset (PortableServer_Servant _servant, +impl_getTextBeforeOffset (PortableServer_Servant servant, const CORBA_long offset, const Accessibility_TEXT_BOUNDARY_TYPE type, CORBA_long * startOffset, CORBA_long * endOffset, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; gchar *txt; CORBA_char *rv; gint intStartOffset, intEndOffset; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); + + g_return_val_if_fail (text != NULL, CORBA_string_dup ("")); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)""); - text = TEXT (obj); - g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)""); + txt = atk_text_get_text_before_offset (text, + (gint) offset, (AtkTextBoundary) type, + &intStartOffset, &intEndOffset); - txt = atk_text_get_text_before_offset (ATK_TEXT(text->atko), - (gint) offset, (AtkTextBoundary) type, - &intStartOffset, &intEndOffset); *startOffset = (CORBA_long) intStartOffset; *endOffset = (CORBA_long) intEndOffset; @@ -387,231 +179,244 @@ impl_getTextBeforeOffset (PortableServer_Servant _servant, } else rv = CORBA_string_dup (""); + return rv; } static CORBA_long -impl__get_caretOffset (PortableServer_Servant _servant, - CORBA_Environment * ev) +impl__get_caretOffset (PortableServer_Servant servant, + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1); - text = TEXT (obj); - g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_long)-1); - - return (CORBA_long) - atk_text_get_caret_offset (ATK_TEXT(text->atko)); -} + g_return_val_if_fail (text != NULL, -1); + return (CORBA_long) atk_text_get_caret_offset (text); +} static CORBA_string -impl_getAttributes (PortableServer_Servant _servant, - const CORBA_long offset, - CORBA_long * startOffset, - CORBA_long * endOffset, - CORBA_Environment * ev) +impl_getAttributes (PortableServer_Servant servant, + const CORBA_long offset, + CORBA_long * startOffset, + CORBA_long * endOffset, + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)""); - text = TEXT (obj); - g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)""); + g_return_val_if_fail (text != NULL, CORBA_string_dup ("")); g_print ("getAttributes not yet implemented.\n"); + + return CORBA_string_dup (""); } + static void -impl_getCharacterExtents (PortableServer_Servant _servant, +impl_getCharacterExtents (PortableServer_Servant servant, const CORBA_long offset, CORBA_long * x, CORBA_long * y, CORBA_long * width, CORBA_long * height, const CORBA_short coordType, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_if_fail (IS_TEXT (obj)); - text = TEXT (obj); - g_return_if_fail (ATK_IS_TEXT (text->atko)); + g_return_if_fail (text != NULL); - atk_text_get_character_extents (ATK_TEXT(text->atko), (gint) offset, - (gint *) x, (gint *) y, (gint *) width, (gint *) height, - (AtkCoordType) coordType); + /* FIXME: Casting a CORBA_long to a gint * is inherantly risky */ + atk_text_get_character_extents ( + text, (gint) offset, + (gint *) x, (gint *) y, (gint *) width, (gint *) height, + (AtkCoordType) coordType); } - static CORBA_long -impl__get_characterCount (PortableServer_Servant _servant, - CORBA_Environment * ev) +impl__get_characterCount (PortableServer_Servant servant, + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + CORBA_long retval; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0); - text = TEXT (obj); + g_return_val_if_fail (text != NULL, 0); - return (CORBA_long) - atk_text_get_character_count (ATK_TEXT(text->atko)); -} + retval = (CORBA_long) atk_text_get_character_count (text); + return retval; +} static CORBA_long -impl_getOffsetAtPoint (PortableServer_Servant _servant, +impl_getOffsetAtPoint (PortableServer_Servant servant, const CORBA_long x, const CORBA_long y, const CORBA_short coordType, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1); - text = TEXT (obj); + g_return_val_if_fail (text != NULL, -1); return (CORBA_long) - atk_text_get_offset_at_point (ATK_TEXT(text->atko), - (gint) x, (gint) y, (AtkCoordType) coordType); + atk_text_get_offset_at_point (text, + (gint) x, (gint) y, + (AtkCoordType) coordType); } - static CORBA_long -impl_getNSelections (PortableServer_Servant _servant, - CORBA_Environment * ev) +impl_getNSelections (PortableServer_Servant servant, + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0); - text = TEXT (obj); + g_return_val_if_fail (text != NULL, 0); - return (CORBA_long) - atk_text_get_n_selections (ATK_TEXT(text->atko)); + return (CORBA_long) atk_text_get_n_selections (text); } - static void -impl_getSelection (PortableServer_Servant _servant, +impl_getSelection (PortableServer_Servant servant, const CORBA_long selectionNum, CORBA_long * startOffset, CORBA_long * endOffset, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_if_fail (IS_TEXT (obj)); - text = TEXT (obj); + g_return_if_fail (text != NULL); - atk_text_get_selection (ATK_TEXT(text->atko), (gint) selectionNum, + atk_text_get_selection (text, (gint) selectionNum, (gint *) startOffset, (gint *) endOffset); } - static CORBA_boolean -impl_addSelection (PortableServer_Servant _servant, +impl_addSelection (PortableServer_Servant servant, const CORBA_long startOffset, const CORBA_long endOffset, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE); - text = TEXT (obj); + g_return_val_if_fail (text != NULL, FALSE); return (CORBA_boolean) - atk_text_add_selection (ATK_TEXT(text->atko), + atk_text_add_selection (text, (gint) startOffset, (gint) endOffset); } - static CORBA_boolean -impl_removeSelection (PortableServer_Servant _servant, +impl_removeSelection (PortableServer_Servant servant, const CORBA_long selectionNum, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE); - text = TEXT (obj); + g_return_val_if_fail (text != NULL, FALSE); return (CORBA_boolean) - atk_text_remove_selection (ATK_TEXT(text->atko), (gint) selectionNum); + atk_text_remove_selection (text, (gint) selectionNum); } - static CORBA_boolean -impl_setSelection (PortableServer_Servant _servant, +impl_setSelection (PortableServer_Servant servant, const CORBA_long selectionNum, const CORBA_long startOffset, const CORBA_long endOffset, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE); - text = TEXT (obj); + g_return_val_if_fail (text != NULL, FALSE); return (CORBA_boolean) - atk_text_set_selection (ATK_TEXT(text->atko), + atk_text_set_selection (text, (gint) selectionNum, (gint) startOffset, (gint) endOffset); } - static CORBA_boolean -impl_setCaretOffset (PortableServer_Servant _servant, +impl_setCaretOffset (PortableServer_Servant servant, const CORBA_long value, - CORBA_Environment * ev) + CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE); - text = TEXT (obj); + g_return_val_if_fail (text != NULL, FALSE); return (CORBA_boolean) - atk_text_set_caret_offset (ATK_TEXT(text->atko), (gint) value); + atk_text_set_caret_offset (text, (gint) value); } - static void -impl_getRowColAtOffset (PortableServer_Servant _servant, +impl_getRowColAtOffset (PortableServer_Servant servant, const CORBA_long offset, CORBA_long * row, - CORBA_long * column, CORBA_Environment * ev) + CORBA_long * column, CORBA_Environment *ev) { - Text *text; - BonoboObject *obj; + AtkText *text = get_text_from_servant (servant); - obj = (bonobo_object_from_servant (_servant)); - g_return_if_fail (IS_TEXT (obj)); - text = TEXT (obj); + g_return_if_fail (text != NULL); g_print ("getRowColAtOffset not yet implemented\n"); } +static void +spi_text_class_init (SpiTextClass *klass) +{ + POA_Accessibility_Text__epv *epv = &klass->epv; + + /* Initialize epv table */ + + epv->getText = impl_getText; + epv->getTextAfterOffset = impl_getTextAfterOffset; + epv->getCharacterAtOffset = impl_getCharacterAtOffset; + epv->getTextAtOffset = impl_getTextAtOffset; + epv->getTextBeforeOffset = impl_getTextBeforeOffset; + epv->_get_caretOffset = impl__get_caretOffset; + epv->getAttributes = impl_getAttributes; + epv->getCharacterExtents = impl_getCharacterExtents; + epv->_get_characterCount = impl__get_characterCount; + epv->getOffsetAtPoint = impl_getOffsetAtPoint; + epv->getNSelections = impl_getNSelections; + epv->getSelection = impl_getSelection; + epv->addSelection = impl_addSelection; + epv->removeSelection = impl_removeSelection; + epv->setSelection = impl_setSelection; + epv->setCaretOffset = impl_setCaretOffset; +} + +static void +spi_text_init (SpiText *text) +{ +} + +BONOBO_TYPE_FUNC_FULL (SpiText, + Accessibility_Text, + PARENT_TYPE, + spi_text); + +void +spi_text_construct (SpiText *text, AtkObject *obj) +{ + spi_base_construct (SPI_BASE (text), G_OBJECT(obj)); +} + + +SpiText * +spi_text_interface_new (AtkObject *obj) +{ + SpiText *retval; + + g_return_val_if_fail (ATK_IS_TEXT (obj), NULL); + + retval = g_object_new (SPI_TEXT_TYPE, NULL); + + spi_text_construct (retval, obj); + + return retval; +}