if (aEndOffset < 0 ) aEndOffset = 1024;
static MaiInterfaceText *getText(AtkText *aIface);G_BEGIN_DECLSstatic void interfaceInitCB(AtkTextIface *aIface);/* text interface callbacks */static gchar *getTextCB(AtkText *aText,                        gint aStartOffset, gint aEndOffset);static gchar *getTextAfterOffsetCB(AtkText *aText, gint aOffset,                                   AtkTextBoundary aBoundaryType,                                   gint *aStartOffset, gint *aEndOffset);static gchar *getTextAtOffsetCB(AtkText *aText, gint aOffset,                                AtkTextBoundary aBoundaryType,                                gint *aStartOffset, gint *aEndOffset);static gunichar getCharacterAtOffsetCB(AtkText *aText, gint aOffset);static gchar *getTextBeforeOffsetCB(AtkText *aText, gint aOffset,                                    AtkTextBoundary aBoundaryType,                                    gint *aStartOffset, gint *aEndOffset);static gint getCaretOffsetCB(AtkText *aText);static AtkAttributeSet *getRunAttributesCB(AtkText *aText, gint aOffset,                                           gint *aStartOffset,                                           gint *aEndOffset);static AtkAttributeSet* getDefaultAttributesCB(AtkText *aText);static void getCharacterExtentsCB(AtkText *aText, gint aOffset,                                  gint *aX, gint *aY,                                  gint *aWidth, gint *aHeight,                                  AtkCoordType aCoords);static gint getCharacterCountCB(AtkText *aText);static gint getOffsetAtPointCB(AtkText *aText,                               gint aX, gint aY,                               AtkCoordType aCoords);static gint getSelectionCountCB(AtkText *aText);static gchar *getSelectionCB(AtkText *aText, gint aSelectionNum,                             gint *aStartOffset, gint *aEndOffset);// set methodsstatic gboolean addSelectionCB(AtkText *aText,                               gint aStartOffset,                               gint aEndOffset);static gboolean removeSelectionCB(AtkText *aText,                                  gint aSelectionNum);static gboolean setSelectionCB(AtkText *aText, gint aSelectionNum,                               gint aStartOffset, gint aEndOffset);static gboolean setCaretOffsetCB(AtkText *aText, gint aOffset);/************************************************* // signal handlers //    static void TextChangedCB(AtkText *aText, gint aPosition, gint aLength);    static void TextCaretMovedCB(AtkText *aText, gint aLocation);    static void TextSelectionChangedCB(AtkText *aText);*/G_END_DECLSMaiInterfaceText::MaiInterfaceText(MaiWidget *aMaiWidget):    MaiInterface(aMaiWidget){}MaiInterfaceText::~MaiInterfaceText(){}MaiInterfaceTypeMaiInterfaceText::GetType(){    return MAI_INTERFACE_TEXT;}const GInterfaceInfo *MaiInterfaceText::GetInterfaceInfo(){    static const GInterfaceInfo atk_if_text_info = {        (GInterfaceInitFunc)interfaceInitCB,        (GInterfaceFinalizeFunc) NULL,        NULL    };    return &atk_if_text_info;}#define MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, value) \    nsCOMPtr<nsIAccessibleText> \        accessIface(do_QueryInterface(GetNSAccessible())); \    if (!(accessIface)) \        return (value)#define MAI_IFACE_RETURN_IF_FAIL(accessIface) \    nsCOMPtr<nsIAccessibleText> \        accessIface(do_QueryInterface(GetNSAccessible())); \    if (!(accessIface)) \        returnconst gchar *MaiInterfaceText::GetText(gint aStartOffset, gint aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, NULL);    nsAutoString autoStr;    nsresult rv = accessIface->GetText(aStartOffset, aEndOffset, autoStr);    if (NS_FAILED(rv))        return NULL;    mText = NS_ConvertUCS2toUTF8(autoStr);    return mText.get();}const gchar *MaiInterfaceText::GetTextAfterOffset(gint aOffset,                                     AtkTextBoundary aBoundaryType,                                     gint *aStartOffset, gint *aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, NULL);    nsAutoString autoStr;    PRInt32 startOffset = 0, endOffset = 0;    nsresult rv =        accessIface->GetTextAfterOffset(aOffset, aBoundaryType,                                        &startOffset, &endOffset, autoStr);    *aStartOffset = startOffset;    *aEndOffset = endOffset;    if (NS_FAILED(rv))        return NULL;    mText = NS_ConvertUCS2toUTF8(autoStr);    return mText.get();}const gchar *MaiInterfaceText::GetTextAtOffset(gint aOffset,                                  AtkTextBoundary aBoundaryType,                                  gint *aStartOffset, gint *aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, NULL);    nsAutoString autoStr;    PRInt32 startOffset = 0, endOffset = 0;    nsresult rv =        accessIface->GetTextAtOffset(aOffset, aBoundaryType,                                     &startOffset, &endOffset, autoStr);    *aStartOffset = startOffset;    *aEndOffset = endOffset;    if (NS_FAILED(rv))        return NULL;    mText = NS_ConvertUCS2toUTF8(autoStr);    return mText.get();}gunicharMaiInterfaceText::GetCharacterAtOffset(gint aOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, gunichar(0));    /* PRUnichar is unsigned short in Mozilla */    /* gnuichar is guint32 in glib */    PRUnichar uniChar;    nsresult rv =        accessIface->GetCharacterAtOffset(aOffset, &uniChar);    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gunichar, uniChar);}const gchar *MaiInterfaceText::GetTextBeforeOffset(gint aOffset,                                      AtkTextBoundary aBoundaryType,                                      gint *aStartOffset, gint *aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, NULL);    nsAutoString autoStr;    PRInt32 startOffset = 0, endOffset = 0;    nsresult rv =        accessIface->GetTextBeforeOffset(aOffset, aBoundaryType,                                         &startOffset, &endOffset, autoStr);    *aStartOffset = startOffset;    *aEndOffset = endOffset;    if (NS_FAILED(rv))        return NULL;    mText = NS_ConvertUCS2toUTF8(autoStr);    return mText.get();}gintMaiInterfaceText::GetCaretOffset(void){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, 0);    PRInt32 offset;    nsresult rv = accessIface->GetCaretOffset(&offset);    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, offset);}AtkAttributeSet *MaiInterfaceText::GetRunAttributes(gint aOffset,                                   gint *aStartOffset,                                   gint *aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, NULL);    nsCOMPtr<nsISupports> attrSet;    PRInt32 startOffset = 0, endOffset = 0;    nsresult rv = accessIface->GetAttributeRange(aOffset,                                                 &startOffset, &endOffset,                                                 getter_AddRefs(attrSet));    *aStartOffset = startOffset;    *aEndOffset = endOffset;    if (NS_FAILED(rv))        return NULL;    /* what to do with the nsISupports ? ??? */    return NULL;}AtkAttributeSet *MaiInterfaceText::GetDefaultAttributes(void){    /* not supported ??? */    return NULL;}voidMaiInterfaceText::GetCharacterExtents(gint aOffset,                                      gint *aX, gint *aY,                                      gint *aWidth, gint *aHeight,                                      AtkCoordType aCoords){    MAI_IFACE_RETURN_IF_FAIL(accessIface);    PRInt32 extY = 0, extX = 0;    PRInt32 extWidth = 0, extHeight = 0;    nsresult rv = accessIface->GetCharacterExtents(aOffset, &extX, &extY,                                                   &extWidth, &extHeight,                                                   aCoords);    *aX = extX;    *aY = extY;    *aWidth = extWidth;    *aHeight = extHeight;    NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),                     "MaiInterfaceText::GetCharacterExtents, failed\n");}gintMaiInterfaceText::GetCharacterCount(void){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, 0);    PRInt32 count = 0;    nsresult rv = accessIface->GetCharacterCount(&count);    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, count);}gintMaiInterfaceText::GetOffsetAtPoint(gint aX, gint aY,                                   AtkCoordType aCoords){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, 0);    PRInt32 offset = 0;    nsresult rv = accessIface->GetOffsetAtPoint(aX, aY, aCoords, &offset);    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, offset);}gintMaiInterfaceText::GetSelectionCount(void){    /* no implemetation in nsIAccessibleText??? */    //new attribuate will be added in nsIAccessibleText.idl    //readonly attribute long selectionCount;    return 0;}const gchar *MaiInterfaceText::GetSelection(gint aSelectionNum,                               gint *aStartOffset, gint *aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, NULL);    PRInt32 startOffset = 0, endOffset = 0;    nsresult rv = accessIface->GetSelectionBounds(aSelectionNum,                                                  &startOffset, &endOffset);    *aStartOffset = startOffset;    *aEndOffset = endOffset;    if (NS_FAILED(rv))        return NULL;    return GetText(*aStartOffset, *aEndOffset);}// set methodsgbooleanMaiInterfaceText::AddSelection(gint aStartOffset, gint aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, FALSE);    nsresult rv = accessIface->AddSelection(aStartOffset, aEndOffset);    return NS_SUCCEEDED(rv);}gbooleanMaiInterfaceText::RemoveSelection(gint aSelectionNum){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, FALSE);    nsresult rv = accessIface->RemoveSelection(aSelectionNum);    return NS_SUCCEEDED(rv);}gbooleanMaiInterfaceText::SetSelection(gint aSelectionNum,                               gint aStartOffset, gint aEndOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, FALSE);    nsresult rv = accessIface->SetSelectionBounds(aSelectionNum,                                                  aStartOffset, aEndOffset);    return NS_SUCCEEDED(rv);}gbooleanMaiInterfaceText::SetCaretOffset(gint aOffset){    MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, FALSE);    nsresult rv = accessIface->SetCaretOffset(aOffset);    return NS_SUCCEEDED(rv);}/* statics *//* do general checking for callbacks functions * return the MaiInterfaceText extracted from atk text */MaiInterfaceText *getText(AtkText *aText){    g_return_val_if_fail(MAI_IS_ATK_WIDGET(aText), NULL);    MaiWidget *maiWidget =        NS_STATIC_CAST(MaiWidget*, (MAI_ATK_OBJECT(aText)->maiObject));    g_return_val_if_fail(maiWidget != NULL, NULL);    g_return_val_if_fail(maiWidget->GetAtkObject() == (AtkObject*)aText,                         NULL);    MaiInterfaceText *maiInterfaceText =        NS_STATIC_CAST(MaiInterfaceText*,                       (maiWidget->GetMaiInterface(MAI_INTERFACE_TEXT)));    return maiInterfaceText;}