Visual Studio builds: Support Visual Studio 2017
[platform/upstream/atk.git] / atk / atkprivate.c
1 /* ATK -  Accessibility Toolkit
2  *
3  * Copyright (C) 2014 Igalia, S.L.
4  *
5  * Author: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "config.h"
24
25 #include <string.h>
26 #include <locale.h>
27
28 #include <glib-object.h>
29 #include <glib/gi18n-lib.h>
30
31 #include "atkprivate.h"
32
33 #ifdef G_OS_WIN32
34
35 #define STRICT
36 #include <windows.h>
37 #undef STRICT
38
39 static HMODULE atk_dll;
40
41 BOOL WINAPI
42 DllMain (HINSTANCE hinstDLL,
43          DWORD     fdwReason,
44          LPVOID    lpvReserved)
45 {
46   switch (fdwReason)
47     {
48     case DLL_PROCESS_ATTACH:
49       atk_dll = (HMODULE) hinstDLL;
50       break;
51     }
52
53   return TRUE;
54 }
55
56 static const char *
57 get_atk_locale_dir (void)
58 {
59   static gchar *atk_localedir = NULL;
60
61   if (!atk_localedir)
62     {
63       const gchar *p;
64       gchar *root, *temp;
65       
66       /* ATK_LOCALEDIR might end in either /lib/locale or
67        * /share/locale. Scan for that slash.
68        */
69       p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
70       while (*--p != '/')
71         ;
72       while (*--p != '/')
73         ;
74
75       root = g_win32_get_package_installation_directory_of_module (atk_dll);
76       temp = g_build_filename (root, p, NULL);
77       g_free (root);
78
79       /* atk_localedir is passed to bindtextdomain() which isn't
80        * UTF-8-aware.
81        */
82       atk_localedir = g_win32_locale_filename_from_utf8 (temp);
83       g_free (temp);
84     }
85   return atk_localedir;
86 }
87
88 #undef ATK_LOCALEDIR
89
90 #define ATK_LOCALEDIR get_atk_locale_dir()
91
92 #endif
93
94 void
95 _gettext_initialization (void)
96 {
97 #ifdef ENABLE_NLS
98   static gboolean gettext_initialized = FALSE;
99
100   if (!gettext_initialized)
101     {
102       const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
103
104       gettext_initialized = TRUE;
105       if (dir == NULL)
106         dir = ATK_LOCALEDIR;
107
108       bindtextdomain (GETTEXT_PACKAGE, dir);
109 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
110       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
111 #endif
112     }
113 #endif
114 }
115
116 /*
117  * Compacts a name. For example: to get "accelerator label" instead of
118  * "accelerator-label"
119  */
120 void
121 _compact_name (gchar *name)
122 {
123   gchar *p = name;
124
125   while (*p)
126     {
127       if (*p == '-')
128         *p = ' ';
129       p++;
130     }
131 }