1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Sun Microsystems, Inc.
20 : * Portions created by the Initial Developer are Copyright (C) 2002
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Bolian Yin (bolian.yin@sun.com)
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsString.h"
41 : #include "nsMaiInterfaceEditableText.h"
42 :
43 : void
44 0 : editableTextInterfaceInitCB(AtkEditableTextIface *aIface)
45 : {
46 0 : NS_ASSERTION(aIface, "Invalid aIface");
47 0 : if (!aIface)
48 0 : return;
49 :
50 0 : aIface->set_run_attributes = setRunAttributesCB;
51 0 : aIface->set_text_contents = setTextContentsCB;
52 0 : aIface->insert_text = insertTextCB;
53 0 : aIface->copy_text = copyTextCB;
54 0 : aIface->cut_text = cutTextCB;
55 0 : aIface->delete_text = deleteTextCB;
56 0 : aIface->paste_text = pasteTextCB;
57 : }
58 :
59 : /* static, callbacks for atkeditabletext virutal functions */
60 :
61 : gboolean
62 0 : setRunAttributesCB(AtkEditableText *aText, AtkAttributeSet *aAttribSet,
63 : gint aStartOffset, gint aEndOffset)
64 :
65 : {
66 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
67 0 : if (!accWrap)
68 0 : return FALSE;
69 :
70 0 : nsCOMPtr<nsIAccessibleEditableText> accText;
71 : accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
72 0 : getter_AddRefs(accText));
73 0 : NS_ENSURE_TRUE(accText, FALSE);
74 :
75 0 : nsCOMPtr<nsISupports> attrSet;
76 : /* how to insert attributes into nsISupports ??? */
77 :
78 0 : nsresult rv = accText->SetAttributes(aStartOffset, aEndOffset,
79 0 : attrSet);
80 0 : return NS_FAILED(rv) ? FALSE : TRUE;
81 : }
82 :
83 : void
84 0 : setTextContentsCB(AtkEditableText *aText, const gchar *aString)
85 : {
86 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
87 0 : if (!accWrap)
88 0 : return;
89 :
90 0 : nsCOMPtr<nsIAccessibleEditableText> accText;
91 : accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
92 0 : getter_AddRefs(accText));
93 0 : if (!accText)
94 : return;
95 :
96 0 : MAI_LOG_DEBUG(("EditableText: setTextContentsCB, aString=%s", aString));
97 :
98 0 : NS_ConvertUTF8toUTF16 strContent(aString);
99 0 : accText->SetTextContents(strContent);
100 : }
101 :
102 : void
103 0 : insertTextCB(AtkEditableText *aText,
104 : const gchar *aString, gint aLength, gint *aPosition)
105 : {
106 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
107 0 : if (!accWrap)
108 0 : return;
109 :
110 0 : nsCOMPtr<nsIAccessibleEditableText> accText;
111 : accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
112 0 : getter_AddRefs(accText));
113 0 : if (!accText)
114 : return;
115 :
116 0 : NS_ConvertUTF8toUTF16 strContent(aString);
117 :
118 : // interface changed in nsIAccessibleEditableText.idl ???
119 : //
120 : // PRInt32 pos = *aPosition;
121 : // nsresult rv = accText->InsertText(strContent, aLength, &pos);
122 : // *aPosition = pos;
123 :
124 0 : accText->InsertText(strContent, *aPosition);
125 :
126 0 : MAI_LOG_DEBUG(("EditableText: insert aString=%s, aLength=%d, aPosition=%d",
127 : aString, aLength, *aPosition));
128 : }
129 :
130 : void
131 0 : copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
132 : {
133 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
134 0 : if (!accWrap)
135 0 : return;
136 :
137 0 : nsCOMPtr<nsIAccessibleEditableText> accText;
138 : accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
139 0 : getter_AddRefs(accText));
140 0 : if (!accText)
141 : return;
142 :
143 0 : MAI_LOG_DEBUG(("EditableText: copyTextCB, aStartPos=%d, aEndPos=%d",
144 : aStartPos, aEndPos));
145 0 : accText->CopyText(aStartPos, aEndPos);
146 : }
147 :
148 : void
149 0 : cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
150 : {
151 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
152 0 : if (!accWrap)
153 0 : return;
154 :
155 0 : nsCOMPtr<nsIAccessibleEditableText> accText;
156 : accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
157 0 : getter_AddRefs(accText));
158 0 : if (!accText)
159 : return;
160 0 : MAI_LOG_DEBUG(("EditableText: cutTextCB, aStartPos=%d, aEndPos=%d",
161 : aStartPos, aEndPos));
162 0 : accText->CutText(aStartPos, aEndPos);
163 : }
164 :
165 : void
166 0 : deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
167 : {
168 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
169 0 : if (!accWrap)
170 0 : return;
171 :
172 0 : nsCOMPtr<nsIAccessibleEditableText> accText;
173 : accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
174 0 : getter_AddRefs(accText));
175 0 : if (!accText)
176 : return;
177 :
178 0 : MAI_LOG_DEBUG(("EditableText: deleteTextCB, aStartPos=%d, aEndPos=%d",
179 : aStartPos, aEndPos));
180 0 : accText->DeleteText(aStartPos, aEndPos);
181 : }
182 :
183 : void
184 0 : pasteTextCB(AtkEditableText *aText, gint aPosition)
185 : {
186 0 : nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
187 0 : if (!accWrap)
188 0 : return;
189 :
190 0 : nsCOMPtr<nsIAccessibleEditableText> accText;
191 : accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
192 0 : getter_AddRefs(accText));
193 0 : if (!accText)
194 : return;
195 :
196 0 : MAI_LOG_DEBUG(("EditableText: pasteTextCB, aPosition=%d", aPosition));
197 0 : accText->PasteText(aPosition);
198 : }
|