Back to index

lightning-sunbird  0.9+nobinonly
nsMaiInterfaceValue.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  *
00008  * The contents of this file are subject to the Mozilla Public
00009  * License Version 1.1 (the "License"); you may not use this file
00010  * except in compliance with the License. You may obtain a copy of
00011  * the License at http://www.mozilla.org/MPL/
00012  *
00013  * Software distributed under the License is distributed on an "AS
00014  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00015  * implied. See the License for the specific language governing
00016  * rights and limitations under the License.
00017  *
00018  * The Original Code is mozilla.org code.
00019  *
00020  * The Initial Developer of the Original Code is Sun Microsystems, Inc.
00021  * Portions created by Sun Microsystems are Copyright (C) 2002 Sun
00022  * Microsystems, Inc. All Rights Reserved.
00023  *
00024  * Original Author: Silvia Zhao (silvia.zhao@sun.com)
00025  *
00026  * Contributor(s):
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the NPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the NPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #include "nsMaiInterfaceValue.h"
00043 
00044 G_BEGIN_DECLS
00045     
00046 /*value interface callbacks*/
00047 
00048 static void interfaceInitCB(AtkValueIface *aIface);
00049 static void getCurrentValueCB(AtkValue *obj,
00050                               GValue *value);
00051 static void getMaximumValueCB(AtkValue *obj,
00052                               GValue *value);
00053 static void getMinimumValueCB(AtkValue *obj,
00054                               GValue *value);
00055 static gboolean setCurrentValueCB(AtkValue *obj,
00056                                   const GValue *value);
00057 G_END_DECLS
00058 
00059 MaiInterfaceValue::MaiInterfaceValue(nsAccessibleWrap *aAccWrap):
00060     MaiInterface(aAccWrap)
00061 {
00062 }
00063 
00064 MaiInterfaceValue::~MaiInterfaceValue()
00065 {
00066 }
00067 
00068 MaiInterfaceType
00069 MaiInterfaceValue::GetType()
00070 {
00071     return MAI_INTERFACE_VALUE;
00072 }
00073 
00074 const GInterfaceInfo *
00075 MaiInterfaceValue::GetInterfaceInfo()
00076 {
00077     static const GInterfaceInfo atk_if_value_info = {
00078         (GInterfaceInitFunc) interfaceInitCB,
00079         (GInterfaceFinalizeFunc) NULL,
00080         NULL
00081     };
00082     return &atk_if_value_info;
00083 }
00084 
00085 /* static functions */
00086 
00087 void
00088 interfaceInitCB(AtkValueIface *aIface)
00089 {
00090     NS_ASSERTION(aIface, "Invalid aIface");
00091     if (!aIface)
00092         return;
00093 
00094     aIface->get_current_value = getCurrentValueCB;
00095     aIface->get_maximum_value = getMaximumValueCB;
00096     aIface->get_minimum_value = getMinimumValueCB;
00097     aIface->set_current_value = setCurrentValueCB;
00098 }
00099 
00100 void
00101 getCurrentValueCB(AtkValue *obj, GValue *value)
00102 {
00103     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(obj));
00104     if (!accWrap)
00105         return;
00106 
00107     nsCOMPtr<nsIAccessibleValue> accValue;
00108     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleValue),
00109                             getter_AddRefs(accValue));
00110     if (!accValue)
00111         return;
00112 
00113     memset (value,  0, sizeof (GValue));
00114     double accDouble;
00115     if (NS_FAILED(accValue->GetCurrentValue(&accDouble)))
00116         return;
00117     g_value_init (value, G_TYPE_DOUBLE);
00118     g_value_set_double (value, accDouble);
00119 }
00120 
00121 void
00122 getMaximumValueCB(AtkValue *obj, GValue *value)
00123 {
00124     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(obj));
00125     if (!accWrap)
00126         return;
00127 
00128     nsCOMPtr<nsIAccessibleValue> accValue;
00129     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleValue),
00130                             getter_AddRefs(accValue));
00131     if (!accValue)
00132         return;
00133 
00134     memset (value,  0, sizeof (GValue));
00135     double accDouble;
00136     if (NS_FAILED(accValue->GetMaximumValue(&accDouble)))
00137         return;
00138     g_value_init (value, G_TYPE_DOUBLE);
00139     g_value_set_double (value, accDouble);
00140 }
00141 
00142 void
00143 getMinimumValueCB(AtkValue *obj, GValue *value)
00144 {
00145     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(obj));
00146     if (!accWrap)
00147         return;
00148 
00149     nsCOMPtr<nsIAccessibleValue> accValue;
00150     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleValue),
00151                             getter_AddRefs(accValue));
00152     if (!accValue)
00153         return;
00154 
00155     memset (value,  0, sizeof (GValue));
00156     double accDouble;
00157     if (NS_FAILED(accValue->GetMinimumValue(&accDouble)))
00158         return;
00159     g_value_init (value, G_TYPE_DOUBLE);
00160     g_value_set_double (value, accDouble);
00161 }
00162 
00163 gboolean
00164 setCurrentValueCB(AtkValue *obj, const GValue *value)
00165 {
00166     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(obj));
00167     NS_ENSURE_TRUE(accWrap, FALSE);
00168 
00169     nsCOMPtr<nsIAccessibleValue> accValue;
00170     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleValue),
00171                             getter_AddRefs(accValue));
00172     NS_ENSURE_TRUE(accValue, FALSE);
00173 
00174     PRBool aBool;
00175     double accDouble;
00176     accDouble = g_value_get_double (value);
00177     accValue->SetCurrentValue(accDouble, &aBool);
00178     return aBool;
00179 }