1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <sal/config.h>
23 
24 #include <string_view>
25 
26 #include <atk/atk.h>
27 #include <gtk/gtk.h>
28 #include <gtk/gtk-a11y.h>
29 #include <com/sun/star/accessibility/XAccessible.hpp>
30 
31 extern "C" {
32 
33 namespace com::sun::star::accessibility {
34     class XAccessibleAction;
35     class XAccessibleComponent;
36     class XAccessibleEditableText;
37     class XAccessibleHypertext;
38     class XAccessibleImage;
39     class XAccessibleMultiLineText;
40     class XAccessibleSelection;
41     class XAccessibleTable;
42     class XAccessibleText;
43     class XAccessibleTextMarkup;
44     class XAccessibleTextAttributes;
45     class XAccessibleValue;
46 }
47 
48 struct AtkObjectWrapper
49 {
50     AtkObject aParent;
51     AtkObject* mpOrig;  //if we're a GtkDrawingArea acting as a custom LibreOffice widget, this is the toolkit default impl
52     AtkObject* mpSysObjChild; //if we're a container for a sysobj, then this is the sysobj native gtk AtkObject
53 
54     css::uno::Reference<css::accessibility::XAccessible> mpAccessible;
55     css::uno::Reference<css::accessibility::XAccessibleContext> mpContext;
56     css::uno::Reference<css::accessibility::XAccessibleAction> mpAction;
57     css::uno::Reference<css::accessibility::XAccessibleComponent> mpComponent;
58     css::uno::Reference<css::accessibility::XAccessibleEditableText>
59         mpEditableText;
60     css::uno::Reference<css::accessibility::XAccessibleHypertext> mpHypertext;
61     css::uno::Reference<css::accessibility::XAccessibleImage> mpImage;
62     css::uno::Reference<css::accessibility::XAccessibleMultiLineText>
63         mpMultiLineText;
64     css::uno::Reference<css::accessibility::XAccessibleSelection> mpSelection;
65     css::uno::Reference<css::accessibility::XAccessibleTable> mpTable;
66     css::uno::Reference<css::accessibility::XAccessibleText> mpText;
67     css::uno::Reference<css::accessibility::XAccessibleTextMarkup> mpTextMarkup;
68     css::uno::Reference<css::accessibility::XAccessibleTextAttributes>
69         mpTextAttributes;
70     css::uno::Reference<css::accessibility::XAccessibleValue> mpValue;
71 
72     AtkObject *child_about_to_be_removed;
73     gint       index_of_child_about_to_be_removed;
74 //    OString * m_pKeyBindings
75 };
76 
77 struct AtkObjectWrapperClass
78 {
79     GtkWidgetAccessibleClass aParentClass;
80 };
81 
82 GType                  atk_object_wrapper_get_type() G_GNUC_CONST;
83 AtkObject *            atk_object_wrapper_ref(
84     const css::uno::Reference< css::accessibility::XAccessible >& rxAccessible,
85     bool create = true );
86 
87 AtkObject *            atk_object_wrapper_new(
88     const css::uno::Reference< css::accessibility::XAccessible >& rxAccessible,
89     AtkObject* parent = nullptr, AtkObject* orig = nullptr );
90 
91 void                   atk_object_wrapper_add_child(AtkObjectWrapper* wrapper, AtkObject *child, gint index);
92 void                   atk_object_wrapper_remove_child(AtkObjectWrapper* wrapper, AtkObject *child, gint index);
93 void                   atk_object_wrapper_set_role(AtkObjectWrapper* wrapper, sal_Int16 role);
94 
95 void                   atk_object_wrapper_dispose(AtkObjectWrapper* wrapper);
96 
97 AtkStateType mapAtkState( sal_Int16 nState );
98 
99 AtkRelation*           atk_object_wrapper_relation_new(const css::accessibility::AccessibleRelation& rRelation);
100 
101 void                   actionIfaceInit(AtkActionIface *iface);
102 void                   componentIfaceInit(AtkComponentIface *iface);
103 void                   editableTextIfaceInit(AtkEditableTextIface *iface);
104 void                   hypertextIfaceInit(AtkHypertextIface *iface);
105 void                   imageIfaceInit(AtkImageIface *iface);
106 void                   selectionIfaceInit(AtkSelectionIface *iface);
107 void                   tableIfaceInit(AtkTableIface *iface);
108 void                   textIfaceInit(AtkTextIface *iface);
109 void                   valueIfaceInit(AtkValueIface *iface);
110 
111 } // extern "C"
112 
113 #define ATK_TYPE_OBJECT_WRAPPER atk_object_wrapper_get_type()
114 #define ATK_OBJECT_WRAPPER(obj) \
115     (G_TYPE_CHECK_INSTANCE_CAST ((obj), ATK_TYPE_OBJECT_WRAPPER, AtkObjectWrapper))
116 #define ATK_IS_OBJECT_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATK_TYPE_OBJECT_WRAPPER))
117 
118 static inline gchar *
OUStringToGChar(std::u16string_view rString)119 OUStringToGChar(std::u16string_view rString )
120 {
121     OString aUtf8 = OUStringToOString( rString, RTL_TEXTENCODING_UTF8 );
122     return g_strdup( aUtf8.getStr() );
123 }
124 
125 #define OUStringToConstGChar( string ) OUStringToOString( string, RTL_TEXTENCODING_UTF8 ).getStr()
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
128